Advertisement
Guest User

pycarna pro jerryho

a guest
May 3rd, 2016
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.04 KB | None | 0 0
  1. <?php
  2. include_once("init.php");
  3. $ld = mysql_query("SELECT max(idm) as idm FROM email limit 1");
  4. $lid = mysql_fetch_object($ld);
  5. $last_id = (int)$lid->idm;
  6. $mailbox = '***';
  7. $username = '***';
  8. $password = '***';
  9. $encryption = 'ssl'; // or ssl or ''
  10. // open connection
  11. $imap = new Imap($mailbox, $username, $password, $encryption);
  12. // stop on error
  13.  
  14. if($imap->isConnected()==false) die($imap->getError());
  15.  
  16.  
  17. $imap->selectFolder('INBOX');
  18.  
  19. $emails = $imap->getMessages();
  20. //new dbug($emails);
  21. foreach ($emails as $key => $x) {
  22.  
  23.  
  24. $mid = (int)$x["uid"]-1;
  25.  
  26.     //if ($mid>$last_id)
  27.     if (1==1)
  28.     {
  29.            
  30.             $titulek    = $x["subject"];
  31.                 $cdatum = $x["date"];
  32.                 $rd     = explode(",", $cdatum);
  33.                 $rdx    = $rd[1];
  34.  
  35.             $date       = date_create($rdx);
  36.             $datum      = date_format($date, 'd.m.Y');
  37.             $text       = $x["body"];
  38.             echo $dec   = mb_detect_encoding($text);
  39.             //echo iconv('UTF-8', 'ISO-8859-1//TRANSLIT', $text);
  40.             echo iconv('cp1250', "UTF-8//IGNORE", $text);
  41.             $text       = str_replace("'", "", $text);
  42.  
  43.             $text = strip_tags($text, '<br><a><b><i><u>');
  44.             //$text         = mysql_real_escape_string($text);
  45.             $autor      = $x["from"];
  46.             if (isset($x["attachments"]))
  47.             {
  48.                 $count_att  = count($x["attachments"]);
  49.                 if ($count_att>0)
  50.                 {
  51.                     include_once("news_att.php");
  52.                         for ($i=0;$i<$count_att;$i++)
  53.                             {      
  54.                                 $name =  $x["attachments"][$i]["name"];
  55.                                 $size =  $x["attachments"][$i]["size"];
  56.                                 mysql_query("INSERT INTO email_files (idm,nazev,velikost) VALUES($mid,'$name','$size')");
  57.                             }
  58.                 }
  59.             unset($x["attachments"]);
  60.             }
  61.             //use encoding;
  62.             //use encoding.php
  63.  
  64. //          $utf8_string = Encoding::toUTF8($text);
  65.             echo $text;
  66.             $save = "INSERT INTO email (idm,autor,predmet,text) VALUES($mid,'$autor','$titulek','$text')";
  67.             //$save = mysql_query("INSERT INTO email (idm,autor,predmet,text) VALUES($mid,'$autor','$titulek','$text')");
  68.             /*
  69.             $result = mysql_query($save);
  70.             if (!$result) {
  71.                 die('Invalid query: ' . mysql_error());
  72.             }
  73.             */
  74.  
  75.     }
  76.  
  77. echo "<hr>";
  78.  
  79. }
  80.  
  81. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement