BSD 4_4 release
[unix-history] / usr / src / usr.bin / xsend / xsend / xsend.c
index 2bd8cdb..ad14aa4 100644 (file)
@@ -1,23 +1,34 @@
+/*-
+ * This module is believed to contain source code proprietary to AT&T.
+ * Use and redistribution is subject to the Berkeley Software License
+ * Agreement and your Software Agreement with AT&T (Western Electric).
+ */
+
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)xsend.c    4.1 %G%";
-#endif
+static char sccsid[] = "@(#)xsend.c    8.1 (Berkeley) 6/6/93";
+#endif /* not lint */
 
 
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <sys/dir.h>
+#include <pwd.h>
 #include "xmail.h"
 #include "xmail.h"
-#include "sys/types.h"
-#include "pwd.h"
-#include "sys/stat.h"
-#include "sys/dir.h"
+#include "pathnames.h"
+
 extern int errno;
 struct stat stbuf;
 int uid, destuid;
 extern int errno;
 struct stat stbuf;
 int uid, destuid;
-char *myname, *dest, *keyfile[128], line[128];
-struct direct dbuf;
-char *maildir = "/usr/spool/secretmail/";
-FILE *kf, *mf, *df;
+char *myname, *dest, keyfile[128], line[128];
+struct direct *dbuf;
+char *maildir = _PATH_SECRETMAIL;
+FILE *kf, *mf;
+DIR *df;
 MINT *a[42], *cd[6][128];
 MINT *msg;
 char buf[256], eof;
 int dbg;
 MINT *a[42], *cd[6][128];
 MINT *msg;
 char buf[256], eof;
 int dbg;
+extern char *malloc(), *getlogin();
+
 main(argc, argv) char **argv;
 {      int i, nmax, len;
        char *p;
 main(argc, argv) char **argv;
 {      int i, nmax, len;
        char *p;
@@ -43,7 +54,7 @@ main(argc, argv) char **argv;
        kf = fopen(keyfile, "r");
        if(kf == NULL)
                xfatal("addressee's key weird");
        kf = fopen(keyfile, "r");
        if(kf == NULL)
                xfatal("addressee's key weird");
-       df = fopen(maildir, "r");
+       df = opendir(maildir);
        if(df == NULL)
        {       perror(maildir);
                exit(1);
        if(df == NULL)
        {       perror(maildir);
                exit(1);
@@ -51,10 +62,8 @@ main(argc, argv) char **argv;
        strcpy(line, dest);
        strcat(line, ".%d");
        nmax = -1;
        strcpy(line, dest);
        strcat(line, ".%d");
        nmax = -1;
-       for(; !feof(df);)
-       {       fread(&dbuf, sizeof(dbuf), 1, df);
-               if(dbuf.d_ino == 0) continue;
-               if(sscanf(dbuf.d_name, line, &i) != 1)
+       while ((dbuf=readdir(df))!=NULL)
+       {       if(sscanf(dbuf->d_name, line, &i) != 1)
                        continue;
                if(i>nmax) nmax = i;
        }
                        continue;
                if(i>nmax) nmax = i;
        }
@@ -72,8 +81,27 @@ main(argc, argv) char **argv;
        dbg = 1;
 #endif
        run();
        dbg = 1;
 #endif
        run();
-       sprintf(buf, "mail %s <%snotice", dest, maildir);
-       system(buf);
+       {
+               char    hostname[MAXHOSTNAMELEN];
+               FILE    *nf, *popen();
+               struct  passwd  *passp;
+
+               sprintf(buf, "%s %s", _PATH_MAIL, dest);
+               if ((nf = popen(buf, "w")) == NULL)
+                       xfatal("cannot pipe to %s", _PATH_MAIL);
+               passp = getpwuid(getuid());
+               if (passp == 0){
+                       pclose(nf);
+                       xfatal("Who are you?");
+               }
+               gethostname(hostname, sizeof(hostname));
+               fprintf(nf, "Subject: %s@%s sent you secret mail\n",
+                       passp->pw_name, hostname);
+               fprintf(nf,
+                "Your secret mail can be read on host %s using ``xget''.\n",
+                       hostname);
+               pclose(nf);
+       }
        exit(0);
 }
 mkcd()
        exit(0);
 }
 mkcd()