Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
use strict; use warnings; use Unix::PasswdFile; use HTTP::Cookies; use XML::Simple; use MIME::Lite; use Mail::Box::Mbox; use URI::Escape; require LWP::UserAgent; require HTTP::Request; use vars qw ($username $host $maildir $msgsleep $usersleep $configfile $cookiefile $pmurl %users); ### BEGINNING OF USER SETTINGS ####################################### +######### $username = 'msgmail'; # Username of the daemon. $host = 'localhost'; # Host of the msgmail daemon. $maildir = '/var/spool/mail'; # Location of mbox mail "folders". $msgsleep = 5; # Time (in minutes) between /msg che +cks. $usersleep = 60; # Time (in minutes) between checks for ne +w users. $configfile = '.msgmail'; # Name of config file in each user's home +dir. $cookiefile = '.msgmail_cookie'; # Name of cookie file in each user' +s homedir. $pmurl = 'http://www.perlmonks.org/'; # Url of PerlMonks. ### END OF USER SETTINGS ############################################# +######### { init(); my $i = 0; for ( ; ; ) { if ( $i == $usersleep ) { getUsers(); $i = 0; } for my $user ( keys %users ) { my $msgreq = HTTP::Request->new( GET => "$pmurl?node_id=15 +848" ); $users{$user}{ua}->cookie_jar->add_cookie_header($msgreq); ( my $xml = XMLin( $users{$user}{ua}->simple_request($msgreq)->{_con +tent}, forcearray => 1 ) ) || next(); for my $msg ( @{ $$xml{message} } ) { if ( $$msg{content} =~ m/\[(.*?)\] announcement -- / ) + { my $temp_auth = $1; $$msg{content} =~ s/--/-- [$$msg{author}] says:/; $$msg{author} = $temp_auth; } my $mail = MIME::Lite->new( From => "$username\@$host", To => $users{$user}{email}, Subject => "/msgmail from $$msg{author} " . "[$$msg{author}:$user:" . crypt( $users{$user}{passwd}, $user ) . "]", Data => $$msg{content} ); if ( $mail->send ) { my $delreq = HTTP::Request->new( HEAD => "$pmurl?op=message&deletemsg_$$msg{message_id}=y +up" ); $users{$user}{ua}->cookie_jar->add_cookie_header($ +delreq); $users{$user}{ua}->simple_request($delreq); } } } my $folder = Mail::Box::Mbox->new( folder => "=$username", folderdir => $ +maildir, access => 'rw' ); for (@$folder) { ( my ( $to, $from, $passwd ) = $_->subject() =~ m/\[(.*?):(.*?):(.*?)\]/ ) || $_->delete() && next(); if ( $passwd ne crypt( $users{$from}{passwd}, $from ) ) { $_->delete() && next(); } my $text = $_->body(); $text =~ s/\n/ /g; $text = uri_escape($text); my $sendreq = HTTP::Request->new( HEAD => "$pmurl?op=message&message=/msg\%20$to\%20$text" ); $users{$from}{ua}->cookie_jar->add_cookie_header($sendreq) +; $users{$from}{ua}->simple_request($sendreq) && $_->delete( +); } $folder->close(); $i++; sleep($msgsleep); } } sub getUsers { my $pw = Unix::PasswdFile->new("/etc/passwd"); foreach ( $pw->users() ) { open( FILE, "<" . $pw->home($_) . "/$configfile" ) || next(); chomp( my $line = <FILE> ); close(FILE); my ( $user, $passwd, $email ) = split ( /\|/, $line ); my $ua = LWP::UserAgent->new(); $ua->cookie_jar( HTTP::Cookies->new( File => $pw->home($_) . "/$cookiefile", AutoSave => 1, ignore_discard => 1 ) ); $ua->cookie_jar->load( $pw->home($_) . "/$cookiefile" ); $ua->simple_request( HTTP::Request->new( GET => "$pmurl?user=$user&passwd=$passwd&op=login" ) ) || next(); $ua->cookie_jar->save() || next(); $users{$_} = { ua => $ua, email => $email, passwd => $passwd } +; } } sub init { # Initializes stuff for the program to use. getUsers(); $usersleep = int( $usersleep / $msgsleep ); $msgsleep *= 60; MIME::Lite->send( 'smtp', 'localhost', Timeout => 60 ); }

In reply to msgmail.pl by zdog

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (12)
    As of 2014-11-27 17:18 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My preferred Perl binaries come from:














      Results (186 votes), past polls