开发者

How to alter email2sms script to search for qualifier WARNING: blatant Plagiarism

I found a perl script that checks an email account and forwards the contents to a gsm phone. It uses below code to determine the body of the email. This can be different for each email package so doesn't really work. I was going to have a # at the beginning of the email body instead, how would go about doing this?

  sub ProcessEmail
 {
   # Assign parameter to a local variable
   my (@lines) = @_;
   my $body_start = 'FALSE';
   $sms_body = "";

   # Declare local variables开发者_开发问答
   my ($from, $line, $sms_to);

   # Check each line in the header
   foreach $line (@lines)
   {
 print $line;
     if($line =~ m/^From: (.*)/)
     {
        # We found the "From" field, so let's get what we need
        $from = $1;
        $from =~ s/"|<.*>//g;
        $from = substr($from, 0, 39);               # This gives us the 'From' Name
    }
    elsif( $line =~ m/^Subject: (.*)/)
    {
        # We found the "Subject" field. This contains the No to send the SMS to.

       $sms_to   = $1;
        $sms_to = substr($sms_to, 0, 29);

       if ($sms_to =~ /^[+]?\d+$/ )             # here we check if the subject is a no. If so we proceed.
       {
           print "Got email. Subject is a number. Processing further\n";
       }
   else #Otherwise we delete the message and ignore it.
       {
        print "Got email. Subject is NOT a number. Ignoring it. \n";
        return;
      }
     } 
   elsif(( $line =~ m/^Envelope-To:/)||($body_start eq 'TRUE')) # This is the last line in the email header
    {          # after this the body starts
   if($body_start ne 'FALSE')
   {
   $sms_body = $sms_body . $line;
   }
       $body_start='TRUE';
    }
   }

   # At this point we know the Subject, From and Body.
   # So we can send the SMS out to the provided no.

   $sms_body = "SMS via Email2SMS from $from: " . $sms_body;

   # You can only send SMS in chunks of 160 chars Max according to gnokii. 
   # so breaking the body into chunks of 160 and sending them 1 at a time.
 print  $sms_to;
 print $sms_body;


This is something you'll be able to avoid re-inventing by using a module from CPAN to handle it.

At a quick glance, Mail::Message::Body from the Mail::Box distribution looks like it should probably do the job. See also Email::Abstract.


Altered to search for a string that was specific to the mailer. Nasty and will only work from a specific mail sender, but it worked

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