aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/upas/common/mail.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2005-10-29 16:26:44 +0000
committerrsc <devnull@localhost>2005-10-29 16:26:44 +0000
commit5cdb17983ae6e6367ad7a940cb219eab247a9304 (patch)
tree8ca1ef49af2a96e7daebe624d91fdf679814a057 /src/cmd/upas/common/mail.c
parentcd3745196389579fb78b9b01ef1daefb5a57aa71 (diff)
downloadplan9port-5cdb17983ae6e6367ad7a940cb219eab247a9304.tar.gz
plan9port-5cdb17983ae6e6367ad7a940cb219eab247a9304.tar.bz2
plan9port-5cdb17983ae6e6367ad7a940cb219eab247a9304.zip
Thanks to John Cummings.
Diffstat (limited to 'src/cmd/upas/common/mail.c')
-rw-r--r--src/cmd/upas/common/mail.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/cmd/upas/common/mail.c b/src/cmd/upas/common/mail.c
new file mode 100644
index 00000000..5347c655
--- /dev/null
+++ b/src/cmd/upas/common/mail.c
@@ -0,0 +1,57 @@
+#include "common.h"
+
+/* format of REMOTE FROM lines */
+char *REMFROMRE =
+ "^>?From[ \t]+((\".*\")?[^\" \t]+?(\".*\")?[^\" \t]+?)[ \t]+(.+)[ \t]+remote[ \t]+from[ \t]+(.*)\n$";
+int REMSENDERMATCH = 1;
+int REMDATEMATCH = 4;
+int REMSYSMATCH = 5;
+
+/* format of LOCAL FROM lines */
+char *FROMRE =
+ "^>?From[ \t]+((\".*\")?[^\" \t]+?(\".*\")?[^\" \t]+?)[ \t]+(.+)\n$";
+int SENDERMATCH = 1;
+int DATEMATCH = 4;
+
+/* output a unix style local header */
+int
+print_header(Biobuf *fp, char *sender, char *date)
+{
+ return Bprint(fp, "From %s %s\n", sender, date);
+}
+
+/* output a unix style remote header */
+int
+print_remote_header(Biobuf *fp, char *sender, char *date, char *system)
+{
+ return Bprint(fp, "From %s %s remote from %s\n", sender, date, system);
+}
+
+/* parse a mailbox style header */
+int
+parse_header(char *line, String *sender, String *date)
+{
+ if (!IS_HEADER(line))
+ return -1;
+ line += sizeof("From ") - 1;
+ s_restart(sender);
+ while(*line==' '||*line=='\t')
+ line++;
+ if(*line == '"'){
+ s_putc(sender, *line++);
+ while(*line && *line != '"')
+ s_putc(sender, *line++);
+ s_putc(sender, *line++);
+ } else {
+ while(*line && *line != ' ' && *line != '\t')
+ s_putc(sender, *line++);
+ }
+ s_terminate(sender);
+ s_restart(date);
+ while(*line==' '||*line=='\t')
+ line++;
+ while(*line)
+ s_putc(date, *line++);
+ s_terminate(date);
+ return 0;
+}