rendered paste body<pre><?phpfunction getdecodevalue($message,$coding) { if ($coding == 0) { $message = imap_8bit($message); } elseif ($coding == 1) { $message = imap_8bit($message); } elseif ($coding == 2) { $message = imap_binary($message); } elseif ($coding == 3) { $message=imap_base64($message); } elseif ($coding == 4) { $message = imap_qprint($message); } elseif ($coding == 5) { $message = imap_base64($message); } return $message;}$mbox = imap_open("{imap.gmi.co.nz:143}", "gmi", "gmi");$folders = imap_listmailbox($mbox, "{imap.gmi.co.nz:143}", "*");for ($i=1;$i<=imap_num_msg($mbox);$i++) { $headers = imap_headerinfo($mbox,$i); $email_from = $headers->from; $email_sender = $headers->from[0]->mailbox.'@'.$headers->from[0]->host; $email_unixdate = $headers->udate; $allowed_hosts = array( 'legendmemory.com', 'dove.co.nz', 'cdlnz.com', 'ingrammicro.co.nz', 'itatwork.co.nz', 'overclockers.co.nz' ); // print_r($email_from); if (in_array($email_from[0]->host, $allowed_hosts)) { $structure = imap_fetchstructure($mbox,$i); $parts = $structure->parts; if ($headers->Deleted == 'D') { echo "Email from $email_sender has been marked for deletion\n"; } else { //print_r($headers); //print_r($structure); $fpos = 2; for($j=1;$j<count($parts);$j++) { $part = $parts[$j]; $file_name = $email_unixdate.'-'.$fpos.'-'.$part->dparameters[0]->value; $attachment = imap_fetchbody($mbox,$i,$fpos); $fp = fopen("./dump/$file_name",'w') or die("Couldn\'t open file to write to: $file_name"); $data = getdecodevalue($attachment,$part->type); if (fwrite($fp,$data) === FALSE) {die("Couldn\'t write to file: $file_name");} fclose($fp); echo "Email from $email_sender, sent on ".date("F j, Y, g:i a", $email_unixdate) ."Wrote $file_name.\n"; $fpos++; } } } else { echo "Email from $email_sender is not in allowed hosts\n"; }}imap_close($mbox);?></pre>