Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
603
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.84 KB | None | 0 0
  1. <?php
  2.         include("style/setup.inc");
  3.     $imap = imap_open("{imap.gmail.com:993/imap/ssl}Inbox", "todoquick@gmail.com", "todoquick1");
  4.     $message_count = imap_num_msg($imap);
  5.     for ($i = 1; $i <= $message_count; ++$i) {
  6.       $header = imap_headerinfo($imap, $i);
  7.             $dateset = false;
  8.             $tocount = count($header->to);
  9.             if ($tocount > 0) {
  10.                 for ($j = 1; $j <= ($tocount-1); $j++) {
  11.                     if ($dateset == false) {
  12.                         $name = $header->to[$j]->mailbox;
  13.                         $date = strtotime($name);
  14.                         if ($date != false) {
  15.                             $dateset = true;
  16.                         } else {
  17.                             $intervalstring = "P".strtoupper($name);
  18.                             $interval = new DateInterval($intervalstring);
  19.                             $date = new DateTime(time());
  20.                             $date = $date->add($interval);
  21.                             if ($date != false) {
  22.                                 $dateset = true;
  23.                                 $activatedaddress = "{$header->from[$j]->mailbox}@{$header->from[$j]->host}";
  24.                             }
  25.                         }
  26.                     }
  27.                 }
  28.             }
  29.             $cccount = count($header->cc);
  30.             if ($cccount > 0) {
  31.                 for ($j = 1; $j <= ($cccount-1); $j++) {
  32.                     if ($dateset == false) {
  33.                         $name = $header->cc[$j]->mailbox;
  34.                         $date = strtotime($name);
  35.                         if ($date != false) {
  36.                             $dateset = true;
  37.                         } else {
  38.                             $intervalstring = "P".strtoupper($name);
  39.                             $interval = new DateInterval($intervalstring);
  40.                             $date = new DateTime(time());
  41.                             $date = $date->add($interval);
  42.                             if ($date != false) {
  43.                                 $dateset = true;
  44.                                 $activatedaddress = "{$header->cc[$j]->mailbox}@{$header->cc[$j]->host}";
  45.                             }
  46.                         }
  47.                     }
  48.                 }
  49.             }
  50.             $bcccount = count($header->bcc);
  51.             if ($bcccount > 0) {
  52.                 for ($j = 1; $j <= ($bcccount-1); $j++) {
  53.                     if ($dateset == false) {
  54.                         $name = $header->bcc[$j]->mailbox;
  55.                         $date = strtotime($name);
  56.                         if ($date != false) {
  57.                             $dateset = true;
  58.                         } else {
  59.                             $intervalstring = "P".strtoupper($name);
  60.                             $interval = new DateInterval($intervalstring);
  61.                             $date = new DateTime(time());
  62.                             $date = $date->add($interval);
  63.                             if ($date != false) {
  64.                                 $dateset = true;
  65.                                 $activatedaddress = "{$header->bcc[$j]->mailbox}@{$header->bcc[$j]->host}";
  66.                             }
  67.                         }
  68.                     }
  69.                 }
  70.             }
  71.             if (!$dateset) {
  72.                 $msg = <<<MSG
  73. Dear $from,
  74.  
  75. A message was received by ToDoQuick from this address, sent to
  76. $activatedaddress
  77.  
  78. The ToDoQuick System has handled this message as a ToDo, but was unable to process it.
  79. Please check the syntax of the address - this should be in the format described in the help section.
  80.  
  81. Should you have wished to contact ToDoQuick, Please check the email you addressed your message to.
  82. A list of emails can be found in the contact section.
  83.  
  84. Thankyou for using ToDoQuick.
  85. MSG;
  86.                 mail($from, "ToDoQuick Email Error", $msg);
  87.                 mail("supersam.littley@gmail.com", "ToDoQuick Email Error", $msg);
  88.                 imap_delete($imap, $i);
  89.                 continue;
  90.             }
  91.             $from = "{$header->from[0]->mailbox}@{$header->from[0]->host}";
  92.             $date = date("Y-m-d", $date);
  93.             $subject = $header->subject;
  94.       $body = trim(imap_fetchbody($imap, $i, 1));
  95.             $qry = sprintf("SELECT * FROM `todo`.`users` WHERE email='%s'", mysql_real_escape_string($from));
  96.             $result = mysql_query($qry, $cxn);
  97.             if (!$result) {
  98.                 echo("Error sending mysql request to retrieve userdata for email $from");
  99.                 continue;
  100.             }
  101.             elseif (mysql_num_rows($result) > 1) {
  102.                 echo("Error with user table - too many rows received for email $from");
  103.                 continue;
  104.             }
  105.             elseif (mysql_num_rows($result) == 0) {
  106.                 $msg = <<<MSG
  107. Dear $from,\n
  108. \n
  109. A message was received by ToDoQuick from this address, sent to\n\n
  110. $activatedaddress
  111. \n
  112. The ToDoQuick System has handled this message as a ToDo, but was\n
  113. unable to find your email address and account in the database.\n
  114. Please check your account settings, and/or sign up for the service\n
  115. before sending emails
  116. \n
  117. Should you have wished to contact ToDoQuick, please check the email\n
  118. you addressed your message to, as there are a finite list of\n
  119. manned mailboxes. A list of emails can be found in the contact\n
  120. section.
  121. \n
  122. Thankyou from ToDoQuick.
  123.  
  124. MSG;
  125.                 mail($from, "ToDoQuick Email Error", $msg);
  126.                 mail("supersam.littley@gmail.com", "ToDoQuick Email Error", $msg);
  127.                 continue;
  128.             }
  129.             $row = mysql_fetch_array($result);
  130.             $qry2 = sprintf("INSERT INTO `todo`.`%s` (`name`,`description`,`startdate`) VALUES (`%s`,`%s`,`%s`)", $row['username'], $subject, $body, $date);
  131.             $result2 = mysql_query($qry2, $cxn);
  132.             if (!$result2) {
  133.                 echo("Error sending mysql request to add todo for email $from");
  134.                 continue;
  135.             }
  136.             $replymsg = "ToDo added for $date with the following as a description\n\n".$body;
  137.             mail($from, $subject, $replymsg);
  138.             imap_delete($imap,$i);
  139.     }
  140.         imap_expunge($imap);
  141.     imap_close($imap);
  142. ?>
  143.  
  144. Error Messages :-
  145. 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