The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 21, 2019, 06:37:59 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Would appreciate encoding help (PHP IMAP functions)  (Read 3001 times)
sysbuilder
Rookie
**
Offline Offline

Posts: 17


View Profile
« on: June 07, 2008, 11:15:30 AM »

So I'm currently writing an activation email checker in PHP. My script uses PHP's IMAP functions to fetch an email with certain subject text, and then parses the plain text for links, using cURL to visit the links. I've experienced some success with it so far, but I've also run into a baffling problem that I am not sure how to fix.

So a certain service sends activation emails in the form of:
http://www.randomwebinternetservice.com/activation.php?key=123456

When I check the activation email manually (in a program like SquirrelMail), I can see the correct key displayed. However, when I try to fetch the same email using PHP's IMAP functions, in the following snippet of code:

Code:
imap_fetchbody($this->imapConnection, $emailId, "1")

The same url above shows up as http://www.randomwebinternetservice.com/activation.php?key=3D123456 (there is an extra 3D present in the URL).

I'm a big newbie when it comes to encoding issues, but I've tried to use mb_detect_encoding on the return value from imap_fetchbody (it returns an ASCII encoding), while the MIME header for the email shows "MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable", so possibly I need to somehow decode UTF-8 entities?

Not really sure what is happening, so I would be grateful for any help you guys could provide me.

Thanks,
sysbuilder
Logged

No links in signatures please
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #1 on: June 07, 2008, 01:50:23 PM »

3d is hex for an equals sign ( = ) - which can look like its a glitch or something, but 3d could also be dec 61, the size of the next block that you are downloading if this is a multipart document. Gonna need more than what you have posted to figure it out... can you post the entire RAW source of the email? Take anything identifying and replace it with a capital X so that we know there's a character there, but the sizing of the document will remain unchanged. Change as little as possible to make sure youre safe, but so the mail structure can be seen.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
sysbuilder
Rookie
**
Offline Offline

Posts: 17


View Profile
« Reply #2 on: June 24, 2008, 10:37:22 PM »

Hey perkiset - very sorry for the long delay in replying, basically I was without internet access for about a week due to an emergency, then when I regained access, I found that the server I usually do development work on had been compromised. So I'm just now getting back into the swing of things...

Anyway, here are the raw headers of the email (identifying elements replaced with capital X's) - obtained using imap_fetchheader:

Code:
Return-path:
Envelope-to: XXXX@XXXXXX.com
Delivery-date: Sat, 07 Jun 2008 12:18:48 -0500
Received: from XXXXXX.net ([XXX.XXX.XX.XXX] helo=XXXXXXX.net)
by XXXXX.XXXXXX.com with esmtp (Exim 4.68)
(envelope-from )
id 14XXX0-0007UaXXX-Gb
for XXXX@XXXXXX.com; Sat, 07 Jun 2008 12:18:48 -0500
Received: from XXXX.XXX (XXXX.XXX [XX.X.X.X])
by XXXXXX.net (Postfix) with ESMTP id 9FCX5F6XX85
for ; Sat, 7 Jun 2008 17:18:45 +0000 (GMT)
Received: by XXXX.XX (Postfix, from userid XX)
id XXXXX; Sat, 7 Jun 2008 13:18:58 -0400 (EDT)
Received: from localhost
by localhost (MailRouter rev. 1.04)
id TUMXXXXXXXXXXXXXXXXXE1ODYyNVNhMS4wNFNUUEhQ; Sat Jun 7 17:18:58 2008
To: XXXX@XXXXXX.com
Subject: Activate XXXXXXXXXXXXXXX
Date: Sat, 7 Jun 2008 17:18:57 +0000
From: XXXXXXXXXX
Message-ID: <XXXXXXXXXXXX@XXXXXXXX.com>
X-Priority: 3
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

I fiddled around for about a hour and cannot figure out how to get PHP to show the raw body of the email (whenever I use imap_fetchbody it simply returns the plain text of the email), but here is the output of imap_fetchstructure (with some comments of mine, variable meanings translated from the values over at http://us.php.net/manual/en/function.imap-fetchstructure.php):

Code:
object(stdClass)#19 (12) {
["type"]=> int(0)                      // Primary body type is 'text'
["encoding"]=> int(4)                // Body transfer encoding is 'QUOTED-PRINTABLE'
["ifsubtype"]=> int(1)               // There is a subtype string
["subtype"]=> string(5) "PLAIN"  // The subtype is plain
["ifdescription"]=> int(0)           // There is no content description string
["ifid"]=> int(0)                       // There is no identification string
["lines"]=> int(10)                    // 10 lines in the email
["bytes"]=> int(295)                // 295 bytes in the email
["ifdisposition"]=> int(0)           // No disposition string
["ifdparameters"]=> int(0)         // No dparameters array
["ifparameters"]=> int(1)          // Parameters array exists
["parameters"]=> array(1) { [0]=> object(stdClass)#23 (2) { ["attribute"]=> string(7) "charset" ["value"]=> string(5) "utf-8" } } }   // charset is UTF-8
To activate XXXXXX, please click the following link XXXX (basically plain text message body is here)

Hopefully that helps a bit, if there is anything else I can do to make the problem clearer, please let me know.

Thanks,
sysbuilder
Logged

No links in signatures please
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!