示例#1
0
 /**
  * Parse Invitation Email from Picasa
  **/
 function getEmail()
 {
     // Require DB & Email Config
     require_once "../lib/picasa/receivemail.class.php";
     require_once "../lib/picasa/config.php";
     // Create an instance of ADO connection object
     $conn = new COM("ADODB.Connection") or die("Cannot start ADO");
     // Define connection string, specify database driver
     $connStr = "PROVIDER=SQLOLEDB;SERVER=" . $server . ";UID=" . $username . ";PWD=" . $passwd . ";DATABASE=" . $db;
     $conn->open($connStr);
     //Open the connection to the database
     // Create Object For reciveMail Class
     $obj = new receiveMail($uemail, $pemail, $email, $eserver, $etype, $eport);
     //Connect to the Mail Box
     $obj->connect();
     // Get Total Number of Unread Email in mail box
     $total = $obj->getTotalMails();
     //Total Mails in Inbox Return integer value
     $emailArray = array();
     for ($i = 1; $i <= $total; $i++) {
         $content = $obj->getBody($i);
         $lines = preg_split("/\r?\n|\r/", $content);
         // turn the content into rows
         $links_regex = '#<a[^/>]*' . 'href=["|\']([^javascript:].*)["|\']#Ui';
         //regular expression to extract url from html links
         $searchString = $lines[31];
         // check if line number 31 contains a link.
         $findString = "<a href";
         $pos = strpos($searchString, $findString);
         if ($pos === false) {
             preg_match_all($links_regex, $lines[35], $out, PREG_PATTERN_ORDER);
             //if line 31 did not contains link than use line 35 to process regex
         } else {
             preg_match_all($links_regex, $lines[31], $out, PREG_PATTERN_ORDER);
             //use line 31 to process regex
         }
         $emailItem = array();
         $vars = explode("?", $out[1][0]);
         $splitVars = explode("&", $vars[1]);
         for ($j = 0; $j < 4; $j++) {
             array_push($emailItem, $this->_getVal($splitVars[$j]));
         }
         array_push($emailArray, $emailItem);
         //declare the SQL statement that will query the database
         $query = "INSERT INTO tbl_picasa ( username, type, type_id, authkey ) \n\t\t\t\t\t\t\t\tVALUES ( '" . $this->_getVal($splitVars[0]) . "', '" . $this->_getVal($splitVars[1]) . "', '" . $this->_getVal($splitVars[2]) . "', '" . $this->_getVal($splitVars[3]) . "' )";
         //print_r($query);
         //execute the SQL statement and return records
         $rs = $conn->execute($query);
         $obj->deleteMails($i);
         // Delete Mail from Mail box
     }
     $obj->close_mailbox();
     //Close Mail Box
     if ($total > 0) {
         return $emailArray;
     } else {
         return $total;
     }
 }
