$file = tempnam("/tmp/friendica/", "mail-out-");
file_put_contents($file, json_encode($it));
- $headers .= 'Message-Id: <' . email_cleanupmessageid($it['uri']). '>' . "\n";
+ $headers .= 'Message-Id: <' . iri2msgid($it['uri']). '>' . "\n";
//logger("Mail: uri: ".$it['uri']." parent-uri ".$it['parent-uri'], LOGGER_DEBUG);
//logger("Mail: Data: ".print_r($it, true), LOGGER_DEBUG);
//logger("Mail: Data: ".print_r($it, true), LOGGER_DATA);
if($it['uri'] !== $it['parent-uri']) {
- $headers .= 'References: <' . email_cleanupmessageid($it['parent-uri']) . '>' . "\n";
+ $headers .= 'References: <' . iri2msgid($it['parent-uri']) . '>' . "\n";
if(! strlen($it['title'])) {
$r = q("SELECT `title` FROM `item` WHERE `parent-uri` = '%s' LIMIT 1",
dbesc($it['parent-uri'])
//$headers .= 'Content-Type: text/html; charset=UTF-8' . "\n";
//$headers .= 'Content-Type: text/plain; charset=UTF-8' . "\n";
//$headers .= 'Content-Transfer-Encoding: 8bit' . "\n\n";
+
+ $part = uniqid("", true);
+
$html = prepare_body($item);
$headers .= "Mime-Version: 1.0\n";
- $headers .= 'Content-Type: multipart/alternative; boundary="=_1f5dbdf8dbd0a060ea5bc3050bb14c6a"'."\n\n";
+ $headers .= 'Content-Type: multipart/alternative; boundary="=_'.$part.'"'."\n\n";
- $body = "--=_1f5dbdf8dbd0a060ea5bc3050bb14c6a\n";
- $body .= "Content-Transfer-Encoding: quoted-printable\n";
+ $body = "\n--=_".$part."\n";
+ $body .= "Content-Transfer-Encoding: 8bit\n";
$body .= "Content-Type: text/plain; charset=utf-8; format=flowed\n\n";
$body .= html2plain($html)."\n";
- $body .= "--=_1f5dbdf8dbd0a060ea5bc3050bb14c6a\n";
- $body .= "Content-Transfer-Encoding: quoted-printable\n";
+ $body .= "--=_".$part."\n";
+ $body .= "Content-Transfer-Encoding: 8bit\n";
$body .= "Content-Type: text/html; charset=utf-8\n\n";
- $body .= $html."\n\n";
+ $body .= '<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">'.$html."</body></html>\n";
- $body .= "--=_1f5dbdf8dbd0a060ea5bc3050bb14c6a--\n";
+ $body .= "--=_".$part."--";
//$message = '<html><body>' . $html . '</body></html>';
//$message = html2plain($html);
mail($addr, $subject, $body, $headers);
}
-function email_cleanupmessageid($messageid) {
- global $a;
-
- if (!strpos($messageid, '@'))
- $messageid = str_replace(":", ".", $messageid).'@'.$a->get_hostname();
-
- return($messageid);
+function iri2msgid($iri) {
+ if (!strpos($iri, "@"))
+ $msgid = preg_replace("/urn:(\S+):(\S+)\.(\S+):(\d+):(\S+)/i", "urn!$1!$4!$5@$2.$3", $iri);
+ else
+ $msgid = $iri;
+ return($msgid);
}
+function msgid2iri($msgid) {
+ if (strpos($msgid, "@"))
+ $iri = preg_replace("/urn!(\S+)!(\d+)!(\S+)@(\S+)\.(\S+)/i", "urn:$1:$4.$5:$2:$3", $msgid);
+ else
+ $iri = $msgid;
+ return($iri);
+}
$file = tempnam("/tmp/friendica/", "mail-out2-");
file_put_contents($file, json_encode($it));
- $headers .= 'Message-Id: <' . email_cleanupmessageid($it['uri']) . '>' . "\n";
+ $headers .= 'Message-Id: <' . iri2msgid($it['uri']) . '>' . "\n";
if($it['uri'] !== $it['parent-uri']) {
- $headers .= 'References: <' . email_cleanupmessageid($it['parent-uri']) . '>' . "\n";
+ $headers .= 'References: <' . iri2msgid($it['parent-uri']) . '>' . "\n";
if(! strlen($it['title'])) {
$r = q("SELECT `title` FROM `item` WHERE `parent-uri` = '%s' LIMIT 1",
dbesc($it['parent-uri'])
// look for a 'references' header and try and match with a parent item we have locally.
$raw_refs = ((x($headers,'references')) ? str_replace("\t",'',$headers['references']) : '');
- $datarray['uri'] = trim($meta->message_id,'<>');
+ $datarray['uri'] = msgid2iri(trim($meta->message_id,'<>'));
if($raw_refs) {
$refs_arr = explode(' ', $raw_refs);
if(count($refs_arr)) {
for($x = 0; $x < count($refs_arr); $x ++)
- $refs_arr[$x] = "'" . str_replace(array('<','>',' '),array('','',''),dbesc($refs_arr[$x])) . "'";
+ $refs_arr[$x] = "'" . msgid2iri(str_replace(array('<','>',' '),array('','',''),dbesc($refs_arr[$x]))) . "'";
}
$qstr = implode(',',$refs_arr);
$r = q("SELECT `uri` , `parent-uri` FROM `item` WHERE `uri` IN ( $qstr ) AND `uid` = %d LIMIT 1",