[Sussex] Procmail Recipies

John Crowhurst fyremoon at fyremoon.net
Sat Dec 6 14:16:59 UTC 2003


> All,
>
> I'm trying to automate playing of mp3s via email to see what procmail
> can do.
>
> My files look like this:
>
> .procmailrc
>
> :0
> | $FORMAIL -tzxSubject: | /home/auto/play.pl
>
>
> /home/auto/play.pl
>
> #!/usr/bin/perl
>
> $playlist = <STDIN>;
> system("/usr/bin/mplayer $playlist");
>
>
>
> If I do
>
> auto at localhost auto$ echo chill | ./play.pl
>
> it works fine, and running formail strips the correct subject (chill)
> out of my email, but somewhere its not working!
>
> the file "chill" is an m3u playlist without an extension, and works in
> both xmms and mplayer.

Hmm, why not just take the entire message into your script, parse for
Subject and process the result.

In my .procmailrc you could have:

EMAIL_ADDRESS=your at email.address.here
:0
* !^FROM_DAEMON
* !^X-Loop: $EMAIL_ADDRESS
  | /home/myhome/play.pl

In the play script you could have:
#!/usr/bin/perl
$playlistdir="/path/to/playlist";
$found=0;
while (<STDIN>) {
  $inp=$_;
  # Check to see if we have already processed a Subject header
  if ($found eq 0) {
    # Check to see if we have the Subject header
    if ($inp =~ /^Subject/) {
      $found=1;
      ($key, $value) = split (/:/,$inp);
      # If the playlist exists, play the list through mplayer
      if (-f "$playlistdir/$value") {
         `/path/to/mplayer $playlistdir/$value`;
      }
    }
  }
}

--
John






More information about the Sussex mailing list