????JFIF??x?x????'
Server IP : 79.136.114.73 / Your IP : 3.22.79.2 Web Server : Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.29 OpenSSL/1.0.1f System : Linux b8009 3.13.0-170-generic #220-Ubuntu SMP Thu May 9 12:40:49 UTC 2019 x86_64 User : www-data ( 33) PHP Version : 5.5.9-1ubuntu4.29 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/appsrv.astacus.se/gmail/ |
Upload File : |
<?php /** * Gmail attachment extractor. * * Downloads attachments from Gmail and saves it to a file. * Uses PHP IMAP extension, so make sure it is enabled in your php.ini, * extension=php_imap.dll * */ set_time_limit(3000); /* connect to gmail with your credentials */ $hostname = '{imap.gmail.com:993/imap/ssl}INBOX'; $username = 'reclaim@astacus.se'; # e.g somebody@gmail.com $password = 'astacus2015'; /* try to connect */ $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error()); /* get all new emails. If set to 'ALL' instead * of 'NEW' retrieves all the emails, but can be * resource intensive, so the following variable, * $max_emails, puts the limit on the number of emails downloaded. * */ $emails = imap_search($inbox,'ALL'); /* useful only if the above search is set to 'ALL' */ $max_emails = 16; /* if any emails found, iterate through each email */ if($emails) { $count = 1; /* put the newest emails on top */ rsort($emails); /* for every email... */ foreach($emails as $email_number) { /* get information specific to this email */ $overview = imap_fetch_overview($inbox,$email_number,0); //print_r( $overview ); /* get mail message */ $message = imap_fetchbody($inbox,$email_number,2); /* get mail structure */ $structure = imap_fetchstructure($inbox, $email_number); $attachments = array(); /* if any attachments found... */ if(isset($structure->parts) && count($structure->parts)) { echo(count($structure->parts)); for($i = 0; $i < count($structure->parts); $i++) { $attachments[$i] = array( 'is_attachment' => false, 'filename' => '', 'name' => '', 'attachment' => '' ); //print_r($structure->parts[$i]); if($structure->parts[$i]->ifdparameters) { foreach($structure->parts[$i]->dparameters as $object) { if(strtolower($object->attribute) == 'FILENAME') { $attachments[$i]['is_attachment'] = true; $attachments[$i]['filename'] = $object->value; } } } print_r($structure->parts[$i]->parameters); if($structure->parts[$i]->ifparameters) { foreach($structure->parts[$i]->dparameters as $object) { // if(strtolower($object->attribute) == 'name') // { $attachments[$i]['is_attachment'] = true; $attachments[$i]['name'] = $object->value; // } } } if($attachments[$i]['is_attachment']) { $attachments[$i]['attachment'] = imap_fetchbody($inbox, $email_number, $i+1); /* 4 = QUOTED-PRINTABLE encoding */ if($structure->parts[$i]->encoding == 3) { $attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']); } /* 3 = BASE64 encoding */ elseif($structure->parts[$i]->encoding == 4) { $attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']); } } } } /* iterate through each attachment and save it */ foreach($attachments as $attachment) { if($attachment['is_attachment'] == 1) { $filename = $attachment['name']; if(empty($filename)) $filename = $attachment['filename']; if(empty($filename)) $filename = time() . ".dat"; /* prefix the email number to the filename in case two emails * have the attachment with the same file name. */ $fp = fopen("/var/www/appsrv.astacus.se/gmail/". $email_number . "-" . $filename, "w+"); fwrite($fp, $attachment['attachment']); fclose($fp); echo "/var/www/appsrv.astacus.se/gmail/".$email_number . "-" . $filename, "w+"; } } if($count++ >= $max_emails) break; } } /* close the connection */ imap_close($inbox); echo "Done"; ?>