11 void printmsg(int fd, String *msg, char *replyto, char *listname);
12 void appendtoarchive(char* listname, String *firstline, String *msg);
13 void printsubject(int fd, Field *f, char *listname);
18 fprint(2, "usage: %s address-list-file listname\n", argv0);
23 main(int argc, char **argv)
27 char *listname, *alfile;
30 char *replytoname = nil;
44 if(replytoname == nil)
45 replytoname = listname;
49 if(Binit(&in, 0, OREAD) < 0)
50 sysfatal("opening input: %r");
55 /* discard the 'From ' line */
56 if(s_read_line(&in, firstline) == nil)
57 sysfatal("reading input: %r");
59 /* read up to the first 128k of the message. more is redculous.
60 Not if word documents are distributed. Upped it to 2MB (pb) */
61 if(s_read(&in, msg, 2*1024*1024) <= 0)
62 sysfatal("reading input: %r");
64 /* parse the header */
65 yyinit(s_to_c(msg), s_len(msg));
73 sysfatal("message must contain From: or Sender:");
74 if(strcmp(listname, s_to_c(from)) == 0)
75 sysfatal("can't remail messages from myself");
76 addaddr(s_to_c(from));
78 /* start the mailer up and return a pipe to it */
79 fd = startmailer(listname);
81 /* send message adding our own reply-to and precedence */
82 printmsg(fd, msg, replytoname, listname);
85 /* wait for mailer to end */
87 if(w->msg != nil && w->msg[0])
88 sysfatal("%s", w->msg);
92 /* if the mailbox exits, cat the mail to the end of it */
93 appendtoarchive(listname, firstline, msg);
97 /* send message filtering Reply-to out of messages */
99 printmsg(int fd, String *msg, char *replyto, char *listname)
107 for(f = firstfield; f; f = f->next){
109 for(p = f->node; p; p = p->next)
111 if(f->node->c == REPLY_TO)
113 if(f->node->c == PRECEDENCE)
115 if(f->node->c == SUBJECT){
119 write(fd, ocp, cp-ocp);
121 printsubject(fd, subject, listname);
122 fprint(fd, "Reply-To: %s\nPrecedence: bulk\n", replyto);
123 write(fd, cp, s_len(msg) - (cp - s_to_c(msg)));
126 /* if the mailbox exits, cat the mail to the end of it */
128 appendtoarchive(char* listname, String *firstline, String *msg)
134 mboxpath("mbox", listname, mbox, 0);
135 if(access(s_to_c(mbox), 0) < 0)
137 fd = open(s_to_c(mbox), OWRITE);
141 write(fd, s_to_c(firstline), s_len(firstline));
142 write(fd, s_to_c(msg), s_len(msg));
145 /* add the listname to the subject */
147 printsubject(int fd, Field *f, char *listname)
153 if(f == nil || f->node == nil){
154 fprint(fd, "Subject: [%s]\n", listname);
157 s = e = f->node->end + 1;
158 for(p = f->node; p; p = p->next)
161 ln = smprint("[%s]", listname);
162 if(ln != nil && strstr(s, ln) == nil)
163 fprint(fd, "Subject: %s%s\n", ln, s);
165 fprint(fd, "Subject:%s\n", s);