Merge pull request #3725 from annando/mail-bugfix

Bugfix for better mail import
This commit is contained in:
Tobias Diekershoff 2017-09-24 07:22:13 +02:00 committed by GitHub
commit c72d85333b
4 changed files with 65 additions and 66 deletions

View file

@ -584,10 +584,10 @@ function get_contact($url, $uid = 0, $no_update = false) {
return 0; return 0;
} }
$data = Probe::uri($url); $data = Probe::uri($url, "", $uid);
// Last try in gcontact for unsupported networks // 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) { if ($uid != 0) {
return 0; return 0;
} }

View file

@ -18,22 +18,27 @@ function email_poll($mbox,$email_addr) {
return array(); return array();
$search1 = @imap_search($mbox,'FROM "' . $email_addr . '"', SE_UID); $search1 = @imap_search($mbox,'FROM "' . $email_addr . '"', SE_UID);
if (! $search1) if (!$search1) {
$search1 = array(); $search1 = array();
} else {
logger("Found mails from ".$email_addr, LOGGER_DEBUG);
}
$search2 = @imap_search($mbox,'TO "' . $email_addr . '"', SE_UID); $search2 = @imap_search($mbox,'TO "' . $email_addr . '"', SE_UID);
if (! $search2) if (!$search2) {
$search2 = array(); $search2 = array();
} else {
logger("Found mails to ".$email_addr, LOGGER_DEBUG);
}
$search3 = @imap_search($mbox,'CC "' . $email_addr . '"', SE_UID); $search3 = @imap_search($mbox,'CC "' . $email_addr . '"', SE_UID);
if (! $search3) if (!$search3) {
$search3 = array(); $search3 = array();
} else {
logger("Found mails cc ".$email_addr, LOGGER_DEBUG);
}
$search4 = @imap_search($mbox,'BCC "' . $email_addr . '"', SE_UID); $res = array_unique(array_merge($search1, $search2, $search3));
if (! $search4)
$search4 = array();
$res = array_unique(array_merge($search1,$search2,$search3,$search4));
return $res; return $res;
} }

View file

@ -328,7 +328,7 @@ function onepoll_run(&$argv, &$argc){
unlink($cookiejar); unlink($cookiejar);
} elseif ($contact['network'] === NETWORK_MAIL || $contact['network'] === NETWORK_MAIL2) { } 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); $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
if ($mail_disabled) if ($mail_disabled)
@ -366,7 +366,7 @@ function onepoll_run(&$argv, &$argc){
$msgs = email_poll($mbox, $contact['addr']); $msgs = email_poll($mbox, $contact['addr']);
if (count($msgs)) { 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)); $metas = email_msg_meta($mbox,implode(',',$msgs));
if (count($metas) != count($msgs)) { if (count($metas) != count($msgs)) {
@ -498,10 +498,8 @@ function onepoll_run(&$argv, &$argc){
logger("Mail: Importing ".$msg_uid." for ".$mailconf[0]['user']); logger("Mail: Importing ".$msg_uid." for ".$mailconf[0]['user']);
// some mailing lists have the original author as 'from' - add this sender info to msg body.
/// @TODO Adding a gravatar for the original author would be cool /// @TODO Adding a gravatar for the original author would be cool
if (! stristr($meta->from,$contact['addr'])) {
$from = imap_mime_header_decode($meta->from); $from = imap_mime_header_decode($meta->from);
$fromdecoded = ""; $fromdecoded = "";
foreach ($from as $frompart) { foreach ($from as $frompart) {
@ -522,8 +520,6 @@ function onepoll_run(&$argv, &$argc){
$fromname = $frommail; $fromname = $frommail;
} }
//$datarray['body'] = "[b]".t('From: ') . escape_tags($fromdecoded) . "[/b]\n\n" . $datarray['body'];
$datarray['author-name'] = $fromname; $datarray['author-name'] = $fromname;
$datarray['author-link'] = "mailto:".$frommail; $datarray['author-link'] = "mailto:".$frommail;
$datarray['author-avatar'] = $contact['photo']; $datarray['author-avatar'] = $contact['photo'];
@ -532,12 +528,6 @@ function onepoll_run(&$argv, &$argc){
$datarray['owner-link'] = "mailto:".$contact['addr']; $datarray['owner-link'] = "mailto:".$contact['addr'];
$datarray['owner-avatar'] = $contact['photo']; $datarray['owner-avatar'] = $contact['photo'];
} else {
$datarray['author-name'] = $contact['name'];
$datarray['author-link'] = 'mailbox';
$datarray['author-avatar'] = $contact['photo'];
}
$datarray['uid'] = $importer_uid; $datarray['uid'] = $importer_uid;
$datarray['contact-id'] = $contact['id']; $datarray['contact-id'] = $contact['id'];
if ($datarray['parent-uri'] === $datarray['uri']) if ($datarray['parent-uri'] === $datarray['uri'])

View file

@ -306,7 +306,7 @@ class Probe {
* *
* @return array uri data * @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) { if ($cache) {
$result = Cache::get("probe_url:".$network.":".$uri); $result = Cache::get("probe_url:".$network.":".$uri);
@ -315,7 +315,7 @@ class Probe {
} }
} }
if ($uid == 0) { if ($uid == -1) {
$uid = local_user(); $uid = local_user();
} }
@ -1483,6 +1483,7 @@ class Probe {
return false; return false;
} }
if ($uid != 0) {
$x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1", intval($uid)); $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));
@ -1503,6 +1504,7 @@ class Probe {
if (!count($msgs)) { if (!count($msgs)) {
return false; return false;
} }
}
$phost = substr($uri, strpos($uri, '@') + 1); $phost = substr($uri, strpos($uri, '@') + 1);
@ -1512,7 +1514,7 @@ class Probe {
$data["name"] = substr($uri, 0, strpos($uri, '@')); $data["name"] = substr($uri, 0, strpos($uri, '@'));
$data["nick"] = $data["name"]; $data["nick"] = $data["name"];
$data["photo"] = avatar_img($uri); $data["photo"] = avatar_img($uri);
$data["url"] = 'http://'.$phost."/".$data["nick"]; $data["url"] = 'mailto:'.$uri;
$data["notify"] = 'smtp '.random_string(); $data["notify"] = 'smtp '.random_string();
$data["poll"] = 'email '.random_string(); $data["poll"] = 'email '.random_string();
@ -1542,7 +1544,9 @@ class Probe {
} }
} }
} }
if (!empty($mbox)) {
imap_close($mbox); imap_close($mbox);
}
return $data; return $data;
} }