Submitted by: Damon Harper
Date: 2006-08-26, 2007-09-21
Summary: Add some new escapes to comsatd / .biffrc
This patch introduces two new escapes for use in comsatd's .biffrc:
$f: The full pathname of the mailbox file where the new mail is found.
$o: The offset into $f where the new mail starts.
This allows things like echoing the mailbox pathname when mail might
be in one of a number of inboxes, or passing the pathname and offset
to another program. For instance, I call a perl script that
rebroadcasts the comsat message "address@hidden:$f" to my workstation).
The patch is implemented by making path and offset global variables
within comsatd.
diff -urN mailutils-1.2.orig/comsat/action.c mailutils-1.2/comsat/action.c
--- mailutils-1.2.orig/comsat/action.c 2007-06-27 05:07:16.000000000 -0700
+++ mailutils-1.2/comsat/action.c 2007-09-21 02:02:48.000000000 -0700
@@ -18,6 +18,7 @@
MA 02110-1301 USA */
#include "comsat.h"
+#include
#define obstack_chunk_alloc malloc
#define obstack_chunk_free free
#include
@@ -96,6 +97,7 @@
mu_stream_t stream;
int rc = 1;
size_t size = 0, lncount = 0;
+ char *offset_str;
switch (*++p) /* skip past $ */
{
@@ -113,6 +115,21 @@
rc = 0;
break;
+ case 'f':
+ len = strlen (path);
+ obstack_grow (stk, path, len);
+ *pp = p;
+ rc = 0;
+ break;
+
+ case 'o':
+ offset_str = mu_umaxtostr(0, offset);
+ len = strlen (offset_str);
+ obstack_grow (stk, offset_str, len);
+ *pp = p;
+ rc = 0;
+ break;
+
case 'H':
/* Header field */
if (*++p != '{')
diff -urN mailutils-1.2.orig/comsat/comsat.c mailutils-1.2/comsat/comsat.c
--- mailutils-1.2.orig/comsat/comsat.c 2007-06-27 05:07:16.000000000 -0700
+++ mailutils-1.2/comsat/comsat.c 2007-09-21 02:02:38.000000000 -0700
@@ -104,7 +104,7 @@
static void comsat_daemon_init (void);
static void comsat_daemon (int _port);
static int comsat_main (int fd);
-static void notify_user (const char *user, const char *device, const char *path, off_t offset);
+static void notify_user (const char *user, const char *device);
static int find_user (const char *name, char *tty);
static char *mailbox_path (const char *user);
static void change_user (const char *user);
@@ -226,6 +226,8 @@
time_t overflow_control_interval = 10; /* Overflow control interval */
time_t overflow_delay_time = 5;
+char *path = NULL; /* Will contain the mailbox filename */
+size_t offset; /* Will contain the offset of message within mailbox */
void
comsat_daemon (int port)
@@ -325,8 +327,6 @@
pid_t pid;
char tty[MAX_TTY_SIZE];
char *p, *endp;
- size_t offset;
- char *path = NULL;
len = sizeof sin_from;
rdlen = recvfrom (fd, buffer, sizeof buffer, 0,
@@ -400,7 +400,7 @@
}
/* Child: do actual I/O */
- notify_user (buffer, tty, path, offset);
+ notify_user (buffer, tty);
exit (0);
}
@@ -423,7 +423,7 @@
/* NOTE: Do not bother to free allocated memory, as the program exits
immediately after executing this */
static void
-notify_user (const char *user, const char *device, const char *path, off_t offset)
+notify_user (const char *user, const char *device)
{
FILE *fp;
const char *cr;
diff -urN mailutils-1.2.orig/comsat/comsat.h mailutils-1.2/comsat/comsat.h
--- mailutils-1.2.orig/comsat/comsat.h 2007-06-27 05:07:16.000000000 -0700
+++ mailutils-1.2/comsat/comsat.h 2007-09-21 02:02:38.000000000 -0700
@@ -76,6 +76,8 @@
extern const char *username;
extern char hostname[];
extern struct daemon_param daemon_param;
+extern char *path;
+extern size_t offset;
extern void read_config (const char *config_file);
int acl_match (struct sockaddr_in *sa_in);
diff -urN mailutils-1.2.orig/doc/texinfo/mailutils.info-1 mailutils-1.2/doc/texinfo/mailutils.info-1
--- mailutils-1.2.orig/doc/texinfo/mailutils.info-1 2007-06-29 05:01:17.000000000 -0700
+++ mailutils-1.2/doc/texinfo/mailutils.info-1 2007-09-21 02:02:38.000000000 -0700
@@ -4043,6 +4043,12 @@
$h
Expands to hostname
+$f
+ Expands to the name of the folder containing the new message.
+
+$o
+ Expands to the offset in $f where the new message starts.
+
$H{name}
Expands to value of message header `name'.
diff -urN mailutils-1.2.orig/doc/texinfo/programs.texi mailutils-1.2/doc/texinfo/programs.texi
--- mailutils-1.2.orig/doc/texinfo/programs.texi 2007-02-25 10:08:35.000000000 -0800
+++ mailutils-1.2/doc/texinfo/programs.texi 2007-09-21 02:02:38.000000000 -0700
@@ -4121,6 +4121,10 @@
Expands to username
@item $h
Expands to hostname
address@hidden $f
+Expands to the name of the folder containing the new message.
address@hidden $o
+Expands to the offset in $f where the new message starts.
@item address@hidden@}
Expands to value of message header @samp{name}.
@item $B(@var{c},@var{l})