1
전자 메일의 머리글과 텍스트를 구분하는 PHP 스크립트가 있습니다. 필자는 이메일을 사용자의 입력 파일로 사용할 수 있도록 Perl 스크립트로 변환하려고했습니다.PHP 스크립트를 변경하여 Perl 스크립트로 실행
#!/usr/bin/php
<?php
//debug
#ini_set ("display_errors", "1");
#error_reporting(E_ALL);
//include email parser
require_once('/path/to/class/rfc822_addresses.php');
require_once('/path/to/class/mime_parser.php');
// read email in from stdin
$fd = fopen(ARGV[0], "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
//create the email parser class
$mime=new mime_parser_class;
$mime->ignore_syntax_errors = 1;
$parameters=array(
'Data'=>$email,
);
$mime->Decode($parameters, $decoded);
//---------------------- GET EMAIL HEADER INFO -----------------------//
//get the name and email of the sender
$fromName = $decoded[0]['ExtractedAddresses']['from:'][0]['name'];
$fromEmail = $decoded[0]['ExtractedAddresses']['from:'][0]['address'];
//get the name and email of the recipient
$toEmail = $decoded[0]['ExtractedAddresses']['to:'][0]['address'];
$toName = $decoded[0]['ExtractedAddresses']['to:'][0]['name'];
//get the subject
$subject = $decoded[0]['Headers']['subject:'];
$removeChars = array('<','>');
//get the message id
$messageID = str_replace($removeChars,'',$decoded[0]['Headers']['message-id:']);
//get the reply id
$replyToID = str_replace($removeChars,'',$decoded[0]['Headers']['in-reply-to:']);
//---------------------- FIND THE BODY -----------------------//
//get the message body
if(substr($decoded[0]['Headers']['content-type:'],0,strlen('text/plain')) == 'text/plain' && isset($decoded[0]['Body'])){
$body = $decoded[0]['Body'];
} elseif(substr($decoded[0]['Parts'][0]['Headers']['content-type:'],0,strlen('text/plain')) == 'text/plain' && isset($decoded[0]['Parts'][0]['Body'])) {
$body = $decoded[0]['Parts'][0]['Body'];
} elseif(substr($decoded[0]['Parts'][0]['Parts'][0]['Headers']['content-type:'],0,strlen('text/plain')) == 'text/plain' && isset($decoded[0]['Parts'][0]['Parts'][0]['Body'])) {
$body = $decoded[0]['Parts'][0]['Parts'][0]['Body'];
}
//print out our data
echo "
Message ID: $messageID
Reply ID: $replyToID
Subject: $subject
To: $toName $toEmail
From: $fromName $fromEmail
Body: $body
";
//show all the decoded email info
print_r($decoded);
난 그냥 내가 그것을 펄 스크립트로 실행할 수 있도록해야 변경됩니다 무엇인지 알 필요가 : 다음은 PHP 스크립트입니다?
당신이 펄에서 nativly를 실행하고 싶다면 perl로 다시 작성해야합니다! – Sgoettschkes
perl과 php가 다른 언어이기 때문에 첫 번째 # 이후 거의 모든 것을 바꿔야합니다. – AD7six
http://p3rl.org/Courriel은 MIME 메시지를 구문 분석합니다. – daxim