X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fonepoll.php;h=9fbef168c6fa4d594f1fc875ce430794c616b959;hb=7de5c7ebe1fba7757f06762d26dae478c9de5389;hp=722ebe846b56e4496bce873e9f9e0d69651100aa;hpb=9413900a9f9cb3c455ee4f0300224dec3a4a9f75;p=friendica.git diff --git a/include/onepoll.php b/include/onepoll.php index 722ebe846b..9fbef168c6 100644 --- a/include/onepoll.php +++ b/include/onepoll.php @@ -25,6 +25,7 @@ function onepoll_run($argv, $argc){ require_once('include/email.php'); require_once('include/socgraph.php'); require_once('include/pidfile.php'); + require_once('include/queue_fn.php'); load_config('config'); load_config('system'); @@ -35,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; @@ -53,6 +49,7 @@ function onepoll_run($argv, $argc){ logger('onepoll: no contact'); return; } + $d = datetime_convert(); @@ -60,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' ) @@ -84,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")) @@ -135,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 @@ -152,16 +146,19 @@ function onepoll_run($argv, $argc){ intval($contact['id']) ); - continue; + return; } if(! strstr($handshake_xml,'status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id))) - continue; + return; if(((float) $res->dfrn_version > 2.21) && ($contact['poco'] == '')) { q("update contact set poco = '%s' where id = %d limit 1", @@ -221,7 +218,7 @@ function onepoll_run($argv, $argc){ if($final_dfrn_id != $orig_id) { logger('poller: ID did not decode: ' . $contact['id'] . ' orig: ' . $orig_id . ' final: ' . $final_dfrn_id); // did not decode properly - cannot trust this site - continue; + return; } $postvars['dfrn_id'] = $idtosend; @@ -251,7 +248,7 @@ function onepoll_run($argv, $argc){ // Are we allowed to import from this person? if($contact['rel'] == CONTACT_IS_FOLLOWER || $contact['blocked'] || $contact['readonly']) - continue; + return; $xml = fetch_url($contact['poll']); } @@ -261,7 +258,7 @@ function onepoll_run($argv, $argc){ $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1); if($mail_disabled) - continue; + return; logger("onepoll: Mail: Enabled", LOGGER_DEBUG); @@ -278,7 +275,7 @@ function onepoll_run($argv, $argc){ openssl_private_decrypt(hex2bin($mailconf[0]['pass']),$password,$x[0]['prvkey']); $mbox = email_connect($mailbox,$mailconf[0]['user'],$password); unset($password); - logger("Mail: Connect"); + logger("Mail: Connect to " . $mailconf[0]['user']); if($mbox) { q("UPDATE `mailacct` SET `last_check` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1", dbesc(datetime_convert()), @@ -292,38 +289,24 @@ function onepoll_run($argv, $argc){ $msgs = email_poll($mbox,$contact['addr']); if(count($msgs)) { - logger("Mail: Parsing ".count($msgs)." mails.", 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)); + if(count($metas) != count($msgs)) { + logger("onepoll: for " . $mailconf[0]['user'] . " there are ". count($msgs) . " messages but received " . count($metas) . " metas", LOGGER_DEBUG); + break; + } + $msgs = array_combine($msgs, $metas); + + foreach($msgs as $msg_uid => $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), @@ -331,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'] = ""; @@ -380,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 @@ -424,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); @@ -452,13 +465,13 @@ function onepoll_run($argv, $argc){ if($xml) { logger('poller: received xml : ' . $xml, LOGGER_DATA); - if(! strstr($xml,'