]> git.mxchange.org Git - friendica.git/blobdiff - include/onepoll.php
bbcode: New element "share" for shared content
[friendica.git] / include / onepoll.php
index a50d234e22932fba603242e6fd41701fdb959c71..68d7873ecb9c3b54aeabc406c8a906d263eaf83b 100644 (file)
@@ -2,6 +2,13 @@
 
 require_once("boot.php");
 
+function RemoveReply($subject) {
+       while (in_array(strtolower(substr($subject, 0, 3)), array("re:", "aw:")))
+               $subject = trim(substr($subject, 4));
+
+       return($subject);
+}
+
 function onepoll_run(&$argv, &$argc){
        global $a, $db;
 
@@ -367,10 +374,6 @@ function onepoll_run(&$argv, &$argc){
        //                                                      $datarray['parent-uri'] = $r[0]['uri'];
                                                }
 
-
-                                               if(! x($datarray,'parent-uri'))
-                                                       $datarray['parent-uri'] = $datarray['uri'];
-
                                                // Decoding the header
                                                $subject = imap_mime_header_decode($meta->subject);
                                                $datarray['title'] = "";
@@ -385,11 +388,26 @@ function onepoll_run(&$argv, &$argc){
                                                //$datarray['title'] = notags(trim($meta->subject));
                                                $datarray['created'] = datetime_convert('UTC','UTC',$meta->date);
 
-                                               // Is it  reply?
+                                               // Is it a reply?
                                                $reply = ((substr(strtolower($datarray['title']), 0, 3) == "re:") or
                                                        (substr(strtolower($datarray['title']), 0, 3) == "re-") or
                                                        (raw_refs != ""));
 
+                                               // Remove Reply-signs in the subject
+                                               $datarray['title'] = RemoveReply($datarray['title']);
+
+                                               // If it seems to be a reply but a header couldn't be found take the last message with matching subject
+                                               if(!x($datarray,'parent-uri') and $reply) {
+                                                       $r = q("SELECT `uri` , `parent-uri` FROM `item` WHERE MATCH (`title`) AGAINST ('".'"%s"'."' IN BOOLEAN MODE) ORDER BY `created` DESC LIMIT 1",
+                                                               besc(protect_sprintf($datarray['title'])));
+                                                       if(count($r))
+                                                               $datarray['parent-uri'] = $r[0]['parent-uri'];
+                                               }
+
+                                               if(! x($datarray,'parent-uri'))
+                                                       $datarray['parent-uri'] = $datarray['uri'];
+
+
                                                $r = email_get_msg($mbox,$msg_uid, $reply);
                                                if(! $r) {
                                                        logger("Mail: can't fetch msg ".$msg_uid." for ".$mailconf[0]['user']);