procmail can send notifications to comsat using an extended format:

        $LOGNAME@offset_of_message_in_mailbox:absolute_path_to_mailbox

The modifications are similar to the modifications freebsd did long
time ago.


-- 
Roberto E. Vargas Caballero
Index: comsat.8
===================================================================
RCS file: /cvs/src/libexec/comsat/comsat.8,v
retrieving revision 1.6
diff -u -p -r1.6 comsat.8
--- comsat.8    31 May 2007 19:19:39 -0000      1.6
+++ comsat.8    7 Aug 2013 17:34:40 -0000
@@ -50,7 +50,7 @@ and
 .Xr inetd 8 ) .
 The one line messages are of the form:
 .Pp
-.Dl user@mailbox-offset
+.Dl user@mailbox-offset[:mailbox-name]
 .Pp
 If the
 .Em user
@@ -69,6 +69,8 @@ Lines which appear to be part of the mes
 or
 .Dq Subject
 lines are not included in the displayed message.
+.Pp
+If mailbox-name is omitted, standard mailbox is assumed.
 .Sh FILES
 .Bl -tag -width /var/run/utmp -compact
 .It Pa /var/run/utmp
Index: comsat.c
===================================================================
RCS file: /cvs/src/libexec/comsat/comsat.c,v
retrieving revision 1.37
diff -u -p -r1.37 comsat.c
--- comsat.c    4 Dec 2012 02:24:47 -0000       1.37
+++ comsat.c    7 Aug 2013 17:34:40 -0000
@@ -62,9 +62,9 @@ struct        utmp *utmp = NULL;
 time_t lastmsgtime;
 int    nutmp, uf;
 
-void jkfprintf(FILE *, char[], off_t);
+void jkfprintf(FILE *, char[], char [], off_t);
 void mailfor(char *);
-void notify(struct utmp *, off_t);
+void notify(struct utmp *, char [], off_t, int);
 void readutmp(int);
 void doreadutmp(void);
 void reapchildren(int);
@@ -201,23 +201,40 @@ mailfor(char *name)
        char utname[UT_NAMESIZE+1];
        char *cp;
        off_t offset;
+       int folder;
+       char *file;
+       char buf[sizeof(_PATH_MAILDIR) + UT_NAMESIZE + 1];
+       char buf2[sizeof(_PATH_MAILDIR) + UT_NAMESIZE + 1];
 
        if (!(cp = strchr(name, '@')))
                return;
        *cp = '\0';
        offset = atoi(cp + 1);
+       if (!(cp = strchr(cp + 1, ':')))
+               file = name;
+       else
+               file = cp + 1;
+       snprintf(buf,sizeof(buf),"%s/%.*s",
+                _PATH_MAILDIR, (int)sizeof(utp->ut_name), name);
+       if (*file != '/') {
+               snprintf(buf2, sizeof(buf2), "%s/%.*s", _PATH_MAILDIR,
+                       (int)sizeof(utp->ut_name), file);
+               file = buf2;
+       }
+       folder = strcmp(buf, file);
+
        while (--utp >= utmp) {
                memcpy(utname, utp->ut_name, UT_NAMESIZE);
                utname[UT_NAMESIZE] = '\0';
                if (!strncmp(utname, name, UT_NAMESIZE))
-                       notify(utp, offset);
+                       notify(utp, file, offset, folder);
        }
 }
 
 static char *cr;
 
 void
-notify(struct utmp *utp, off_t offset)
+notify(struct utmp *utp, char file[], off_t offset, int folder)
 {
        FILE *tp;
        struct stat stb;
@@ -251,15 +268,17 @@ notify(struct utmp *utp, off_t offset)
            "\n" : "\n\r";
        memcpy(name, utp->ut_name, UT_NAMESIZE);
        name[UT_NAMESIZE] = '\0';
-       (void)fprintf(tp, "%s\007New mail for %s@%.*s\007 has arrived:%s----%s",
-           cr, name, (int)sizeof(hostname), hostname, cr, cr);
-       jkfprintf(tp, name, offset);
+       (void)fprintf(tp, "%s\007New mail for %s@%.*s\007 has 
arrived%s%s%s:%s----%s",
+           cr, name, (int)sizeof(hostname), hostname,
+           folder ? cr : "", folder ? "to " : "", folder ? file : "",
+           cr, cr);
+       jkfprintf(tp, name, file, offset);
        (void)fclose(tp);
        _exit(0);
 }
 
 void
-jkfprintf(FILE *tp, char name[], off_t offset)
+jkfprintf(FILE *tp, char user[], char file[], off_t offset)
 {
        char *cp, ch;
        char visout[5], *s2;
@@ -269,12 +288,12 @@ jkfprintf(FILE *tp, char name[], off_t o
        char line[BUFSIZ];
 
        /* Set effective uid to user in case mail drop is on nfs */
-       if ((p = getpwnam(name)) != NULL) {
+       if ((p = getpwnam(user)) != NULL) {
                (void) seteuid(p->pw_uid);
                (void) setuid(p->pw_uid);
        }
 
-       if ((fi = fopen(name, "r")) == NULL)
+       if ((fi = fopen(file, "r")) == NULL)
                return;
 
        (void)fseeko(fi, offset, SEEK_SET);

Reply via email to