phpsycho Posted July 28, 2011 Share Posted July 28, 2011 I found these functions online and I edited them A LOT lol very buggy.. but now I'm stuck on one of these bugs. Here is the code: function aff_mail($servr, $user, $passwd, $folder, $mail, $verbose) { $mailhost = $servr; GLOBAL $attach_tab; GLOBAL $PHP_SELF; $glob_body = ''; $subject = $from = $to = $cc = ''; $pop = @imap_open('{' . $mailhost . '}' . $folder, $user, $passwd); $num_messages = @imap_num_msg($pop); $ref_contenu_message = @imap_header($pop, $mail); $struct_msg = @imap_fetchstructure($pop, $mail); if (sizeof($struct_msg->parts) > 0) GetPart($struct_msg, NULL, false); else GetSinglePart($struct_msg, htmlspecialchars(imap_fetchheader($pop, $mail)), @imap_body($pop, $mail)); if ($verbose == 1 && $use_verbose == 1) $header = htmlspecialchars(imap_fetchheader($pop, $mail)); else $header = ''; $tmp = array_pop($attach_tab); if (eregi('text/html', $tmp['mime']) || eregi('text/plain', $tmp['mime'])) { if ($tmp['transfer'] == 'QUOTED-PRINTABLE') $glob_body = imap_qprint(imap_fetchbody($pop, $mail, $tmp['number'])); elseif ($tmp['transfer'] == 'BASE64') $glob_body = base64_decode(imap_fetchbody($pop, $mail, $tmp['number'])); else $glob_body = imap_fetchbody($pop, $mail, $tmp['number']); $glob_body = remove_stuff($glob_body, $tmp['mime']); } else array_push($attach_tab, $tmp); @imap_close($pop); if (strtolower($struct_msg->subtype) != "alternative" && strtolower($struct_msg->subtype) != "related") { switch (sizeof($attach_tab)) { case 0: $link_att = ''; break; case 1: $link_att = link_att($mailhost, $mail, $attach_tab, $display_part_no); break; default: $link_att = link_att($mailhost, $mail, $attach_tab, $display_part_no); break; } } $subject_array = imap_mime_header_decode($ref_contenu_message->subject); for ($j = 0; $j < count($subject_array); $j++) $subject .= $subject_array[$j]->text; $from_array = imap_mime_header_decode($ref_contenu_message->fromaddress); for ($j = 0; $j < count($from_array); $j++) $from .= $from_array[$j]->text; $to_array = imap_mime_header_decode($ref_contenu_message->toaddress); for ($j = 0; $j < count($to_array); $j++) $to .= $to_array[$j]->text; if(!empty($ref_contenu_message->ccaddress)){ $cc_array = imap_mime_header_decode($ref_contenu_message->ccaddress); for ($j = 0; $j < count($cc_array); $j++){ $cc .= $cc_array[$j]->text; } }else{ $cc = ""; } $content = Array( 'from' => htmlspecialchars($from), 'to' => htmlspecialchars($to), 'cc' => htmlspecialchars($cc), 'subject' => htmlspecialchars($subject), 'date' => $ref_contenu_message->udate, 'att' => $link_att, 'body' => $glob_body, 'body_mime' => $tmp['mime'], 'body_transfer' => $tmp['transfer'], 'header' => $header, 'verbose' => $verbose); return ($content); } /* ----------------------------------------------------- */ // based on a function from [email protected] function GetPart($this_part, $part_no, $display_rfc822) { GLOBAL $attach_tab; $att_name = '[unknown]'; if ($this_part->ifdescription == TRUE) $att_name = $this_part->description; for ($lcv = 0; $lcv < count($this_part->parameters); $lcv++) { $param = $this_part->parameters[$lcv]; if (($param->attribute == 'NAME') || ($param->attribute == 'name')) { $att_name = $param->value; break; } } switch ($this_part->type) { case TYPETEXT: $mime_type = 'text'; break; case TYPEMULTIPART: $mime_type = 'multipart'; for ($i = 0; $i < count($this_part->parts); $i++) { if ($part_no != '') $part_no = $part_no . '.'; for ($i = 0; $i < count($this_part->parts); $i++) { // if it's an alternative, we skip the text part to only keep the HTML part if (strtolower($this_part->subtype) == "alternative")// && $read == true) GetPart($this_part->parts[++$i], $part_no . ($i + 1), $display_rfc822); else GetPart($this_part->parts[$i], $part_no . ($i + 1), $display_rfc822); } } break; case TYPEMESSAGE: $mime_type = 'message'; // well it's a message we have to parse it to find attachments or text message $num_parts = count($this_part->parts[0]->parts); if ($num_parts > 0) for ($i = 0; $i < $num_parts; $i++) GetPart($this_part->parts[0]->parts[$i], $part_no . '.' . ($i + 1), $display_rfc822); else GetPart($this_part->parts[0], $part_no . '.1', $display_rfc822); break; // Maybe we can do something with the mime types later ?? case TYPEAPPLICATION: $mime_type = 'application'; break; case TYPEAUDIO: $mime_type = 'audio'; break; case TYPEIMAGE: $mime_type = 'image'; break; case TYPEVIDEO: $mime_type = 'video'; break; case TYPEMODEL: $mime_type = 'model'; break; default: $mime_type = 'unknown'; } $full_mime_type = $mime_type . '/' . $this_part->subtype; switch ($this_part->encoding) { case ENC7BIT: $encoding = '7BIT'; break; case ENC8BIT: $encoding = '8BIT'; break; case ENCBINARY: $encoding = 'BINARY'; break; case ENCBASE64: $encoding = 'BASE64'; break; case ENCQUOTEDPRINTABLE: $encoding = 'QUOTED-PRINTABLE'; break; default: $encoding = 'none'; break; } if (($full_mime_type == 'message/RFC822' && $display_rfc822 == true) || ($mime_type != 'multipart' && $full_mime_type != 'message/RFC822')) { if ($this_part->ifparameters == TRUE) while ($obj = array_pop($this_part->parameters)) if ($obj->attribute == 'CHARSET') $charset = $obj->value; $tmp = Array( 'number' => ($part_no != '' ? $part_no : 1), 'id' => $this_part->id, 'name' => $att_name, 'mime' => $full_mime_type, 'transfer' => $encoding, 'charset' => $this_part->charset, 'size' => ($this_part->bytes > 1000) ? ceil($this_part->bytes / 1000) : 1); array_unshift($attach_tab, $tmp); } } $title = "Message"; include ('header.php'); $id = $_GET['id']; $servr = "imap.***.com:143/novalidate-cert/tls"; $user = "adam@***.com"; $passwd = "***"; $folder = "INBOX"; $verbose = 0; $content = aff_mail($servr, $user, stripslashes($passwd), $folder, $id, $verbose); if ($content['cc'] != '') { echo $content["cc"]; } if ($content['subject'] == ''){ $content['subject'] = "No Subject"; } echo $content['subject']; echo $content['date']; echo $content['att']; echo $content['body']; while ($tmp = array_shift($attach_tab)) { // $attach_tab is the array of attachments // If it's a text/plain, display it if ($display_text_attach && eregi ('text/plain', $tmp['mime'])) echo '<hr />'.view_part($servr, $user, stripslashes($passwd), $folder, $mail, $tmp['number'], $tmp['transfer'], $tmp['charset'], $charset); if ($display_img_attach && (eregi ('image', $tmp['mime']) && ($tmp['id'] == ''))) { // if it's an image, display it $img_type = array_pop(explode('/', $tmp['mime'])); if (eregi('JPEG', $img_type) || eregi('JPG', $img_type) || eregi('GIF', $img_type) || eregi ('PNG', $img_type)) { echo '<hr />'; echo $tmp['number']; } } } include('footer.php'); All the errors so far are.. Notice: Undefined property: stdClass::$id in /var/www/awp/pages/user/email/functions.php on line 287 Notice: Undefined property: stdClass::$charset in /var/www/awp/pages/user/email/functions.php on line 291 Notice: Undefined property: stdClass::$id in /var/www/awp/pages/user/email/functions.php on line 287 Notice: Undefined property: stdClass::$charset in /var/www/awp/pages/user/email/functions.php on line 291 Any idea why $this_part->id $this_part->charset are empty? Seems like anything from $this_part is gone.. I'm confused Quote Link to comment https://forums.phpfreaks.com/topic/243059-imap-problem/ Share on other sites More sharing options...
phpSensei Posted July 28, 2011 Share Posted July 28, 2011 Your receving a E_NOTICE error, it means the Class member variables such as "Properties" aren't defined in your code. In other words you havn't created the variables listed in the error report. stdCLASS is just PHP's generic empty class... I believe you need to do a data type casting on $obj such as (object)... $obj= (object) $array; I don't know what lines 200's are, so you will need to post it. have a look at this http://php.net/manual/en/language.types.object.php Quote Link to comment https://forums.phpfreaks.com/topic/243059-imap-problem/#findComment-1248370 Share on other sites More sharing options...
phpsycho Posted July 28, 2011 Author Share Posted July 28, 2011 still getting this.. Notice: Undefined property: stdClass::$id in /var/www/awp/pages/user/email/functions.php on line 288 Notice: Undefined property: stdClass::$charset in /var/www/awp/pages/user/email/functions.php on line 292 heres a snippet of what the errors are referring to if (($full_mime_type == 'message/RFC822' && $display_rfc822 == true) || ($mime_type != 'multipart' && $full_mime_type != 'message/RFC822')) { if ($this_part->ifparameters == TRUE) while ($obj = array_pop($this_part->parameters)) if ($obj->attribute == 'CHARSET') $charset = $obj->value; $tmp = Array( 'number' => ($part_no != '' ? $part_no : 1), 'id' => $this_part->id, 'name' => $att_name, 'mime' => $full_mime_type, 'transfer' => $encoding, 'charset' => $this_part->charset, 'size' => ($this_part->bytes > 1000) ? ceil($this_part->bytes / 1000) : 1); array_unshift($attach_tab, $tmp); } I'm a newb when it comes to imap functions lol, didn't know they even existed until couple weeks ago. Quote Link to comment https://forums.phpfreaks.com/topic/243059-imap-problem/#findComment-1248746 Share on other sites More sharing options...
phpSensei Posted July 28, 2011 Share Posted July 28, 2011 Where is $this_part defined? Post that part of the code too.. Quote Link to comment https://forums.phpfreaks.com/topic/243059-imap-problem/#findComment-1248776 Share on other sites More sharing options...
phpsycho Posted July 28, 2011 Author Share Posted July 28, 2011 function aff_mail($servr, $user, $passwd, $folder, $mail, $verbose) { $mailhost = $servr; GLOBAL $attach_tab; GLOBAL $PHP_SELF; $glob_body = ''; $subject = $from = $to = $cc = ''; $pop = @imap_open('{' . $mailhost . '}' . $folder, $user, $passwd); $num_messages = @imap_num_msg($pop); $ref_contenu_message = @imap_header($pop, $mail); $struct_msg = @imap_fetchstructure($pop, $mail); if (sizeof($struct_msg->parts) > 0) GetPart($struct_msg, NULL, false); else GetSinglePart($struct_msg, htmlspecialchars(imap_fetchheader($pop, $mail)), @imap_body($pop, $mail)); ///other code here } function GetPart($this_part, $part_no, $display_rfc822) { GLOBAL $attach_tab; $att_name = '[unknown]'; if ($this_part->ifdescription == TRUE) $att_name = $this_part->description; for ($lcv = 0; $lcv < count($this_part->parameters); $lcv++) { $param = $this_part->parameters[$lcv]; if (($param->attribute == 'NAME') || ($param->attribute == 'name')) { $att_name = $param->value; break; } }$obj= (object) $array; switch ($this_part->type) { case TYPETEXT: $mime_type = 'text'; break; case TYPEMULTIPART: $mime_type = 'multipart'; for ($i = 0; $i < count($this_part->parts); $i++) { if ($part_no != '') $part_no = $part_no . '.'; for ($i = 0; $i < count($this_part->parts); $i++) { // if it's an alternative, we skip the text part to only keep the HTML part if (strtolower($this_part->subtype) == "alternative")// && $read == true) GetPart($this_part->parts[++$i], $part_no . ($i + 1), $display_rfc822); else GetPart($this_part->parts[$i], $part_no . ($i + 1), $display_rfc822); } } break; case TYPEMESSAGE: $mime_type = 'message'; // well it's a message we have to parse it to find attachments or text message $num_parts = count($this_part->parts[0]->parts); if ($num_parts > 0) for ($i = 0; $i < $num_parts; $i++) GetPart($this_part->parts[0]->parts[$i], $part_no . '.' . ($i + 1), $display_rfc822); else GetPart($this_part->parts[0], $part_no . '.1', $display_rfc822); break; // Maybe we can do something with the mime types later ?? case TYPEAPPLICATION: $mime_type = 'application'; break; case TYPEAUDIO: $mime_type = 'audio'; break; case TYPEIMAGE: $mime_type = 'image'; break; case TYPEVIDEO: $mime_type = 'video'; break; case TYPEMODEL: $mime_type = 'model'; break; default: $mime_type = 'unknown'; } $full_mime_type = $mime_type . '/' . $this_part->subtype; switch ($this_part->encoding) { case ENC7BIT: $encoding = '7BIT'; break; case ENC8BIT: $encoding = '8BIT'; break; case ENCBINARY: $encoding = 'BINARY'; break; case ENCBASE64: $encoding = 'BASE64'; break; case ENCQUOTEDPRINTABLE: $encoding = 'QUOTED-PRINTABLE'; break; default: $encoding = 'none'; break; } if (($full_mime_type == 'message/RFC822' && $display_rfc822 == true) || ($mime_type != 'multipart' && $full_mime_type != 'message/RFC822')) { if ($this_part->ifparameters == TRUE) while ($obj = array_pop($this_part->parameters)) if ($obj->attribute == 'CHARSET') $charset = $obj->value; $tmp = Array( 'number' => ($part_no != '' ? $part_no : 1), 'id' => $this_part->id, 'name' => $att_name, 'mime' => $full_mime_type, 'transfer' => $encoding, 'charset' => $this_part->charset, 'size' => ($this_part->bytes > 1000) ? ceil($this_part->bytes / 1000) : 1); array_unshift($attach_tab, $tmp); } } $pop = @imap_open('{' . $mailhost . '}' . $folder, $user, $passwd); $struct_msg = @imap_fetchstructure($pop, $mail); GetPart($struct_msg, NULL, false); function GetPart($this_part, $part_no, $display_rfc822) Quote Link to comment https://forums.phpfreaks.com/topic/243059-imap-problem/#findComment-1248790 Share on other sites More sharing options...
phpsycho Posted July 29, 2011 Author Share Posted July 29, 2011 I just removed those two options that are causing issues. doesn't look like I need them but I may be wrong. So far its working without them, but I think I may need those two for getting an attachment image, or downloading any kind of attachment. Not totally sure though.. <?php include ('includes/conn.php'); $id = $_GET['id']; $num = $_GET['num']; $mime = strtolower($_GET['mime']); $transfer = $_GET['transfer']; header("Content-type: image/$mime"); $servr = "imap.**.com:143/novalidate-cert/tls"; $user = "adam@**"; $passwd = "**"; $pop = imap_open('{'.$servr.'}', $user, stripslashes($passwd)); $img = imap_fetchbody($pop, $id, $num); imap_close($pop); if ($transfer == 'BASE64'){ $img = base64_decode($img); }else if ($transfer == 'QUOTED-PRINTABLE'){ $img = imap_qprint($img); } echo $img; ?> All that code does now is spit out a blank page. I commented out the header() and it displayed the source of the image decoded using base64_decode. but when I try displaying it, it comes up with nothing. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/243059-imap-problem/#findComment-1249244 Share on other sites More sharing options...
phpsycho Posted August 1, 2011 Author Share Posted August 1, 2011 bump Quote Link to comment https://forums.phpfreaks.com/topic/243059-imap-problem/#findComment-1250364 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.