Jump to content

iconv_mime_decode() has "malformed string" and imap_utf8() FIX cuts off message!


Recommended Posts

Hi there...

 

My problem is not being able to use e-mail piping or POP3 checking with a third party help

desk script, and I'm getting a different PHP error depending on which one I try.

 

 


PIPING WOES


When a user responds to a ticket by e-mail, it gets cut off after the first few characters

instead of printing the full body of that message to the ticket, and in the automated

e-mail to the Admin. There WAS a PHP memory limit error corresponding with this, but now

that I've changed my limit from 64MB to 256MB, there is no error at all associated with this

anomaly.

 

Note, originally the full e-mail was coming through ... but converted to all caps! I've found

that there's a bug in PHP's imap_utf8 function for versions 5.2.5+, so I was told to use the

following fix inserted in my piping script:

 

function imap_utf8_fix($string) {
  return iconv_mime_decode($string,0,"UTF-8");
}

 

That fixed the all caps issue .. but left me with the issue above of messages being cut off

prematurely, no matter the length, no matter the content of the message. (A line break

helps this along, but isn't necessary -- user input gets cut off after a few words no matter

what.)

 

// Finally, Sanitize
$email['from'] = $ifthd->sanitize_data( imap_utf8_fix( $email['from'] ) ); // TF
$email['nickname'] = $ifthd->sanitize_data( imap_utf8_fix( $email['nickname'] ) ); // TF
$email['to'] = $ifthd->sanitize_data( imap_utf8_fix( $email['to'] ) ); // TF
$email['subject'] = $ifthd->sanitize_data( imap_utf8_fix( $email['subject'] ) ); // TF
$email['message'] = $ifthd->sanitize_data( utf8_encode( decode_ISO88591( imap_utf8_fix( $email['message'] ) ) ) ); // TF
if ( ! $email['nickname'] ) $email['nickname'] = $email['from'];
if ( ! $email['from'] || ! $email['to'] || ! $email['subject'] || ! $email['message'] ) exit();
if ( ! $ifthd->validate_email( $email['from'] ) ) exit();

 

Please note, the 'message' field above is the one that's being cut off prematurely with

piping. Everything else comes through perfectly.

 

 


POP3 WOES


When a user replies to a ticket by e-mail, it converts their input to all caps. It's entered

into the ticket that way, and sent to the tech that way. I tried the above UTF-8 "fix" to

no avail. It had absolutely no effect at all on my POP3 checking script like it had on my

piping script. And what's more, it causes PHP to spit out this error in the directory of the

script:

 

[12-Sep-2008 23:11:01] PHP Warning:  iconv_mime_decode() [<a href='function.iconv-mime-decode'>function.iconv-mime-decode</a>]: Malformed string in /home/username/public_html/deskdir/scriptdir/pop3.php on line 42

 

Lines 43 to 45 of pop3.php reads:

 

function imap_utf8_fix($string) {
  return iconv_mime_decode($string,0,"UTF-8");
}

 

I've also tried a "2" in place of the 0, and "ISO-8859-1" in place of "UTF-8", but I have

absolutely no idea at all what I'm doing -- I know nothing about PHP.

 

The relevant sections of the code that correspond to the imap_utf8_fix above read:

 

				
// Finally, Sanitize
$email['from'] = $ifthd->sanitize_data( imap_utf8_fix( $email['from'] ) );
$email['nickname'] = $ifthd->sanitize_data( imap_utf8_fix( $email['nickname'] ) );
$email['to'] = $ifthd->sanitize_data( imap_utf8_fix( $email['to'] ) );
$email['subject'] = $ifthd->sanitize_data( imap_utf8_fix( $email['subject'] ) );
$email['message'] = $ifthd->sanitize_data( utf8_encode( decode_ISO88591( imap_utf8_fix( $email['message'] ) ) ) );
$email['date'] = $ifthd->sanitize_data( $email['date'] );
$email['date'] = strtotime( $email['date'] );
if ( ! $email['nickname'] ) $email['nickname'] = $email['from'];
if ( ! $email['from'] || ! $email['to'] || ! $email['subject'] || ! $email['message'] ) continue;
if ( ! $ifthd->validate_email( $email['from'] ) ) continue;

 

 

 


MY SERVER INFORMATION


MX entry - Priority: 0; myrealdomainname.com

Linux shared hosting at Hostgator.com

I've set a local php.ini file to only upgrade my memory limit to 256M

Safe mode is OFF.

 

PHP v5.2.6.

Kernel version 2.6.25.15-grsec

Apache version 1.3.41 (Unix)

MySQL version 5.0.51a-community

MySQL client version: 4.1.22

 

cPanel Version 11.23.6-STABLE 27225

Theme cPanel X v2.6.0

MySQL charset: UTF-8 Unicode (utf8)

MySQL connection collation: utf8_unicode_ci


 

 

 

If someone can tell me how to fix the "malformed string" the error log is referring to,

and stop my user's e-mails from printing in all caps, I would be very appreciative.

(Hopefully I was supposed to put this here and not the PHP Help forum.) My scripts

(pipe.php and pop3.php) are both attached.

 

Thanks in advance!

 

[attachment deleted by admin]

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.