Solution and small question (was Re: [imp] Question about charset and Saved Mail)

Santiago Romero sromero at servicom2000.com
Wed Jan 15 14:01:56 PST 2003


En Mon, 13 Jan 2003 09:12:04 +0100 Santiago Romero
<sromero at servicom2000.com> escribio:

  Well, I finally managed to solve my problem. 

Problem: Displaying of Quoted Printable messages in INBOX,
Trash and Sent-Mail is right (with message.php3 source code),
but in the Drafts folder (with compose.php3), charsets are not
translated correctly (i.e. camión -> cami=3Dn).

Browsing mailbox.php3 I found a piece of source code that
decoded QUOTED_PRINTABLE and ENCBASE64 bodies. I applied that
code to the DRAFT section of compose.php3:

---------------------------------------------------------------
case DRAFT:
     // ( some code snipped for readability )
     if ($mailbox && $index && $bodypart) 
     {
        $h = imap_header($imp->stream, imap_msgno($imp->stream, $index));
        (...)                                
        $msg = imap_fetchbody($imp->stream, $index, $bodypart, FT_UID);
        $structure = @imap_fetchstructure($imp->stream, $index, FT_UID);
        if (@count($structure->parts) > 1) attach_files($structure, '');

        $get_sig = false;

       // begin new code
       // Translate charsets (from mailbox.php3 / Horde-IMP team)
       // compose.php3 changed by sromero - 15-01-2003
       if ($structure->encoding == ENCQUOTEDPRINTABLE) {
           $qmsg = imap_qprint($msg);
           if (!empty($qmsg)) $msg = $qmsg;
       } elseif ($structure->encoding == ENCBASE64) {
           $msg = imap_base64($msg);
       }             
       // end new code
    }
    break;
---------------------------------------------------------------

 Now it seems to work correctly, but I have 2 doubts:
    

1.- I also need to decode UTF8, and I have apache with xml 
support, so I have the utf8_decode function available. How do I 
identify WHEN my message is utf8-encoded? I mean, 

 elseif( $structure->encoding == WHAT_DO_I_PUT_HERE_FOR_UTF8 )
   $msg = utf8_decode($msg);

 How do I detect if my message is UTF8 encoded?


2.- Do you think the above source code is well applied, or it
could damage attachs or something like that? I hope $msg is just
the body message, not the message itself. If it's the body message
I think the code is right, if it's the msg + attachments, I'm
afraid the qprint() or base64() functions could modify the attachs
or something they shouldn't touch.

 The variable $msg is defined as:

 $msg = imap_fetchbody($imp->stream, $index, $bodypart, FT_UID);

 The third parameter is:

 And bodypart is 1 in this part of the code... is that fetching just
the body, so it's right, isn't it?

 Thanks a lot to all and specially to IMP developers.

-- 
Santiago Romero


More information about the imp mailing list