Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include("style/setup.inc");
- $imap = imap_open("{imap.gmail.com:993/imap/ssl}Inbox", "todoquick@gmail.com", "todoquick1");
- $message_count = imap_num_msg($imap);
- for ($i = 1; $i <= $message_count; ++$i) {
- $header = imap_headerinfo($imap, $i);
- $dateset = false;
- $tocount = count($header->to);
- if ($tocount > 0) {
- for ($j = 1; $j <= ($tocount-1); $j++) {
- if ($dateset == false) {
- $name = $header->to[$j]->mailbox;
- $date = strtotime($name);
- if ($date != false) {
- $dateset = true;
- } else {
- $intervalstring = "P".strtoupper($name);
- $interval = new DateInterval($intervalstring);
- $date = new DateTime(time());
- $date = $date->add($interval);
- if ($date != false) {
- $dateset = true;
- $activatedaddress = "{$header->from[$j]->mailbox}@{$header->from[$j]->host}";
- }
- }
- }
- }
- }
- $cccount = count($header->cc);
- if ($cccount > 0) {
- for ($j = 1; $j <= ($cccount-1); $j++) {
- if ($dateset == false) {
- $name = $header->cc[$j]->mailbox;
- $date = strtotime($name);
- if ($date != false) {
- $dateset = true;
- } else {
- $intervalstring = "P".strtoupper($name);
- $interval = new DateInterval($intervalstring);
- $date = new DateTime(time());
- $date = $date->add($interval);
- if ($date != false) {
- $dateset = true;
- $activatedaddress = "{$header->cc[$j]->mailbox}@{$header->cc[$j]->host}";
- }
- }
- }
- }
- }
- $bcccount = count($header->bcc);
- if ($bcccount > 0) {
- for ($j = 1; $j <= ($bcccount-1); $j++) {
- if ($dateset == false) {
- $name = $header->bcc[$j]->mailbox;
- $date = strtotime($name);
- if ($date != false) {
- $dateset = true;
- } else {
- $intervalstring = "P".strtoupper($name);
- $interval = new DateInterval($intervalstring);
- $date = new DateTime(time());
- $date = $date->add($interval);
- if ($date != false) {
- $dateset = true;
- $activatedaddress = "{$header->bcc[$j]->mailbox}@{$header->bcc[$j]->host}";
- }
- }
- }
- }
- }
- if (!$dateset) {
- $msg = <<<MSG
- Dear $from,
- A message was received by ToDoQuick from this address, sent to
- $activatedaddress
- The ToDoQuick System has handled this message as a ToDo, but was unable to process it.
- Please check the syntax of the address - this should be in the format described in the help section.
- Should you have wished to contact ToDoQuick, Please check the email you addressed your message to.
- A list of emails can be found in the contact section.
- Thankyou for using ToDoQuick.
- MSG;
- mail($from, "ToDoQuick Email Error", $msg);
- mail("supersam.littley@gmail.com", "ToDoQuick Email Error", $msg);
- imap_delete($imap, $i);
- continue;
- }
- $from = "{$header->from[0]->mailbox}@{$header->from[0]->host}";
- $date = date("Y-m-d", $date);
- $subject = $header->subject;
- $body = trim(imap_fetchbody($imap, $i, 1));
- $qry = sprintf("SELECT * FROM `todo`.`users` WHERE email='%s'", mysql_real_escape_string($from));
- $result = mysql_query($qry, $cxn);
- if (!$result) {
- echo("Error sending mysql request to retrieve userdata for email $from");
- continue;
- }
- elseif (mysql_num_rows($result) > 1) {
- echo("Error with user table - too many rows received for email $from");
- continue;
- }
- elseif (mysql_num_rows($result) == 0) {
- $msg = <<<MSG
- Dear $from,\n
- \n
- A message was received by ToDoQuick from this address, sent to\n\n
- $activatedaddress
- \n
- The ToDoQuick System has handled this message as a ToDo, but was\n
- unable to find your email address and account in the database.\n
- Please check your account settings, and/or sign up for the service\n
- before sending emails
- \n
- Should you have wished to contact ToDoQuick, please check the email\n
- you addressed your message to, as there are a finite list of\n
- manned mailboxes. A list of emails can be found in the contact\n
- section.
- \n
- Thankyou from ToDoQuick.
- MSG;
- mail($from, "ToDoQuick Email Error", $msg);
- mail("supersam.littley@gmail.com", "ToDoQuick Email Error", $msg);
- continue;
- }
- $row = mysql_fetch_array($result);
- $qry2 = sprintf("INSERT INTO `todo`.`%s` (`name`,`description`,`startdate`) VALUES (`%s`,`%s`,`%s`)", $row['username'], $subject, $body, $date);
- $result2 = mysql_query($qry2, $cxn);
- if (!$result2) {
- echo("Error sending mysql request to add todo for email $from");
- continue;
- }
- $replymsg = "ToDo added for $date with the following as a description\n\n".$body;
- mail($from, $subject, $replymsg);
- imap_delete($imap,$i);
- }
- imap_expunge($imap);
- imap_close($imap);
- ?>
- Error Messages :-
- Notice: Undefined property: stdClass::$cc in /home/samuel/public_html/todo/mail.php on line 29 Notice: Undefined variable: from in /home/samuel/public_html/todo/mail.php on line 76 Notice: Undefined variable: activatedaddress in /home/samuel/public_html/todo/mail.php on line 84 Notice: Undefined variable: from in /home/samuel/public_html/todo/mail.php on line 86 Notice: Undefined property: stdClass::$bcc in /home/samuel/public_html/todo/mail.php on line 50 Notice: Undefined variable: from in /home/samuel/public_html/todo/mail.php on line 76 Notice: Undefined variable: activatedaddress in /home/samuel/public_html/todo/mail.php on line 84 Notice: Undefined variable: from in /home/samuel/public_html/todo/mail.php on line 86 Notice: Undefined property: stdClass::$bcc in /home/samuel/public_html/todo/mail.php on line 50 Notice: Undefined variable: from in /home/samuel/public_html/todo/mail.php on line 76 Notice: Undefined variable: activatedaddress in /home/samuel/public_html/todo/mail.php on line 84 Notice: Undefined variable: from in /home/samuel/public_html/todo/mail.php on line 86
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement