X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fonepoll.php;h=9fbef168c6fa4d594f1fc875ce430794c616b959;hb=7de5c7ebe1fba7757f06762d26dae478c9de5389;hp=a64922aa323e808576df96416335eaec910622ca;hpb=8a4e3cc3701c3278e35d917de526fd8b032709ab;p=friendica.git diff --git a/include/onepoll.php b/include/onepoll.php index a64922aa32..9fbef168c6 100644 --- a/include/onepoll.php +++ b/include/onepoll.php @@ -36,11 +36,6 @@ function onepoll_run($argv, $argc){ logger('onepoll: start'); - $abandon_days = intval(get_config('system','account_abandon_days')); - if($abandon_days < 1) - $abandon_days = 0; - - $manual_id = 0; $generation = 0; $hub_update = false; @@ -54,9 +49,7 @@ function onepoll_run($argv, $argc){ logger('onepoll: no contact'); return; } - - if(was_recently_delayed($contact_id)) - return; + $d = datetime_convert(); @@ -64,11 +57,6 @@ function onepoll_run($argv, $argc){ // and which have a polling address and ignore Diaspora since // we are unable to match those posts with a Diaspora GUID and prevent duplicates. - $abandon_sql = (($abandon_days) - ? sprintf(" AND `user`.`login_date` > UTC_TIMESTAMP() - INTERVAL %d DAY ", intval($abandon_days)) - : '' - ); - $contacts = q("SELECT `contact`.* FROM `contact` WHERE ( `rel` = %d OR `rel` = %d ) AND `poll` != '' AND NOT `network` IN ( '%s', '%s' ) @@ -88,14 +76,13 @@ function onepoll_run($argv, $argc){ $contact = $contacts[0]; - $xml = false; $t = $contact['last-update']; if($contact['subhub']) { - $interval = get_config('system','pushpoll_frequency'); - $contact['priority'] = (($interval !== false) ? intval($interval) : 3); + $poll_interval = get_config('system','pushpoll_frequency'); + $contact['priority'] = (($poll_interval !== false) ? intval($poll_interval) : 3); $hub_update = false; if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 day")) @@ -139,15 +126,18 @@ function onepoll_run($argv, $argc){ . '&perm=' . $perm ; $handshake_xml = fetch_url($url); + $html_code = $a->get_curl_code(); logger('onepoll: handshake with url ' . $url . ' returns xml: ' . $handshake_xml, LOGGER_DATA); - if(! $handshake_xml) { + if((! strlen($handshake_xml)) || ($html_code >= 400) || (! $html_code)) { logger("poller: $url appears to be dead - marking for death "); + // dead connection - might be a transient event, or this might // mean the software was uninstalled or the domain expired. // Will keep trying for one month. + mark_for_death($contact); // set the last-update so we don't keep polling @@ -161,6 +151,9 @@ function onepoll_run($argv, $argc){ if(! strstr($handshake_xml,' $meta) { logger("Mail: Parsing mail ".$msg_uid, LOGGER_DATA); $datarray = array(); - $meta = email_msg_meta($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. +// $meta = email_msg_meta($mbox,$msg_uid); +// $headers = email_msg_headers($mbox,$msg_uid); - $raw_refs = ((x($headers,'references')) ? str_replace("\t",'',$headers['references']) : ''); $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? $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1", intval($importer_uid), @@ -335,34 +314,63 @@ function onepoll_run($argv, $argc){ ); if(count($r)) { -// logger("Mail: Seen before ".$msg_uid); + logger("Mail: Seen before ".$msg_uid." for ".$mailconf[0]['user'],LOGGER_DEBUG); if($meta->deleted && ! $r[0]['deleted']) { q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `id` = %d LIMIT 1", dbesc(datetime_convert()), intval($r[0]['id']) ); } - switch ($mailconf[0]['action']) { + /*switch ($mailconf[0]['action']) { case 0: + logger("Mail: Seen before ".$msg_uid." for ".$mailconf[0]['user'].". Doing nothing.", LOGGER_DEBUG); break; case 1: - logger("Mail: Deleting ".$msg_uid); + logger("Mail: Deleting ".$msg_uid." for ".$mailconf[0]['user']); imap_delete($mbox, $msg_uid, FT_UID); break; case 2: - logger("Mail: Mark as seen ".$msg_uid); + logger("Mail: Mark as seen ".$msg_uid." for ".$mailconf[0]['user']); imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID); break; case 3: - logger("Mail: Moving ".$msg_uid." to ".$mailconf[0]['movetofolder']); + logger("Mail: Moving ".$msg_uid." to ".$mailconf[0]['movetofolder']." for ".$mailconf[0]['user']); imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID); if ($mailconf[0]['movetofolder'] != "") imap_mail_move($mbox, $msg_uid, $mailconf[0]['movetofolder'], FT_UID); break; - } + }*/ 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 $subject = imap_mime_header_decode($meta->subject); $datarray['title'] = ""; @@ -384,12 +392,12 @@ function onepoll_run($argv, $argc){ $r = email_get_msg($mbox,$msg_uid, $reply); if(! $r) { - logger("Mail: can't fetch msg ".$msg_uid); + logger("Mail: can't fetch msg ".$msg_uid." for ".$mailconf[0]['user']); continue; } $datarray['body'] = escape_tags($r['body']); - logger("Mail: Importing ".$msg_uid); + 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 @@ -428,17 +436,18 @@ function onepoll_run($argv, $argc){ ); switch ($mailconf[0]['action']) { case 0: + logger("Mail: Seen before ".$msg_uid." for ".$mailconf[0]['user'].". Doing nothing.", LOGGER_DEBUG); break; case 1: - logger("Mail: Deleting ".$msg_uid); + logger("Mail: Deleting ".$msg_uid." for ".$mailconf[0]['user']); imap_delete($mbox, $msg_uid, FT_UID); break; case 2: - logger("Mail: Mark as seen ".$msg_uid); + logger("Mail: Mark as seen ".$msg_uid." for ".$mailconf[0]['user']); imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID); break; case 3: - logger("Mail: Moving ".$msg_uid." to ".$mailconf[0]['movetofolder']); + logger("Mail: Moving ".$msg_uid." to ".$mailconf[0]['movetofolder']." for ".$mailconf[0]['user']); imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID); if ($mailconf[0]['movetofolder'] != "") imap_mail_move($mbox, $msg_uid, $mailconf[0]['movetofolder'], FT_UID); @@ -456,7 +465,7 @@ function onepoll_run($argv, $argc){ if($xml) { logger('poller: received xml : ' . $xml, LOGGER_DATA); - if((! strstr($xml,'