Advertisement
Guest User

parser

a guest
Jan 26th, 2018
544
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.46 KB | None | 0 0
  1. $imapPath = '{imap.yandex.ru:993/imap/ssl}INBOX';
  2. $username = 'mapi@vteleport.ru';
  3. $password = 'C1B684q0';
  4.  
  5.  
  6. // try to connect
  7. $inbox = imap_open($imapPath, $username, $password) or die('Cannot connect to mail server: ' . imap_last_error());
  8. // Ищем только непрочитанные с темой Telezaim
  9. $emails = imap_search($inbox, 'UNSEEN SUBJECT "Telezaim"');
  10. if ($emails) { // если есть подходящие email, проводим с ними работу
  11.     $unread_emails = jn(',', $emails);
  12.     $status = imap_setflag_full($inbox, $unread_emails, "\\Seen");// Помечаю сообщения как проичтанные
  13.     $output = [];
  14.     foreach ($emails as $mail) {
  15.         $headerInfo = imap_headerinfo($inbox, $mail);
  16.         $personal = 'NO NAME';
  17.         $email = 'NO EMAIL';
  18.         if (isset($headerInfo->from[0]->personal)) {
  19.             $personal = iconv_mime_decode($headerInfo->from[0]->personal);
  20.         }
  21.         if (isset($headerInfo->from[0]->mailbox) && isset($headerInfo->from[0]->host)) {
  22.             $email = $headerInfo->from[0]->mailbox . '@' . $headerInfo->from[0]->host;
  23.         }
  24.        
  25.         $output[] = array($personal, $email);
  26.     }
  27.     if ($output) { // если есть результаты для записи в файл, переходим к дописыванию
  28.         $fp = fopen(root . '.log/.telezaim.app-' . date('Ymd') . '.csv', 'a');
  29.         foreach ($output as $fields) {
  30.             fputcsv($fp, $fields, ';');
  31.         }
  32.         fclose($fp);
  33.     }
  34. }
  35.  
  36. //colse the connection
  37. imap_close($inbox);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement