Browse Source

multipart messages complete, message-id conversion done.

pull/50/head
Michael 9 years ago
parent
commit
a74b0746b1
4 changed files with 29 additions and 20 deletions
  1. +2
    -2
      include/delivery.php
  2. +23
    -14
      include/email.php
  3. +2
    -2
      include/notifier.php
  4. +2
    -2
      include/poller.php

+ 2
- 2
include/delivery.php View File

@ -438,14 +438,14 @@ function delivery_run($argv, $argc){
$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'])


+ 23
- 14
include/email.php View File

@ -232,24 +232,27 @@ function email_send($addr, $subject, $headers, $item) {
//$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);
@ -257,12 +260,18 @@ function email_send($addr, $subject, $headers, $item) {
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);
}

+ 2
- 2
include/notifier.php View File

@ -651,10 +651,10 @@ function notifier_run($argv, $argc){
$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'])


+ 2
- 2
include/poller.php View File

@ -420,13 +420,13 @@ function poller_run($argv, $argc){
// 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",


Loading…
Cancel
Save