更新:在发布新问题之前,请阅读此问题的答案!谢谢。
这是为了工作。(我在 Acenet, Inc - 一个网络主机商工作 - 所以我的代码将被清除重要的登录信息和其他 API 数据)。我需要一些关于我正在编写的脚本的帮助:
<?php
/* lothbrok.php - abuse notification email-reader & ticket-injector script for Acenet Inc */
/*
*
* "One script to rule them all,
* One script to find them.
* One script to bring them home,
* And in the darkness, bind them."
*
*/
if ($_GET['worms'] != "food") {
echo "Sorry, but you are not authorized to run LOTHBROK today! Goodbye!";
exit;
} else {
require("email_functions.php");
global $timeout, $error, $buffer;
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Pragma: no-cache");
ob_start();
//-----------------------------------------------------------------------------
// Declarations
//-----------------------------------------------------------------------------
$error = ""; // Error string.
$timeout = 90; // Default timeout before giving up on a network operation.
$Count = -1; // Mailbox msg count
$buffer = 512; // Socket buffer for socket fgets() calls, max per RFC 1939 the returned line a POP3 server can send is 512 bytes.
$server = "SANITIZED"; // Set this to hard code the server name
$RFC1939 = false; // Set by noop(). See rfc1939.txt
$msg_list_array = array(); // List of messages from server
$login = 'SANITIZED';
$pass = 'SANITIZED';
//-----------------------------------------------------------------------------
// The Code
//-----------------------------------------------------------------------------
echo "<h1>LOTHBROK</h1><h2>Starting Program</h2><br>";
set_time_limit($timeout);
$fp = connect ($server, $port = 110);
$Count = login($login,$pass, $fp);
if( (!$Count) or ($Count == -1) )
{
exit;
}// end if
if ($Count < 1)
{
die();
} else {
echo "Login OK: Inbox contains [$Count] messages<BR>\n";
$msg_list_array = uidl("", $fp);
set_time_limit($timeout);
}// end if
// loop thru the array to get each message
for ($i=1; $i <= $Count; $i++){
set_time_limit($timeout);
$MsgOne = top($i, empty($numLines), $fp);
if( (!$MsgOne) or (gettype($MsgOne) != "array") )
{
echo "oops, Message not returned by the server.<BR>\n";
exit;
}// end if
/*
call the function to read the message
returns true if access, breakdown and insertion
in to db are completed sucessfully
*/
/*
Function to read the message and extract :
a. subject
b. date
c. split the body line by line
*/
$body = ''; // get the body of the message into 1 variable
$subjects = ''; // get the subject of the email
$dates = ''; // get the date of the email
$body_start_key = false; // body starts at blank line, blank line is separator for from headers to body
$TIRSFlag = false; // flag for seeing if the email is really to be processed by the app
$base64Flag = false; // flag to handle base 64 encoding by email systems.
foreach ($MsgOne as $key => $value)
{
if (trim($value) == "Content-Transfer-Encoding: base64"){
$base64Flag = true;
}//end if
//get the subject line of the email
preg_match("/^(Subject\:) (.*)\r?\n$/i",$subjects,$subject);
//look for "FBL" in the subject to see if we need to attempt to process the email
if (strstr($subject,"FBL")) {
$TIRSFlag = true;
}// end if
}// end if
//get the date of the email
preg_match("/(Date\:) ^([A-Za-z]{3}), ([0-9]{2}) ([A-Za-z]{3}) ([0-9]{4}) ([0-9]{2})\:([0-9]{2})\:([0-9]{2}) \-?([0-9]{4})$\r?\n/i",$subjects,$dates);
// Grab the message body
$MsgOne = get($i, $fp);
//the body
if (strlen(trim($value))==0){
if ($body_start_key == false){ $body_start_key = true; } //set the start key for the body
}//end if
if ($body_start_key == true){
$body .= trim($value);
if ($base64Flag == false){ $body .="<br />"; }
}// end if
}// end foreach
// only create support ticket(s) if the subject line contains the acronym "FBL"
if ($TIRSFlag == false){
echo "<br>Nothing to read - finished.</b>";
exit;
}else{
//decode the message if its base64 encoded
if ($base64Flag == true) {
$body = base64_decode($body);
} //end if
}
//convert the body crlf to <br> tags if not done when the message was built
$body = nl2br($body);
$body = preg_replace("/^(Please investigate these FBL reports accordingly and create a ticket for the client if need be.)$/i"," ",$body);
$body = preg_replace("/^(Acenet) (AOL|Comcast|Yahoo!?|Hotmail) (FBL Bot)$/i"," ",$body);
/* Cordoned off in case something doesn't work and this is then neeeded.....
$dayn = substr($date,0,2);
$day = substr($date,6,7);
$monn = substr($date,9,11);
$monn = substr($date,9,11);
$year = substr($date,13,16);
$fhrd = substr($date,18,19);
$mind = substr($date,20,21);
$secd = substr($date,22,23);
$msed = substr($date,26,30);
End of Quarantine! :D .... */
while (preg_match("/(THIS IS AN AUTOMATED ABUSE ALERT - DO NOT REPLY)/i",$body) && $dates > strtotime($dates - 8)) {
// Here goes the part to actually make things work!
/* Yet another Quarantine section....
preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/", $subject, $ipaddy); // Client's first name in records (check WHMCS)
preg_match("/^(AOL|Hotmail|Yahoo|Comcast|Facebook|Google|Gmail)$/", $subject, $mailnet); // FBL Reporting Mailsys Network (Hotmail, Comcast, Yahoo!, Google, or AOL)
Hello, back to the news! */
$getArray["e"] = "/Tickets/Ticket";
$apiUrl = "SANITIZED" . $getArray["e"];
$apiKey = "SANITIZED";
$salt = mt_rand(1,99);
$secretKey = "SANITIZED";
$signature = base64_encode(hash_hmac('sha256',$salt,$secretKey,true));
$subject = "Abuse Email Ticket (TESTING - DO NOT RESPOND!)";
$fullname = "Ragnar Lothbrok";
$email = "burningjunk@mailinator.com";
$contents = "Hello anonymous Acenet user,\n\nWe have recently received an FBL (Feedback Loop) Report from an email provider indicating users have identified one or more messages originating from your account as spam. \n\nAcenet is setup to receive a notification any time email sent from our network arrives in the mailbox of another user at this provider and that email provider's user clicks \"This is Spam\" for that email. This is known as a Feedback Loop, we receive Feedback from external mail providers categorizing email which is sent from our network.\n\nThere are many reasons other users may be categorizing mail from your account as spam. The purpose of this notification is not to imply you are a spammer, but to factually inform you that a user has clicked \"This is Spam\" for email sent from your account. \n\nAlong with the FBL, we receive details about the email itself including the Sender, Subject, and Header information. Please note that the exact recipient of the email is often removed by the mail provider as part of their privacy policy. You will often see <redacted> in place of the true recipient's email address.\n\nThe relevant information related to this FBL Report is included below. \n\nIt's important to understand that we are not implying you are a spammer. But, it is our goal to assist you in determining why this report was generated for your emails. If these reports continue to generate, the aforementioned email provider may end up blacklisting your IP and prevent you from emailing those users. By working with our Technicians to address these FBL reports, we can help you to avoid such a situation.\n\nIf the email details provided below are unfamiliar to you, please update this ticket and our Technicians will be happy to review the contents and help interpret how this email may have originated from your account.\n\n\nIf you recognize the email details provided, you should review your mailing practices and attempt to identify why recipients are clicking \"This is Spam\" for these emails.\nFBL Reporting Information follows:\n-------------------------------------------------------------------------------------\n$body\n\n\n";
$departmentid = "9";
$ticketstatusid = "4";
$ticketpriorityid = "9";
$tickettypeid = "1";
$staffid = "27";
$post_data = array('subject' => $subject,
'fullname' => $fullname,
'email' => $email,
'contents' => $contents,
'departmentid' => $departmentid,
'ticketstatusid' => $ticketstatusid,
'ticketpriorityid' => $ticketpriorityid,
'tickettypeid' => $tickettypeid,
'staffid' => $staffid,
'apikey' => $apiKey,
'salt' => $salt,
'signature' => $signature);
$post_data = http_build_query($post_data, '', '&');
$curl = curl_init($apiUrl);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_URL, $apiUrl);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
$response = curl_exec($curl);
curl_close($curl);
}// end for loop
//close the email box and delete all messages marked for deletion
quit($fp);
//close the application
echo "<br>Finished</b>";
exit;
}
/* Have a nice day! */
?>
无论如何,我的问题是我只需要阅读前 7 天(换句话说:一周)的滥用电子邮件,并将它们作为我们公司 Kayako 安装中的支持票提交。我对 Kayako API 很感兴趣;对我来说,问题是我如何只阅读上周的滥用通知,而不是整个电子邮件帐户中的所有通知(最近两次我运行了这个脚本,它像 Energizer Bunny 和我一样不停地走来走去必须在脚本及其进程所在的服务器上运行kill -9 [process ID]命令)。
顺便说一句,对于这个脚本提到的“email-functions.php”脚本:忽略它。这是其他人写的,不是我写的,所以我不能保证它的错误。
我只能承认我自己编码中的错误......
如果有人知道如何解决我的问题,请留下回复或评论,谢谢!