Advertisement
Guest User

Untitled

a guest
Dec 29th, 2016
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.86 KB | None | 0 0
  1. <?php
  2.  
  3. include 'class.pdf2txt.php';
  4. include 'vendor/autoload.php';
  5.  
  6. set_time_limit(3000);
  7.  
  8. /* connect to gmail with your credentials */
  9. $hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
  10. $username = 'dominos1646nr@gmail.com';
  11. $password = 'ta992555';
  12.  
  13. /* try to connect */
  14. $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
  15.  
  16. $emails = imap_search($inbox, 'FROM "1646@dominos.com"');
  17.  
  18. /* if any emails found, iterate through each email */
  19. if($emails) {
  20.  
  21. $count = 1;
  22.  
  23. /* put the newest emails on top */
  24. rsort($emails);
  25.  
  26.  
  27. $email_number = $emails[0];
  28.  
  29. /* get information specific to this email */
  30. $overview = imap_fetch_overview($inbox,$email_number,0);
  31.  
  32. $message = imap_fetchbody($inbox,$email_number,2);
  33.  
  34. /* get mail structure */
  35. $structure = imap_fetchstructure($inbox, $email_number);
  36.  
  37. $attachments = array();
  38.  
  39. /* if any attachments found... */
  40. if(isset($structure->parts) && count($structure->parts))
  41. {
  42. for($i = 0; $i < count($structure->parts); $i++)
  43. {
  44. $attachments[$i] = array(
  45. 'is_attachment' => false,
  46. 'filename' => '',
  47. 'name' => '',
  48. 'attachment' => ''
  49. );
  50.  
  51. if($structure->parts[$i]->ifdparameters)
  52. {
  53. foreach($structure->parts[$i]->dparameters as $object)
  54. {
  55. if(strtolower($object->attribute) == 'filename')
  56. {
  57. $attachments[$i]['is_attachment'] = true;
  58. $attachments[$i]['filename'] = $object->value;
  59. }
  60. }
  61. }
  62.  
  63. if($structure->parts[$i]->ifparameters)
  64. {
  65. foreach($structure->parts[$i]->parameters as $object)
  66. {
  67. if(strtolower($object->attribute) == 'name')
  68. {
  69. $attachments[$i]['is_attachment'] = true;
  70. $attachments[$i]['name'] = $object->value;
  71. }
  72. }
  73. }
  74.  
  75. if($attachments[$i]['is_attachment'])
  76. {
  77. $attachments[$i]['attachment'] = imap_fetchbody($inbox, $email_number, $i+1);
  78.  
  79. /* 3 = BASE64 encoding */
  80. if($structure->parts[$i]->encoding == 3)
  81. {
  82. $attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']);
  83. }
  84. /* 4 = QUOTED-PRINTABLE encoding */
  85. elseif($structure->parts[$i]->encoding == 4)
  86. {
  87. $attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']);
  88. }
  89. }
  90. }
  91.  
  92.  
  93. /* iterate through each attachment and save it */
  94. foreach($attachments as $attachment)
  95. {
  96. if($attachment['is_attachment'] == 1)
  97. {
  98. $filename = $attachment['name'];
  99. if(empty($filename)) $filename = $attachment['filename'];
  100.  
  101. if(empty($filename)) $filename = time() . ".dat";
  102. $folder = "attachment";
  103. if(!is_dir($folder))
  104. {
  105. mkdir($folder);
  106. }
  107. $php = "./". $folder ."/". $email_number . "-" . $filename;
  108. $fp = fopen("./". $folder ."/". $email_number . "-" . $filename, "w+");
  109. fwrite($fp, $attachment['attachment']);
  110. fclose($fp);
  111.  
  112. #$a = new PDF2Text();
  113. #$a->setFilename($php);
  114. #$a->decodePDF();
  115. #echo $a->output();
  116.  
  117. echo 'ay';
  118. try {
  119. $pdf = new \TonchikTm\PdfToHtml\Pdf($php, [
  120. 'pdftohtml_path' => '/site/wwwroot/poppler-0.50/bin/pdftohtml.exe',
  121. 'pdfinfo_path' => '/site/wwwroot/poppler-0.50/bin/pdfinfo.exe'
  122. ]);
  123. // get pdf info
  124. $pdfInfo = $pdf->getInfo();
  125. echo $pdf;
  126. // get count pages
  127. $countPages = $pdf->countPages();
  128.  
  129. // get content from one page
  130. $contentFirstPage = $pdf->getHtml()->getPage(1);
  131.  
  132. // get content from all pages and loop for they
  133. foreach ($pdf->getHtml()->getAllPages() as $page) {
  134. echo $page . '<br/>';
  135. }
  136. } catch (Exception $e) {
  137. echo $e->getMessage();
  138. }
  139. }
  140. }
  141. }
  142. }
  143.  
  144. /* close the connection */
  145. imap_close($inbox);
  146.  
  147. echo "all attachment Downloaded";
  148.  
  149. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement