2011-07-16 26 views
0

我發現一個perl腳本,檢查電子郵件帳戶,並將內容轉發到gsm手機。它使用下面的代碼來確定電子郵件的正文。對於每個電子郵件包,這可能會有所不同,因此實際上並不奏效我將在電子郵件正文的開頭部署一個#,而如何去做這件事?如何更改email2sms腳本搜索限定符警告:blatant剽竊

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; 

回答

0

更改爲搜索特定於郵件程序的字符串。討厭,只會從一個特定的郵件發件人工作,但它的工作

1

這是你可以避免通過使用CPAN模塊來處理它重新發明的東西。

快速瀏覽一下,Mail :: Box發行版中的Mail::Message::Body看起來應該可能完成這項工作。另請參閱Email::Abstract