Merge pull request #7851 from annando/mail-header

Storing the mail header in the item
This commit is contained in:
Hypolite Petovan 2019-11-21 11:10:43 -05:00 committed by GitHub
commit 11e71780b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 22 deletions

View file

@ -291,12 +291,10 @@ class Item extends BaseObject
$row['object-type'] = Activity\ObjectType::NOTE; $row['object-type'] = Activity\ObjectType::NOTE;
} }
} elseif (array_key_exists('verb', $row) && in_array($row['verb'], ['', Activity::POST, Activity::SHARE])) { } 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 safe some performance by building tag and file strings only here.
// We remove object and target since they aren't used for this type. // We remove the target since they aren't used for this type.
if (array_key_exists('object', $row)) { // In mail posts we do store some mail header data in the object.
$row['object'] = '';
}
if (array_key_exists('target', $row)) { if (array_key_exists('target', $row)) {
$row['target'] = ''; $row['target'] = '';
} }

View file

@ -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. // 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)) { 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 $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']); Logger::log("Mail: can't fetch msg ".$msg_uid." for ".$mailconf['user']);
continue; continue;
} }
$datarray['body'] = Strings::escapeHtml($r['body']); $datarray['body'] = Strings::escapeHtml($r['body']);
$datarray['body'] = BBCode::limitBodySize($datarray['body']); $datarray['body'] = BBCode::limitBodySize($datarray['body']);
Logger::log("Mail: Importing ".$msg_uid." for ".$mailconf['user']); 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); if (!empty($headers->from)) {
$fromdecoded = ""; $object['from'] = $headers->from;
foreach ($from as $frompart) {
if ($frompart->charset != "default") {
$fromdecoded .= iconv($frompart->charset, 'UTF-8//IGNORE', $frompart->text);
} else {
$fromdecoded .= $frompart->text;
}
} }
$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 (isset($fromarr[0]->personal)) { if (!empty($headers->sender)) {
$fromname = $fromarr[0]->personal; $object['sender'] = $headers->sender;
} else { }
$fromname = $frommail;
if (!empty($object)) {
$datarray['object'] = json_encode($object);
}
$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; $datarray['author-name'] = $fromname;