Initial revision
authorJohn Kohl <jtkohl@mit.edu>
Wed, 20 Mar 1991 17:03:18 +0000 (17:03 +0000)
committerJohn Kohl <jtkohl@mit.edu>
Wed, 20 Mar 1991 17:03:18 +0000 (17:03 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@1925 dc483132-0cff-0310-8789-dd5450dbe970

src/appl/popper/pop_enter.c [new file with mode: 0644]

diff --git a/src/appl/popper/pop_enter.c b/src/appl/popper/pop_enter.c
new file mode 100644 (file)
index 0000000..72d9ce2
--- /dev/null
@@ -0,0 +1,185 @@
+
+/*
+ * 
+ */
+#include <errno.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <strings.h>
+#include <sys/stat.h>
+#include <sys/file.h>
+#include <mit-copyright.h>
+
+#ifdef ZEPHYR
+#include <zephyr/zephyr.h>
+
+char *Zsignature = "Your friendly neighborhood post office.";
+#endif ZEPHYR
+
+void notify_recipient();
+
+#define POP_MAILDIR "/usr/spool/pop"
+
+char buffer[BUFSIZ];
+char tmpfile[512];           /* tmp file */
+int  newmail;                /* fd for temp message */
+int  maildrop;               /* file descriptor for drop */
+
+extern int errno;
+
+
+
+main (argc, argv)
+     int argc;
+     char **argv;     
+{
+  int status = 0;
+  int  i = 1;                  /* argument counter */
+      
+  if(get_message() < 0)
+    exit(1);
+
+  while (--argc > 0) 
+    {
+      if(open_drop(argv[i]) < 0)
+       {
+         lseek(newmail, 0, L_SET);
+         if(new_message(maildrop, newmail) < 0)
+           status = 1;
+         if(close(maildrop) < 0)
+           {
+             status = 1;
+             sprintf(buffer, "%s: error on close", argv[i]);
+             error(buffer, errno);
+           }
+         notify_recipient(argv[i]);
+       }
+      else
+       status = 1;
+      ++i;
+    }
+  
+  close(newmail);
+  unlink(tmpfile);
+  exit(status);
+}
+
+
+
+int
+get_message()
+{
+  int  nchar;        
+
+  sprintf(tmpfile, "/tmp/tpop.%d", getpid());
+  if((newmail = open(tmpfile, O_RDWR|O_CREAT, 0600)) == -1) 
+    {
+      fprintf(stderr, "unable to open temporary file,  \"%s\".\n",  tmpfile);
+      return(-1);
+    }
+    
+  while(nchar = read(0, buffer, sizeof(buffer)))
+    write(newmail, buffer, nchar);  
+
+  return(0);
+}
+
+
+
+int
+open_drop(drop)
+     char *name;
+{
+  char dropfile[512];             
+
+  sprintf(dropfile, "%s/%s", POP_MAILDIR, name);
+  if ((maildrop = open(dropfile, O_RDWR|O_CREAT,0600)) == -1)  
+    {
+      fprintf(stderr, "unable to open \"%s\": %s.\n", 
+             dropfile, (errno < sys_nerr) ? sys_errlist[errno] : "");
+      return(-1);
+    }
+  
+  /*  Lock the user's real mail drop */
+  
+  if (flock(maildrop, LOCK_EX) == -1) 
+    {
+      fprintf(stderr, 
+          "unable to lock \"%s\" (service unavailable... the sequel): %s.\n", 
+             dropfile, (errno < sys_nerr) ? 
+             sys_errlist[errno] : "");
+      return(-1);
+    }
+
+  lseek(maildrop, 0, L_XTND);
+  return(0);
+}
+
+
+
+new_message(to, from)
+     int to, from;
+{
+  int cc;
+  
+  cc = time(0);
+  sprintf(buffer, "From popper %s\n", ctime(&cc)); 
+  write(to, buffer, strlen(buffer) * sizeof(char));
+  while(cc = read(from, buffer, sizeof(buffer)))
+    write(to, buffer, cc);
+  write(to, "\n", 1);
+}
+      
+
+
+void
+notify_recipient(name)
+     char *name;
+     
+{
+  char *message = "You have new mail";
+
+#ifdef ZEPHYR
+  static int init = 0;
+  ZNotice_t notice;             /* Zephyr notice */
+  int    ret;                   /* return value, length */
+  
+  if(init)
+    if ((ret = ZInitialize()) == ZERR_NONE)
+      init = 0;
+
+  bzero(&notice, sizeof(notice));
+  notice.z_kind = UNSAFE;
+  notice.z_class          = "message";
+  notice.z_class_inst     = "pop";
+  notice.z_recipient      = name;
+
+  zsend(&notice, &message, 1, 1);
+#endif ZEPHYR
+}
+
+
+
+#ifdef ZEPHYR
+zsend(notice, items, nitems, auth)
+     ZNotice_t *notice;
+     char **items;
+     int nitems;
+     int auth;
+{
+  int ret;
+
+  if ((ret = ZSendList(notice, items, nitems, auth ? ZAUTH:ZNOAUTH)) !=
+      ZERR_NONE)
+    { /* syslog */
+      if(auth) 
+        return(zsend(notice, items, nitems, 0));
+      else
+        return(-1);
+    }
+}
+
+#endif ZEPHYR
+  
+