From ade926afc68b6000c15996e8966f6fddd2a52c3c Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 21 Nov 2019 15:28:18 +0000 Subject: [PATCH] Storing the mail header in the item --- src/Model/Item.php | 8 +++----- src/Worker/OnePoll.php | 41 ++++++++++++++++++++++++----------------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index 159fac455b..0b6c1c8bf2 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -291,12 +291,10 @@ class Item extends BaseObject $row['object-type'] = Activity\ObjectType::NOTE; } } elseif (array_key_exists('verb', $row) && in_array($row['verb'], ['', Activity::POST, Activity::SHARE])) { - // Posts don't have an object or target - but having tags or files. + // Posts don't have a target - but having tags or files. // We safe some performance by building tag and file strings only here. - // We remove object and target since they aren't used for this type. - if (array_key_exists('object', $row)) { - $row['object'] = ''; - } + // We remove the target since they aren't used for this type. + // In mail posts we do store some mail header data in the object. if (array_key_exists('target', $row)) { $row['target'] = ''; } diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php index 3f8b98ead1..fefe7d8020 100644 --- a/src/Worker/OnePoll.php +++ b/src/Worker/OnePoll.php @@ -539,9 +539,9 @@ class OnePoll } // look for a 'references' or an 'in-reply-to' header and try to match with a parent item we have locally. - $raw_refs = ((property_exists($meta, 'references')) ? str_replace("\t", '', $meta->references) : ''); + $raw_refs = (property_exists($meta, 'references') ? str_replace("\t", '', $meta->references) : ''); if (!trim($raw_refs)) { - $raw_refs = ((property_exists($meta, 'in_reply_to')) ? str_replace("\t", '', $meta->in_reply_to) : ''); + $raw_refs = (property_exists($meta, 'in_reply_to') ? str_replace("\t", '', $meta->in_reply_to) : ''); } $raw_refs = trim($raw_refs); // Don't allow a blank reference in $refs_arr @@ -601,31 +601,38 @@ class OnePoll Logger::log("Mail: can't fetch msg ".$msg_uid." for ".$mailconf['user']); continue; } + $datarray['body'] = Strings::escapeHtml($r['body']); $datarray['body'] = BBCode::limitBodySize($datarray['body']); Logger::log("Mail: Importing ".$msg_uid." for ".$mailconf['user']); - /// @TODO Adding a gravatar for the original author would be cool + $headers = imap_headerinfo($mbox, $meta->msgno); + $object = []; - $from = imap_mime_header_decode($meta->from); - $fromdecoded = ""; - foreach ($from as $frompart) { - if ($frompart->charset != "default") { - $fromdecoded .= iconv($frompart->charset, 'UTF-8//IGNORE', $frompart->text); - } else { - $fromdecoded .= $frompart->text; - } + if (!empty($headers->from)) { + $object['from'] = $headers->from; } - $fromarr = imap_rfc822_parse_adrlist($fromdecoded, BaseObject::getApp()->getHostName()); + if (!empty($headers->to)) { + $object['to'] = $headers->to; + } - $frommail = $fromarr[0]->mailbox."@".$fromarr[0]->host; + if (!empty($headers->reply_to)) { + $object['reply_to'] = $headers->reply_to; + } + + if (!empty($headers->sender)) { + $object['sender'] = $headers->sender; + } + + if (!empty($object)) { + $datarray['object'] = json_encode($object); + } - if (isset($fromarr[0]->personal)) { - $fromname = $fromarr[0]->personal; - } else { - $fromname = $frommail; + $fromname = $frommail = $headers->from[0]->mailbox . '@' . $headers->from[0]->host; + if (!empty($headers->from[0]->personal)) { + $fromname = $headers->from[0]->personal; } $datarray['author-name'] = $fromname; -- 2.39.5