URI:
       tmlowner.c - plan9port - [fork] Plan 9 from user space
  HTML git clone git://src.adamsgaard.dk/plan9port
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
       tmlowner.c (1135B)
       ---
            1 #include "common.h"
            2 #include "dat.h"
            3 
            4 Biobuf in;
            5 
            6 String *from;
            7 String *sender;
            8 
            9 
           10 void
           11 usage(void)
           12 {
           13         fprint(2, "usage: %s address-list-file listname\n", argv0);
           14         exits("usage");
           15 }
           16 
           17 void
           18 main(int argc, char **argv)
           19 {
           20         String *msg;
           21         char *alfile;
           22         char *listname;
           23 
           24         ARGBEGIN{
           25         }ARGEND;
           26 
           27         rfork(RFENVG);
           28 
           29         if(argc < 2)
           30                 usage();
           31         alfile = argv[0];
           32         listname = argv[1];
           33 
           34         if(Binit(&in, 0, OREAD) < 0)
           35                 sysfatal("opening input: %r");
           36 
           37         msg = s_new();
           38 
           39         /* discard the 'From ' line */
           40         if(s_read_line(&in, msg) == nil)
           41                 sysfatal("reading input: %r");
           42 
           43         /* read up to the first 128k of the message.  more is redculous */
           44         if(s_read(&in, s_restart(msg), 128*1024) <= 0)
           45                 sysfatal("reading input: %r");
           46 
           47         /* parse the header */
           48         yyinit(s_to_c(msg), s_len(msg));
           49         yyparse();
           50 
           51         /* get the sender */
           52         getaddrs();
           53         if(from == nil)
           54                 from = sender;
           55         if(from == nil)
           56                 sysfatal("message must contain From: or Sender:");
           57 
           58         if(strstr(s_to_c(msg), "remove")||strstr(s_to_c(msg), "unsubscribe"))
           59                 writeaddr(alfile, s_to_c(from), 1, listname);
           60         else if(strstr(s_to_c(msg), "subscribe"))
           61                 writeaddr(alfile, s_to_c(from), 0, listname);
           62 
           63         exits(0);
           64 }