Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : IMAP, POP3 and NNTP Functions : imap_utf7_encode

imap_utf7_encode

Converts ISO-8859-1 string to modified UTF-7 text (PHP 4, PHP 5)
string imap_utf7_encode ( string data )


Code Examples / Notes » imap_utf7_encode

hartmut

this function was buggy up to php3.0.15 / php4beta4pl1

31-jul-2006 03:10

This encoding will not work for cyrus imapservers and you might have problems with other mail clients.
Use mb_convert_encoding($str, "UTF7-IMAP","ISO-8859-15") instead.
ps: mb_convert_encoding() requires   building php with  --enable-mbstring option


02-nov-2005 11:01

Note that php4 (4.4.0) will encode IMAP folders in a way that no other program will be able to decode them back.
$ php4 <<EOF
> <?php
> echo "ENCODED: " . imap_utf7_encode("Ü") . "\\n";
> ?>
> EOF
ENCODED: &w5w-
Now try to decode the result string ("&w5w-") using e.g. javamail or python's imaplib, or if you don't like these languages - create an IMAP folder using PHP and try to display it in an IMAP client (mutt, thunderbird, outlook, whatever...)


dn

Maccoy function's isn't reliable 'cause it doesn't follow the RFC 2060. It will work fine for most latin chars (which, in base64, will turn into "+A..."), but for other language it can make a big mess. If you're using an internationalizated system, try using the other presented options.

marcelo

<?php
/**
* @return encoded string
* @param string $str        
* @desc Convert str to UTF-7 imap default mailbox names
   (the imap_utf7_encode don t built the same result)
*/
function getEncodedUtf7($str){
   if(!$str){
      echo "error: you need to give a string parameter.";
      return false;                        
   }
# change spaces by entropy because mb_convert fail with spaces
   $str=ereg_replace(" ","xyxy",$str);                
# if mb_convert work
   if($str=mb_convert_encoding($str,"UTF-7")){
       # change characters
           $str=preg_replace("/\+A/","&A",$str);
       # change to spaces again
           $str=preg_replace("/xyxy/"," ",$str);                        
       # return encoded string
           return $str;
# else
   }else{
       # print error and return false
           echo "error: is not possible to encode this string '$str'.[".
           imap_last_error().
           "]";
           return false;                      
   }                
}
?>


Change Language


Follow Navioo On Twitter
imap_8bit
imap_alerts
imap_append
imap_base64
imap_binary
imap_body
imap_bodystruct
imap_check
imap_clearflag_full
imap_close
imap_createmailbox
imap_delete
imap_deletemailbox
imap_errors
imap_expunge
imap_fetch_overview
imap_fetchbody
imap_fetchheader
imap_fetchstructure
imap_get_quota
imap_get_quotaroot
imap_getacl
imap_getmailboxes
imap_getsubscribed
imap_header
imap_headerinfo
imap_headers
imap_last_error
imap_list
imap_listmailbox
imap_listscan
imap_listsubscribed
imap_lsub
imap_mail_compose
imap_mail_copy
imap_mail_move
imap_mail
imap_mailboxmsginfo
imap_mime_header_decode
imap_msgno
imap_num_msg
imap_num_recent
imap_open
imap_ping
imap_qprint
imap_renamemailbox
imap_reopen
imap_rfc822_parse_adrlist
imap_rfc822_parse_headers
imap_rfc822_write_address
imap_savebody
imap_scanmailbox
imap_search
imap_set_quota
imap_setacl
imap_setflag_full
imap_sort
imap_status
imap_subscribe
imap_thread
imap_timeout
imap_uid
imap_undelete
imap_unsubscribe
imap_utf7_decode
imap_utf7_encode
imap_utf8
eXTReMe Tracker