Я нашел Perl-скрипт, который проверяет учетную запись электронной почты и пересылает содержимое на телефон GSM. Он использует код ниже, чтобы определить тело письма. Это может отличаться для каждого пакета электронной почты, поэтому на самом деле не работает. Вместо этого я собирался получить #
в начале тела письма, как бы я это сделал?
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;