]> git.mxchange.org Git - friendica.git/commitdiff
Storing the mail header in the item
authorMichael <heluecht@pirati.ca>
Thu, 21 Nov 2019 15:28:18 +0000 (15:28 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 21 Nov 2019 15:28:18 +0000 (15:28 +0000)
src/Model/Item.php
src/Worker/OnePoll.php

index 159fac455b9dd96f33c75da491fab12bda68b351..0b6c1c8bf22620c4c972185ff1d26548ddd07015 100644 (file)
@@ -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'] = '';
                        }
index 3f8b98ead1e391854b5e6b8543e64562202931ed..fefe7d8020b451130d06e444c80b372734368ef7 100644 (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.
-                                       $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;