]> git.mxchange.org Git - friendica.git/commitdiff
Bugfix for better mail import
authorMichael <heluecht@pirati.ca>
Sat, 23 Sep 2017 22:53:44 +0000 (22:53 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 23 Sep 2017 22:53:44 +0000 (22:53 +0000)
include/Contact.php
include/email.php
include/onepoll.php
src/Network/Probe.php

index a4477c8cb355b82b710530b917ca3c5a209e6ff5..62122de6ce85f078090d29e66af2146456c3e176 100644 (file)
@@ -584,10 +584,10 @@ function get_contact($url, $uid = 0, $no_update = false) {
                return 0;
        }
 
-       $data = Probe::uri($url);
+       $data = Probe::uri($url, "", $uid);
 
        // Last try in gcontact for unsupported networks
-       if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA, NETWORK_PUMPIO))) {
+       if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA, NETWORK_PUMPIO, NETWORK_MAIL))) {
                if ($uid != 0) {
                        return 0;
                }
index 78e98a830c3dec87e1c2d9e5fc81dd2b59da11cd..b3bd52a6682e9649a0fbd2cc92a12e593b85a33c 100644 (file)
@@ -18,22 +18,27 @@ function email_poll($mbox,$email_addr) {
                return array();
 
        $search1 = @imap_search($mbox,'FROM "' . $email_addr . '"', SE_UID);
-       if (! $search1)
+       if (!$search1) {
                $search1 = array();
+       } else {
+               logger("Found mails from ".$email_addr, LOGGER_DEBUG);
+       }
 
        $search2 = @imap_search($mbox,'TO "' . $email_addr . '"', SE_UID);
-       if (! $search2)
+       if (!$search2) {
                $search2 = array();
+       } else {
+               logger("Found mails to ".$email_addr, LOGGER_DEBUG);
+       }
 
        $search3 = @imap_search($mbox,'CC "' . $email_addr . '"', SE_UID);
-       if (! $search3)
+       if (!$search3) {
                $search3 = array();
+       } else {
+               logger("Found mails cc ".$email_addr, LOGGER_DEBUG);
+       }
 
-       $search4 = @imap_search($mbox,'BCC "' . $email_addr . '"', SE_UID);
-       if (! $search4)
-               $search4 = array();
-
-       $res = array_unique(array_merge($search1,$search2,$search3,$search4));
+       $res = array_unique(array_merge($search1, $search2, $search3));
 
        return $res;
 }
index 28afca28a5ab3a0e21c40497eb986c0ba5068a2a..61de852be9d45de4c13910dc3f600c8cdb9b4ca6 100644 (file)
@@ -328,7 +328,7 @@ function onepoll_run(&$argv, &$argc){
                unlink($cookiejar);
        } elseif ($contact['network'] === NETWORK_MAIL || $contact['network'] === NETWORK_MAIL2) {
 
-               logger("Mail: Fetching", LOGGER_DEBUG);
+               logger("Mail: Fetching for ".$contact['addr'], LOGGER_DEBUG);
 
                $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
                if ($mail_disabled)
@@ -363,10 +363,10 @@ function onepoll_run(&$argv, &$argc){
                }
                if ($mbox) {
 
-                       $msgs = email_poll($mbox,$contact['addr']);
+                       $msgs = email_poll($mbox, $contact['addr']);
 
                        if (count($msgs)) {
-                               logger("Mail: Parsing ".count($msgs)." mails for ".$mailconf[0]['user'], LOGGER_DEBUG);
+                               logger("Mail: Parsing ".count($msgs)." mails from ".$contact['addr']." for ".$mailconf[0]['user'], LOGGER_DEBUG);
 
                                $metas = email_msg_meta($mbox,implode(',',$msgs));
                                if (count($metas) != count($msgs)) {
index 431ff5bf75be3ae9dd4957a395721333781d1801..d27ce18512847eedc337c6e18b04da1b241f4084 100644 (file)
@@ -306,7 +306,7 @@ class Probe {
         *
         * @return array uri data
         */
-       public static function uri($uri, $network = "", $uid = 0, $cache = true) {
+       public static function uri($uri, $network = "", $uid = -1, $cache = true) {
 
                if ($cache) {
                        $result = Cache::get("probe_url:".$network.":".$uri);
@@ -315,7 +315,7 @@ class Probe {
                        }
                }
 
-               if ($uid == 0) {
+               if ($uid == -1) {
                        $uid = local_user();
                }
 
@@ -1483,25 +1483,27 @@ class Probe {
                        return false;
                }
 
-               $x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1", intval($uid));
+               if ($uid != 0) {
+                       $x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1", intval($uid));
 
-               $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval($uid));
+                       $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval($uid));
 
-               if (dbm::is_result($x) && dbm::is_result($r)) {
-                       $mailbox = construct_mailbox_name($r[0]);
-                       $password = '';
-                       openssl_private_decrypt(hex2bin($r[0]['pass']), $password, $x[0]['prvkey']);
-                       $mbox = email_connect($mailbox, $r[0]['user'], $password);
-                       if (!mbox) {
-                               return false;
+                       if (dbm::is_result($x) && dbm::is_result($r)) {
+                               $mailbox = construct_mailbox_name($r[0]);
+                               $password = '';
+                               openssl_private_decrypt(hex2bin($r[0]['pass']), $password, $x[0]['prvkey']);
+                               $mbox = email_connect($mailbox, $r[0]['user'], $password);
+                               if (!mbox) {
+                                       return false;
+                               }
                        }
-               }
 
-               $msgs = email_poll($mbox, $uri);
-               logger('searching '.$uri.', '.count($msgs).' messages found.', LOGGER_DEBUG);
+                       $msgs = email_poll($mbox, $uri);
+                       logger('searching '.$uri.', '.count($msgs).' messages found.', LOGGER_DEBUG);
 
-               if (!count($msgs)) {
-                       return false;
+                       if (!count($msgs)) {
+                               return false;
+                       }
                }
 
                $phost = substr($uri, strpos($uri, '@') + 1);
@@ -1512,7 +1514,7 @@ class Probe {
                $data["name"]    = substr($uri, 0, strpos($uri, '@'));
                $data["nick"]    = $data["name"];
                $data["photo"]   = avatar_img($uri);
-               $data["url"]     = 'http://'.$phost."/".$data["nick"];
+               $data["url"]     = 'mailto:'.$uri;
                $data["notify"]  = 'smtp '.random_string();
                $data["poll"]    = 'email '.random_string();
 
@@ -1542,7 +1544,9 @@ class Probe {
                                }
                        }
                }
-               imap_close($mbox);
+               if (!empty($mbox)) {
+                       imap_close($mbox);
+               }
 
                return $data;
        }