Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function decoderattachment($piecejointe, $coding) {
- switch ($coding) {
- case 1 :
- $piecejointe = imap_8bit ( $piecejointe );
- break;
- case 2 :
- $piecejointe = imap_binary ( $piecejointe );
- break;
- case 3 :
- case 5 :
- case 6 :
- case 7 :
- $piecejointe = imap_base64 ( $piecejointe );
- break;
- case 4 :
- $piecejointe = imap_qprint ( $piecejointe );
- break;
- }
- return $piecejointe;
- }
- <?php
- require ('fpdf.php');
- require_once ('function.php');
- $authhost = "{imap.gmail.com:993/imap/ssl/novalidate-cert}";
- $user = "ipamemail@gmail.com";
- $pass = "imapemail";
- if ($mbox = imap_open ($authhost, $user, $pass)) {
- $nombreMessage = imap_num_msg ($mbox);
- while ($nombreMessage > 0) {
- $structure = imap_fetchstructure($mbox, $nombreMessage);
- $headers = imap_headerinfo ($mbox, $nombreMessage);
- $datetime = $headers->date;
- $subject = $headers->subject;
- mb_internal_encoding ('UTF-8');
- $subject = mb_decode_mimeheader ($subject);
- $fichier = dirname (__FILE__)."/email/".$subject.".txt";
- if (isset ( $structure->parts )) {
- $attachment = array ();
- $text = array ();
- foreach ( $structure->parts as $part ) {
- if (isset ( $part->disposition) && $part->disposition == 'ATTACHMENT') {
- $attachment = $part;
- }else{
- $text = $part;
- }
- }
- if ($attachment) {
- $ext = $part->subtype;
- $coding = $part->encoding;
- $piecejointe = imap_fetchbody ( $mbox, $nombreMessage, 2 );
- echo decoderattachment($piecejointe, $coding);
- $dpiece = dirname ( __FILE__ ) . "/email/piecejointe/" . $subject . "." . $ext;
- $dp = fopen ( $dpiece, 'w=' );
- fwrite ( $dp, $piecejointe );
- fclose ( $dp );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement