Merge pull request #495 from fermionic/email-optimization
send less messages to server; remove delete option
This commit is contained in:
commit
e60c729b51
4 changed files with 52 additions and 34 deletions
|
@ -458,10 +458,10 @@ function probe_url($url, $mode = PROBE_NORMAL) {
|
||||||
$poll = 'email ' . random_string();
|
$poll = 'email ' . random_string();
|
||||||
$priority = 0;
|
$priority = 0;
|
||||||
$x = email_msg_meta($mbox,$msgs[0]);
|
$x = email_msg_meta($mbox,$msgs[0]);
|
||||||
if(stristr($x->from,$orig_url))
|
if(stristr($x[0]->from,$orig_url))
|
||||||
$adr = imap_rfc822_parse_adrlist($x->from,'');
|
$adr = imap_rfc822_parse_adrlist($x[0]->from,'');
|
||||||
elseif(stristr($x->to,$orig_url))
|
elseif(stristr($x[0]->to,$orig_url))
|
||||||
$adr = imap_rfc822_parse_adrlist($x->to,'');
|
$adr = imap_rfc822_parse_adrlist($x[0]->to,'');
|
||||||
if(isset($adr)) {
|
if(isset($adr)) {
|
||||||
foreach($adr as $feadr) {
|
foreach($adr as $feadr) {
|
||||||
if((strcasecmp($feadr->mailbox,$name) == 0)
|
if((strcasecmp($feadr->mailbox,$name) == 0)
|
||||||
|
@ -554,6 +554,13 @@ function probe_url($url, $mode = PROBE_NORMAL) {
|
||||||
logger('probe_url: scrape_vcard: ' . print_r($vcard,true), LOGGER_DATA);
|
logger('probe_url: scrape_vcard: ' . print_r($vcard,true), LOGGER_DATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($diaspora && $addr) {
|
||||||
|
// Diaspora returns the name as the nick. As the nick will never be updated,
|
||||||
|
// let's use the Diaspora nickname (the first part of the handle) as the nick instead
|
||||||
|
$addr_parts = explode('@', $addr);
|
||||||
|
$vcard['nick'] = $addr_parts[0];
|
||||||
|
}
|
||||||
|
|
||||||
if($twitter) {
|
if($twitter) {
|
||||||
logger('twitter: setup');
|
logger('twitter: setup');
|
||||||
$tid = basename($url);
|
$tid = basename($url);
|
||||||
|
|
|
@ -48,8 +48,8 @@ function construct_mailbox_name($mailacct) {
|
||||||
|
|
||||||
|
|
||||||
function email_msg_meta($mbox,$uid) {
|
function email_msg_meta($mbox,$uid) {
|
||||||
$ret = (($mbox && $uid) ? @imap_fetch_overview($mbox,$uid,FT_UID) : array(array()));
|
$ret = (($mbox && $uid) ? @imap_fetch_overview($mbox,$uid,FT_UID) : array(array())); // POSSIBLE CLEANUP --> array(array()) is probably redundant now
|
||||||
return ((count($ret)) ? $ret[0] : array());
|
return ((count($ret)) ? $ret : array());
|
||||||
}
|
}
|
||||||
|
|
||||||
function email_msg_headers($mbox,$uid) {
|
function email_msg_headers($mbox,$uid) {
|
||||||
|
|
|
@ -291,36 +291,17 @@ function onepoll_run($argv, $argc){
|
||||||
if(count($msgs)) {
|
if(count($msgs)) {
|
||||||
logger("Mail: Parsing ".count($msgs)." mails for ".$mailconf[0]['user'], LOGGER_DEBUG);
|
logger("Mail: Parsing ".count($msgs)." mails for ".$mailconf[0]['user'], LOGGER_DEBUG);
|
||||||
|
|
||||||
foreach($msgs as $msg_uid) {
|
$metas = email_msg_meta($mbox,implode(',',$msgs));
|
||||||
|
$msgs = array_combine($msgs, $metas);
|
||||||
|
foreach($msgs as $msg_uid => $meta) {
|
||||||
logger("Mail: Parsing mail ".$msg_uid, LOGGER_DATA);
|
logger("Mail: Parsing mail ".$msg_uid, LOGGER_DATA);
|
||||||
|
|
||||||
$datarray = array();
|
$datarray = array();
|
||||||
$meta = email_msg_meta($mbox,$msg_uid);
|
// $meta = email_msg_meta($mbox,$msg_uid);
|
||||||
$headers = email_msg_headers($mbox,$msg_uid);
|
// $headers = email_msg_headers($mbox,$msg_uid);
|
||||||
|
|
||||||
// look for a 'references' header and try and match with a parent item we have locally.
|
|
||||||
|
|
||||||
$raw_refs = ((x($headers,'references')) ? str_replace("\t",'',$headers['references']) : '');
|
|
||||||
$datarray['uri'] = msgid2iri(trim($meta->message_id,'<>'));
|
$datarray['uri'] = msgid2iri(trim($meta->message_id,'<>'));
|
||||||
|
|
||||||
if($raw_refs) {
|
|
||||||
$refs_arr = explode(' ', $raw_refs);
|
|
||||||
if(count($refs_arr)) {
|
|
||||||
for($x = 0; $x < count($refs_arr); $x ++)
|
|
||||||
$refs_arr[$x] = "'" . msgid2iri(str_replace(array('<','>',' '),array('','',''),dbesc($refs_arr[$x]))) . "'";
|
|
||||||
}
|
|
||||||
$qstr = implode(',',$refs_arr);
|
|
||||||
$r = q("SELECT `uri` , `parent-uri` FROM `item` WHERE `uri` IN ( $qstr ) AND `uid` = %d LIMIT 1",
|
|
||||||
intval($importer_uid)
|
|
||||||
);
|
|
||||||
if(count($r))
|
|
||||||
$datarray['parent-uri'] = $r[0]['uri'];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(! x($datarray,'parent-uri'))
|
|
||||||
$datarray['parent-uri'] = $datarray['uri'];
|
|
||||||
|
|
||||||
// Have we seen it before?
|
// Have we seen it before?
|
||||||
$r = q("SELECT * FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1",
|
$r = q("SELECT * FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1",
|
||||||
intval($importer_uid),
|
intval($importer_uid),
|
||||||
|
@ -328,15 +309,16 @@ function onepoll_run($argv, $argc){
|
||||||
);
|
);
|
||||||
|
|
||||||
if(count($r)) {
|
if(count($r)) {
|
||||||
// logger("Mail: Seen before ".$msg_uid);
|
logger("Mail: Seen before ".$msg_uid." for ".$mailconf[0]['user']);
|
||||||
if($meta->deleted && ! $r[0]['deleted']) {
|
if($meta->deleted && ! $r[0]['deleted']) {
|
||||||
q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `id` = %d LIMIT 1",
|
q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `id` = %d LIMIT 1",
|
||||||
dbesc(datetime_convert()),
|
dbesc(datetime_convert()),
|
||||||
intval($r[0]['id'])
|
intval($r[0]['id'])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
switch ($mailconf[0]['action']) {
|
/*switch ($mailconf[0]['action']) {
|
||||||
case 0:
|
case 0:
|
||||||
|
logger("Mail: Seen before ".$msg_uid." for ".$mailconf[0]['user'].". Doing nothing.", LOGGER_DEBUG);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
logger("Mail: Deleting ".$msg_uid." for ".$mailconf[0]['user']);
|
logger("Mail: Deleting ".$msg_uid." for ".$mailconf[0]['user']);
|
||||||
|
@ -352,10 +334,38 @@ function onepoll_run($argv, $argc){
|
||||||
if ($mailconf[0]['movetofolder'] != "")
|
if ($mailconf[0]['movetofolder'] != "")
|
||||||
imap_mail_move($mbox, $msg_uid, $mailconf[0]['movetofolder'], FT_UID);
|
imap_mail_move($mbox, $msg_uid, $mailconf[0]['movetofolder'], FT_UID);
|
||||||
break;
|
break;
|
||||||
}
|
}*/
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// look for a 'references' or an 'in-reply-to' header and try to match with a parent item we have locally.
|
||||||
|
|
||||||
|
// $raw_refs = ((x($headers,'references')) ? str_replace("\t",'',$headers['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 = trim($raw_refs); // Don't allow a blank reference in $refs_arr
|
||||||
|
|
||||||
|
if($raw_refs) {
|
||||||
|
$refs_arr = explode(' ', $raw_refs);
|
||||||
|
if(count($refs_arr)) {
|
||||||
|
for($x = 0; $x < count($refs_arr); $x ++)
|
||||||
|
$refs_arr[$x] = "'" . msgid2iri(str_replace(array('<','>',' '),array('','',''),dbesc($refs_arr[$x]))) . "'";
|
||||||
|
}
|
||||||
|
$qstr = implode(',',$refs_arr);
|
||||||
|
$r = q("SELECT `uri` , `parent-uri` FROM `item` WHERE `uri` IN ( $qstr ) AND `uid` = %d LIMIT 1",
|
||||||
|
intval($importer_uid)
|
||||||
|
);
|
||||||
|
if(count($r))
|
||||||
|
$datarray['parent-uri'] = $r[0]['parent-uri']; // Set the parent as the top-level item
|
||||||
|
// $datarray['parent-uri'] = $r[0]['uri'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(! x($datarray,'parent-uri'))
|
||||||
|
$datarray['parent-uri'] = $datarray['uri'];
|
||||||
|
|
||||||
// Decoding the header
|
// Decoding the header
|
||||||
$subject = imap_mime_header_decode($meta->subject);
|
$subject = imap_mime_header_decode($meta->subject);
|
||||||
$datarray['title'] = "";
|
$datarray['title'] = "";
|
||||||
|
@ -421,6 +431,7 @@ function onepoll_run($argv, $argc){
|
||||||
);
|
);
|
||||||
switch ($mailconf[0]['action']) {
|
switch ($mailconf[0]['action']) {
|
||||||
case 0:
|
case 0:
|
||||||
|
logger("Mail: Seen before ".$msg_uid." for ".$mailconf[0]['user'].". Doing nothing.", LOGGER_DEBUG);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
logger("Mail: Deleting ".$msg_uid." for ".$mailconf[0]['user']);
|
logger("Mail: Deleting ".$msg_uid." for ".$mailconf[0]['user']);
|
||||||
|
|
|
@ -692,7 +692,7 @@ function settings_content(&$a) {
|
||||||
'$mail_pass' => array('mail_pass', t('Email password:'), '', ''),
|
'$mail_pass' => array('mail_pass', t('Email password:'), '', ''),
|
||||||
'$mail_replyto' => array('mail_replyto', t('Reply-to address:'), '', 'Optional'),
|
'$mail_replyto' => array('mail_replyto', t('Reply-to address:'), '', 'Optional'),
|
||||||
'$mail_pubmail' => array('mail_pubmail', t('Send public posts to all email contacts:'), $mail_pubmail, ''),
|
'$mail_pubmail' => array('mail_pubmail', t('Send public posts to all email contacts:'), $mail_pubmail, ''),
|
||||||
'$mail_action' => array('mail_action', t('Action after import:'), $mail_action, '', array(0=>t('None'), 1=>t('Delete'), 2=>t('Mark as seen'), 3=>t('Move to folder'))),
|
'$mail_action' => array('mail_action', t('Action after import:'), $mail_action, '', array(0=>t('None'), /*1=>t('Delete'),*/ 2=>t('Mark as seen'), 3=>t('Move to folder'))),
|
||||||
'$mail_movetofolder' => array('mail_movetofolder', t('Move to folder:'), $mail_movetofolder, ''),
|
'$mail_movetofolder' => array('mail_movetofolder', t('Move to folder:'), $mail_movetofolder, ''),
|
||||||
'$submit' => t('Submit'),
|
'$submit' => t('Submit'),
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue