fgets getting muddled line from IMAP connection...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
c0ldfyr3
Forum Newbie
Posts: 2
Joined: Tue Sep 28, 2010 1:18 pm

fgets getting muddled line from IMAP connection...

Post by c0ldfyr3 »

Hi all,

First question on the board, sorry it's so directly to the point!

I'm using an IMAP class I got from phpclasses.org and it seems to work perfectly for 99.99% of emails, the other 0.01% are giving me back a muddled line in the header and or subject and this particular line is of the utmost importance regarding my scripts functionality.

A little background, I'm getting the body and header to each email in a mailbox and parsing them for certain key lines to determine what to do with them, I'm using preg_match to extract the data on the lines that I need and at first I thought it was preg_match that was causing the issue but I've debugged deep down into the bowls of the IMAP class and have come to realise fgets seems to be the route of the issue.

The particular problem I'm having is, in a line in the body and/or header of the message is the text [X-Custom: http://www.website.com/folder/script.php?var=1234] minus the brackets. For 0.01% of emails this is being returned as junk from fgets and I'm getting the following on two lines:

X-Custom: http://www.website.com/folder/script.php?var=3D12=
34

The patterin I see is that I get 3D (hex for = yet the = still remains before it) prepending the code I want after var= and then the 4 digit code is being trasnformed into 12=\r\n34 so my code is being split into two lines. I could write a work around but surely there's an easier option??

Something worth noting is that the line looks perfect in 3 different webmail clients and Thunderbird. Also I'm not specifying a length for fgets and my php version is 5.2.8.

Thanks for any input,

c0ld
c0ldfyr3
Forum Newbie
Posts: 2
Joined: Tue Sep 28, 2010 1:18 pm

Re: fgets getting muddled line from IMAP connection...

Post by c0ldfyr3 »

ini_set( 'auto_detect_line_endings', 1 );

Made no difference.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: fgets getting muddled line from IMAP connection...

Post by John Cartwright »

I believe it is simply the amount of characters exceeded the maximum allowed per line, and therefore it was broken up into 2 lines. How to deal with it in your case, or what it's called seems to have eluded me..
Post Reply