示例#2
0
文件: users.php 项目: armpit/e107
 function check_bounces($bounce_act = 'first_check', $bounce_arr = '')
 {
     ### old Trigger code for bounce check
     // $bounce_act = '';
     // if (isset ($_POST['check_bounces']))
     // $bounce_act = 'first_check';
     // if (isset ($_POST['delnonbouncesubmit']))
     // $bounce_act = 'delnonbounce';
     // if (isset ($_POST['clearemailbouncesubmit']))
     // $bounce_act = 'clearemailbounce';
     // if (isset ($_POST['delcheckedsubmit']))
     // $bounce_act = 'delchecked';
     // if (isset ($_POST['delallsubmit']))
     // $bounce_act = 'delall';
     // if ($bounce_act)
     // {
     // $user->check_bounces($bounce_act,implode(',',$_POST['delete_email']));
     // require_once ("footer.php");
     // exit;
     // }
     global $sql, $pref;
     include e_HANDLER . 'pop3_class.php';
     if (!trim($bounce_act)) {
         $bounce_act = 'first_check';
     }
     //	  echo "Check bounces. Action: {$bounce_act}; Entries: {$bounce_arr}<br />";
     $obj = new receiveMail($pref['mail_bounce_user'], $pref['mail_bounce_pass'], $pref['mail_bounce_email'], $pref['mail_bounce_pop3'], varset($pref['mail_bounce_type'], 'pop3'));
     $del_count = 0;
     if ($bounce_act != 'first_check') {
         // Must do some deleting
         $obj->connect();
         $tot = $obj->getTotalMails();
         $del_array = explode(',', $bounce_arr);
         for ($i = 1; $i <= $tot; $i++) {
             // Scan all emails; delete current one if meets the criteria
             $dodel = false;
             switch ($bounce_act) {
                 case 'delnonbounce':
                     $head = $obj->getHeaders($i);
                     $dodel = !$head['bounce'];
                     break;
                 case 'clearemailbounce':
                     if (!in_array($i, $del_array)) {
                         break;
                     }
                     $head = $obj->getHeaders($i);
                     if ($head['bounce']) {
                         if (preg_match("/[\\._a-zA-Z0-9-]+@[\\._a-zA-Z0-9-]+/i", $obj->getBody($i), $result)) {
                             $usr_email = trim($result[0]);
                         }
                         if ($sql->db_Select('user', 'user_id, user_name, user_email', "user_email='" . $usr_email . "' ")) {
                             $row = $sql->fetch();
                             if ($sql->db_Update('user', "`user_email`='' WHERE `user_id` = '" . $row['user_id'] . "' ") !== false) {
                                 // echo "Deleting user email {$row['user_email']} for user {$row['user_name']}, id={$row['user_id']}<br />";
                                 $dodel = true;
                             }
                         }
                     }
                     break;
                 case 'delall':
                     $dodel = true;
                     break;
                 case 'delchecked':
                     $dodel = in_array($i, $del_array);
                     break;
             }
             if ($dodel) {
                 //			  echo "Delete email ID {$i}<br />";
                 $obj->deleteMails($i);
                 $del_count++;
                 // Keep track of number of emails deleted
             }
         }
         // End - Delete one email
         $obj->close_mailbox();
         // This actually deletes the emails
     }
     // End of email deletion
     // Now list the emails that are left
     $obj->connect();
     $tot = $obj->getTotalMails();
     $found = false;
     $DEL = $pref['mail_bounce_delete'] ? true : false;
     $text = "<br /><div><form  method='post' action='" . e_SELF . $qry . "'><table>\r\n\t\t<tr><td style='width:5%'>#</td><td>e107-id</td><td>email</td><td>Subject</td><td>Bounce</td></tr>\n";
     $identifier = deftrue('MAIL_IDENTIFIER', 'X-e107-id');
     for ($i = 1; $i <= $tot; $i++) {
         $head = $obj->getHeaders($i);
         if ($head['bounce']) {
             // Its a 'bounce' email
             if (preg_match('/.*' . $identifier . ':(.*)MIME/', $obj->getBody($i), $result)) {
                 if ($result[1]) {
                     $id[$i] = intval($result[1]);
                     // This should be a user ID - but not on special mailers!
                     //	Try and pull out an email address from body - should be the one that failed
                     if (preg_match("/[\\._a-zA-Z0-9-]+@[\\._a-zA-Z0-9-]+/i", $obj->getBody($i), $result)) {
                         $emails[$i] = "'" . $result[0] . "'";
                     }
                     $found = true;
                 }
             } elseif (preg_match("/[\\._a-zA-Z0-9-]+@[\\._a-zA-Z0-9-]+/i", $obj->getBody($i), $result)) {
                 if ($result[0] && $result[0] != $pref['mail_bounce_email']) {
                     $emails[$i] = "'" . $result[0] . "'";
                     $found = true;
                 } elseif ($result[1] && $result[1] != $pref['mail_bounce_email']) {
                     $emails[$i] = "'" . $result[1] . "'";
                     $found = true;
                 }
             }
             if ($DEL && $found) {
                 // Auto-delete bounced emails once noticed (if option set)
                 $obj->deleteMails($i);
                 $del_count++;
             }
         } else {
             // Its a warning message or similar
             //			  $id[$i] = '';			// Don't worry about an ID for now
             //				Try and pull out an email address from body - should be the one that failed
             if (preg_match("/[\\._a-zA-Z0-9-]+@[\\._a-zA-Z0-9-]+/i", $obj->getBody($i), $result)) {
                 $wmails[$i] = "'" . $result[0] . "'";
             }
         }
         $text .= "<tr><td>" . $i . "</td><td>" . $id[$i] . "</td><td>" . (isset($emails[$i]) ? $emails[$i] : $wmails[$i]) . "</td><td>" . $head['subject'] . "</td><td>" . ($head['bounce'] ? ADMIN_TRUE_ICON : ADMIN_FALSE_ICON);
         $text .= "<input type='checkbox' name='delete_email[]' value='{$i}' /></td></tr>\n";
     }
     if ($del_count) {
         e107::getLog()->add('USET_13', str_replace('--COUNT--', $del_count, USRLAN_169), E_LOG_INFORMATIVE);
     }
     if ($tot) {
         // Option to delete emails - only if there are some in the list
         $text .= "</table><table style='" . ADMIN_WIDTH . "'><tr>\r\n\t\t\t<td style='text-align: center;'><input class='btn btn-default button' type='submit' name='delnonbouncesubmit' value='" . USRLAN_183 . "' /></td>\n\r\n\t\t\t<td style='text-align: center;'><input class='btn btn-default button' type='submit' name='clearemailbouncesubmit' value='" . USRLAN_184 . "' /></td>\n\r\n\t\t\t<td style='text-align: center;'><input class='btn btn-default button' type='submit' name='delcheckedsubmit' value='" . USRLAN_179 . "' /></td>\n\r\n\t\t\t<td style='text-align: center;'><input class='btn btn-default button' type='submit' name='delallsubmit' value='" . USRLAN_180 . "' /></td>\n\r\n\t\t\t</td></tr>";
     }
     $text .= "</table></form></div>";
     array_unique($id);
     array_unique($emails);
     $all_ids = implode(',', $id);
     $all_emails = implode(',', $emails);
     $obj->close_mailbox();
     // This will actually delete emails
     // $tot has total number of emails in the mailbox
     $found = count($emails);
     // $found - Number of bounce emails found
     // $del_count has number of emails deleted
     // Update bounce status for users
     $ed = $sql->db_Update('user', "user_ban=3 WHERE (`user_id` IN (" . $all_ids . ") OR `user_email` IN (" . $all_emails . ")) AND user_sess !='' ");
     if (!$ed) {
         $ed = '0';
     }
     $this->show_message(str_replace(array('{TOTAL}', '{DELCOUNT}', '{DELUSER}', '{FOUND}'), array($tot, $del_count, $ed, $found), USRLAN_155) . $text);
 }