mlowner.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "common.h"
  2. #include "dat.h"
  3. Biobuf in;
  4. String *from;
  5. String *sender;
  6. void
  7. usage(void)
  8. {
  9. fprint(2, "usage: %s address-list-file listname\n", argv0);
  10. exits("usage");
  11. }
  12. void
  13. main(int argc, char **argv)
  14. {
  15. String *msg;
  16. char *alfile;
  17. char *listname;
  18. ARGBEGIN{
  19. }ARGEND;
  20. rfork(RFENVG|RFREND);
  21. if(argc < 2)
  22. usage();
  23. alfile = argv[0];
  24. listname = argv[1];
  25. if(Binit(&in, 0, OREAD) < 0)
  26. sysfatal("opening input: %r");
  27. msg = s_new();
  28. /* discard the 'From ' line */
  29. if(s_read_line(&in, msg) == nil)
  30. sysfatal("reading input: %r");
  31. /* read up to the first 128k of the message. more is ridiculous */
  32. if(s_read(&in, s_restart(msg), 128*1024) <= 0)
  33. sysfatal("reading input: %r");
  34. /* parse the header */
  35. yyinit(s_to_c(msg), s_len(msg));
  36. yyparse();
  37. /* get the sender */
  38. getaddrs();
  39. if(from == nil)
  40. from = sender;
  41. if(from == nil)
  42. sysfatal("message must contain From: or Sender:");
  43. if(strstr(s_to_c(msg), "remove")||strstr(s_to_c(msg), "unsubscribe"))
  44. writeaddr(alfile, s_to_c(from), 1, listname);
  45. else if(strstr(s_to_c(msg), "subscribe"))
  46. writeaddr(alfile, s_to_c(from), 0, listname);
  47. exits(0);
  48. }