note 117891 added to function.imap-8bit
| From: | daveatjuferdotinfo | Date: | Thu, 27 Aug 2015 09:18:40 +0000 |
| Subject: | note 117891 added to function.imap-8bit | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-203486@lists.php.net to get a copy of this message | ||
Encode a mail-subject-string to a encoded-word according to RFC2047 with awareness of special
characters and total-linelength of 75.
Example: "Subject Testä" -> "=?ISO-8859-1?Q?Subject_Test=E4?="
<?php
function getSubjectEncoded($_str,$_charset='ISO-8859-1'){
// 27.08.2015 david jufer
// Convert an 8bit string to a encoded-word string (according to RFC2047)
www.ietf.org/rfc/rfc2047.txt
// encoded-word = "=?" charset "?" encoding "?" encoded-text
"?="
// An 'encoded-word' may not be more than 75 characters long, including
'charset', 'encoding', 'encoded-text', and delimiters.
// The "Q" encoding is similar to the "Quoted-Printable"
content-transfer-encoding defined in RFC 2045
$ret = '';
$str = imap_8bit($_str);
$len = 7+strlen($_charset);
// remove linebreaks from imap_8bit, string chunks are too long
$str = str_replace("=\r\n",'',$str);
// insert linebreaks at right position, be aware of special chars ("ä"
"=E4") do not split them
$s = 0;
$l = 75-$len;
while(strlen($str)>$s){
$ts = $s;
if(substr($str,($s+$l)-2,1)=='='){
$s += $l-2;
}else if(substr($str,($s+$l)-1,1)=='='){
$s += $l-1;
}else{
$s += $l;
}
$ret .= "\r\n".substr($str,$ts,$s-$ts);
}
// remove first linebreak, replace SPACES with "_"
$ret = str_replace(' ','_',trim($ret));
// put together encoded-word
$ret = '=?'.$_charset.'?Q?'.str_replace("\r\n","?=\r\n
=?".$_charset."?Q?",$ret)."?=";
// rückgabe
return $ret;
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 84.226.66.123
----
Manual Page -- http://php.net/manual/en/function.imap-8bit.php
Edit -- https://master.php.net/note/edit/117891
Del: integrated -- https://master.php.net/note/delete/117891/integrated
Del: useless -- https://master.php.net/note/delete/117891/useless
Del: bad code -- https://master.php.net/note/delete/117891/bad+code
Del: spam -- https://master.php.net/note/delete/117891/spam
Del: non-english -- https://master.php.net/note/delete/117891/non-english
Del: in docs -- https://master.php.net/note/delete/117891/in+docs
Del: other reasons-- https://master.php.net/note/delete/117891
Reject -- https://master.php.net/note/reject/117891
Search -- https://master.php.net/manage/user-notes.php