Download the file
  1. #!/usr/bin/perl -w
  2.  
  3. # (c) Matthieu Weber 2004
  4. # Distributed under the terms of the GNU General Public License (GPL)
  5. # http://www.gnu.org/copyleft/gpl.html
  6.  
  7. $cmd_file = "$ENV{HOME}/.mailing_list_options";
  8.  
  9. sub mail {
  10. my ($dest, $subj) = @_;
  11. open(MAIL, "|mutt -s '$subj' '$dest' < /dev/stdin");
  12. print MAIL "$subj";
  13. close(MAIL);
  14. #print "mail to $dest with subj $subj\n";
  15. }
  16.  
  17. sub url {
  18. my $url = shift;
  19. open(VIEW, "|urlview");
  20. print VIEW "$url";
  21. close (VIEW);
  22. }
  23.  
  24. sub prompt_user {
  25. print "\nMailing list $list_name ($list_type) commands:\n";
  26. foreach $c (sort keys(%command)) {
  27. print " $c\n";
  28. }
  29. print "\nYour choice: ";
  30. $ans = <>;
  31. $ans =~ s/\r?\n//;
  32. if ($ans eq "") {
  33. print "Abort.\n";
  34. return 1;
  35. }
  36. if (exists $command{$ans}) {
  37. if (exists $command{$ans}->{subject}) {
  38. my $subject = $command{$ans}->{subject};
  39. if ($subject =~ /%p/) {
  40. print "Password for list $list_name: ";
  41. $pass = <>;
  42. $pass =~ s/\r?\n//;
  43. $subject =~ s/%p/$pass/e;
  44. }
  45. &mail($destination, $subject);
  46. }
  47. return 0;
  48. }
  49. else {
  50. print "No such command. Abort\n";
  51. return 1;
  52.  
  53. }
  54. }
  55.  
  56. sub write_commands {
  57. if (! defined $destination || $destination eq "") {
  58. print "Parsing failed. Is this a mailing-list message?\n";
  59. return 1;
  60. }
  61. open F, ">$cmd_file";
  62. chmod 0600, "$cmd_file";
  63. print F "\$destination = '$destination';\n";
  64. print F "\$list_name = '$list_name';\n";
  65. print F "\$list_type = '$list_type';\n";
  66. print F "\%command = (\n";
  67. foreach $k (keys(%command)) {
  68. print F "'$k' => {";
  69. foreach $sk (keys(%{$command{$k}})) {
  70. print F "'$sk' => '$command{$k}->{$sk}', ";
  71. }
  72. print F "},\n";
  73. }
  74. print F ");\n";
  75. print F "1;\n";
  76. close F;
  77. return 0;
  78. }
  79.  
  80. if (! -f $cmd_file) {
  81. $/="\n\n";
  82. $h = <>;
  83. $/="\n";
  84. $h =~ s/\n\s+/ /gs;
  85. $h =~ s/^From (.*)\n//gm;
  86. $h =~ s/^([^:]+): /$1\n/gm;
  87. %hdr = split /\n/, $h;
  88.  
  89. if (exists $hdr{"List-software"} && $hdr{"List-software"} =~ /Ecartis/) {
  90. # Ecartis
  91. ($destination) = ($hdr{"List-help"} =~ /mailto:([^\>\?]+)/);
  92. $list_name = $hdr{"List-Id"};
  93. $list_name =~ s/ .*$//;
  94.  
  95. $list_type = "Listar";
  96. %command = (
  97. "subscribe" => { "subject" => "subscribe $list_name" },
  98. "unsubscribe" => { "subject" => "unsubscribe $list_name" },
  99. "help" => { "subject" => "help" },
  100. "set_vacation" => { "subject" => "set $list_name vacation" },
  101. "unset_vacation" => { "subject" => "unset $list_name vacation" },
  102. "status" => { "subject" => "stats $list_name" },
  103. );
  104. }
  105. elsif (exists $hdr{"X-Mailman-Version"}) {
  106. # Mailman
  107. ($destination) = ($hdr{"List-Help"} =~ /mailto:([^\>\?]+)/);
  108. ($list_name) = ($hdr{"List-Id"} =~ /<([^\.]+)/);
  109.  
  110. $list_type = "Mailman";
  111. %command = (
  112. "subscribe" => { "subject" => "subscribe \%p" },
  113. "unsubscribe" => { "subject" => "unsubscribe \%p" },
  114. "help" => { "subject" => "help" },
  115. "set_vacation" => { "subject" => "set nomail on \%p" },
  116. "unset_vacation" => { "subject" => "set nomail off \%p" },
  117. "options" => { "subject" => "options" },
  118. );
  119. }
  120. elsif (exists $hdr{"X-Mailing-List"} && $hdr{"X-Mailing-List"} =~ /korppi\.jyu\.fi/) {
  121. ($destination) = ($hdr{"List-Help"} =~ /mailto:([^\>\?]+)/);
  122. ($list_name) = ($hdr{"List-Help"} =~ /mailto:([^@]+)/);
  123. print "$destination\n";
  124.  
  125. $list_type = "Korppi";
  126. %command = (
  127. "subscribe" => { "subject" => "subscribe" },
  128. "unsubscribe" => { "subject" => "unsubscribe" },
  129. "help" => { "subject" => "help" },
  130. "archive_help" => { "subject" => "archive help" },
  131. );
  132. }
  133. $exit_code = &write_commands();
  134. }
  135. else {
  136. require "$cmd_file";
  137. $exit_code = &prompt_user();
  138. unlink "$cmd_file";
  139. }
  140.  
  141. exit $exit_code;
  142.