15.3 Converting Messages to a Readable Format


You are getting messages in the standard UTF-7 encoding and you need to change them to UTF-8 encoding.

Technique

Use the imap_8bit() function, which takes a UTF-7 encoded string and converts it to a quoted printable string:

 <?php $mh = imap_open("{localhost/pop3:110} INBOX", $user, $pass)    or die("Cannot Open IMAP Stream"); $body = imap_8bit(imap_body($mh, $msg_num)); imap_close($mh) or die("Cannot Close IMAP Stream"); ?> 

Comments

UUCP, or UNIX-to-UNIX copy, was created as a result of the e-mail system. It was perfectly suited for its original purposes, which at the time were mainly the plain text mediums of Usenet and e-mail messages. However, UUCP was woefully inadequate at handling binary files. To work around this, programmers created uuencoding, which encodes 8-bit character sets to a 7-bit character set so that they can be sent over e-mail. Therefore, you have to use the imap_8bit() function to decode messages that are sent using this protocol.

In the solution example, we first open a stream to an IMAP mailbox by using the imap_open() function. Then we retrieve the body of a certain message specified in $msg_num . However, we must decode this message before printing it to the user, so we use the imap_8bit() function to convert the uuencoded string into a quoted printable string.



PHP Developer's Cookbook
PHP Developers Cookbook (2nd Edition)
ISBN: 0672323257
EAN: 2147483647
Year: 2000
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net