subtype =='ALTERNATIVE') { $message = imap_fetchbody($inbox,$email_number,2); } else { $message = imap_fetchbody($inbox,$email_number,1); } //$message = imap_base64($message); if($structure->encoding =='3') { $message = imap_base64($message); } $attachments = array(); /* if any attachments found... */ if(isset($structure->parts) && count($structure->parts)) { for($i = 0; $i < count($structure->parts); $i++) { if($structure->parts[$i]->encoding == 0) { $message = $message; } else if($structure->parts[$i]->encoding == 2) { $message = imap_binary($message); } else if($structure->parts[$i]->encoding == 3 && $structure->parts[$i]->subtype !='PLAIN' && $structure->parts[$i]->subtype !='JPEG' && $structure->parts[$i]->subtype !='PNG' && $structure->parts[$i]->subtype !='VND.OPENXMLFORMATS-OFFICEDOCUMENT.WORDPROCESSINGML.DOCUMENT') { $message = imap_base64($message); } else if($structure->parts[$i]->encoding == 1) { $message = quoted_printable_decode(imap_8bit($message)); } else if($structure->parts[$i]->encoding == 4 && $structure->parts[$i]->subtype !='HTML') { $message = quoted_printable_decode($message); } else if($structure->parts[$i]->encoding == 5) { $message = imap_base64($message); } else { $message = imap_qprint($message); } $attachments[$i] = array( 'is_attachment' => false, 'filename' => '', 'name' => '', 'attachment' => '' ); 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; } } } /*11 */ if($structure->parts[$i]->ifparameters) { foreach($structure->parts[$i]->parameters as $object) { if(strtolower($object->attribute) == 'name') { $attachments[$i]['is_attachment'] = true; $attachments[$i]['name'] = $object->value; } } } /*11 */ if($attachments[$i]['is_attachment']) { $attachments[$i]['attachment'] = imap_fetchbody($inbox, $email_number, "$i+1"); if($structure->parts[$i]->encoding == 3) { $attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']); } elseif($structure->parts[$i]->encoding == 4) { $attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']); } } } } /* save */ foreach($attachments as $attachment) { if($attachment['is_attachment'] == 1) { $filename = $attachment['name']; if(empty($filename)) $filename = $attachment['filename']; if(empty($filename)) $filename = time() . ".dat"; $fp = fopen("./" . $email_number . "-" . $filename, "w+"); fwrite($fp, $attachment['attachment']); fclose($fp); } } if($count++ >= $max_emails) break; $output.= '
'; $output.= 'From: '.utf8_decode(imap_utf8($overview[0]->from)).''; $output.= 'on '.utf8_decode(imap_utf8($overview[0]->date)).''; $output.= '
Subject('.$part->encoding.'): '.utf8_decode(imap_utf8($overview[0]->subject)).' '; $output.= '
'; $output.= '
'.$message.'

'; $msg = str_replace("&nbs;", "", $message); $msg = str_replace(" ", " ", $msg); $msg = str_replace("<", "", $msg); $msg = str_replace("&", "", $msg); $msg = str_replace ("'", "", $msg); $msg=utf8_encode(html_entity_decode($msg)); include_once('quickbase.php'); $qbUser = 'Hashmi.jose@marlabs.com'; $qbPassword = 'Hash123|'; $qbAppToken = 'yfiz9xdejcdr4dwp4gwud5cu9vj '; $db = 'bmhztciea'; $realm = 'ctc'; $qb = new QuickBase($qbUser, $qbPassword, true, $db, $qbAppToken,$realm, 2);//creating the object $fields = array( array( 'fid' => 7, 'value' => utf8_decode(imap_utf8($overview[0]->from)) ), array( 'fid' => 6, 'value' => utf8_decode(imap_utf8($overview[0]->to)) ), array( 'fid' => 14, 'value' => utf8_decode(imap_utf8($header->ccaddress)) ), array( 'fid' => 17, 'value' => utf8_decode(imap_utf8($header->to[0]->mailbox)) ), array( 'fid' => 10, 'value' => utf8_decode(imap_utf8($overview[0]->date)) ), array( 'fid' => 8, 'value' => utf8_decode(imap_utf8($overview[0]->subject)) ), array( 'fid' => 9, 'value' => trim(strip_tags($msg,'


')) ) ); $response = $qb->add_record($fields); echo $rid = $response->rid; //echo "gggggggggg". $d=strip_tags($msg); //echo "ooooooooooooooooooooooooooooooooooooooooooooooooooooooo"; //echo html_entity_decode($d, ENT_QUOTES | ENT_XML1, 'UTF-8'); //$htmlcode = htmlentities(htmlspecialchars($d)); // $htmlcode; //echo html_entity_decode(htmlspecialchars_decode($htmlcode)); } echo $output; } } /* close the connection */ imap_close($inbox); echo('

You have '.$nMsgCount.' unread messages.

'); echo "Done"; ?>