]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/clients/zpopnotify/zpopnotify.c
b2f79e395d2df203b6d636e683880852433051cb
[1ts-debian.git] / zephyr / clients / zpopnotify / zpopnotify.c
1 /* This file is part of the Project Athena Zephyr Notification System.
2  * It contains code for the "zpopnotify" command.
3  *
4  *      Created by:     Robert French
5  *
6  *      $Id$
7  *
8  *      Copyright (c) 1987,1988 by the Massachusetts Institute of Technology.
9  *      For copying and distribution information, see the file
10  *      "mit-copyright.h". 
11  */
12
13
14 #include <sysdep.h>
15 #include <zephyr/mit-copyright.h>
16 #include <zephyr/zephyr.h>
17 #include <stdio.h>
18 #include <netdb.h>
19 #include <string.h>
20 #include <sys/param.h>                  /* for MAXHOSTNAMELEN */
21 #include <com_err.h>
22 #include <errno.h>
23
24 #ifndef lint
25 static char rcsid_zpopnotify_c[] = "$Id$";
26 #endif /* lint */
27
28 #define MAIL_CLASS "MAIL"
29 #define MAIL_INSTANCE "POP"
30
31 void usage();
32
33 main(argc,argv)
34         int argc;
35         char *argv[];
36 {
37         ZNotice_t notice;
38         struct hostent *hent;
39         int retval;
40         register int i;
41         char *whoami,myhost[MAXHOSTNAMELEN],mysender[BUFSIZ];
42         char *lines[2];
43         
44         whoami = argv[0];
45
46         if ((retval = ZInitialize()) != ZERR_NONE) {
47                 com_err(whoami,retval,"while initializing");
48                 exit(1);
49         } 
50
51         if (argc < 2) {
52                 usage(whoami);
53                 exit(1);
54         }
55
56         if (gethostname(myhost,MAXHOSTNAMELEN) == -1) {
57                 com_err(whoami,errno,"Can't get hostname");
58                 exit(1);
59         }
60         myhost[MAXHOSTNAMELEN-1] = '\0';
61
62         if (!(hent = gethostbyname(myhost))) {
63                 com_err(whoami,errno,"Can't get canonical hostname");
64                 exit(1);
65         }
66
67         (void) strncpy(myhost,hent->h_name,MAXHOSTNAMELEN);
68         myhost[MAXHOSTNAMELEN-1] = '\0';
69
70         lines[0] = myhost;
71         lines[1] = "You have new mail.";
72         
73         (void) strcpy(mysender,"pop@");
74         (void) strcat(mysender,ZGetRealm());
75
76         for (i = 1; i < argc; i++) {
77             (void) memset((char *)&notice, 0, sizeof(notice));
78             notice.z_kind = UNSAFE;
79             notice.z_class = MAIL_CLASS;
80             notice.z_class_inst = MAIL_INSTANCE;
81             notice.z_opcode = "";
82             notice.z_sender = mysender;
83             notice.z_default_format = "From Post Office $1:\n$2";
84
85             /* in case it's a mailbox name (pathname), strip to username */
86             notice.z_recipient = (char *)strrchr(argv[i],'/');
87             if (notice.z_recipient)
88                 notice.z_recipient++;
89             else
90                 notice.z_recipient = argv[i];
91
92             if ((retval = ZSendList(&notice,lines,2,ZNOAUTH)) != ZERR_NONE) {
93                 com_err(whoami,retval,"while sending notice");
94                 exit(1);
95             } 
96         }
97 }
98
99 void
100 usage(whoami)
101         char *whoami;
102 {
103         printf("Usage: %s username [ username ... ]\n",whoami);
104 }