- else {
- // Head post of a conversation. Have we seen it? If not, import it.
-
- $item_id = $item->get_id();
- $r = q("SELECT `uid`, `last-child`, `edited` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
- dbesc($item_id),
- intval($importer['uid'])
- );
- if(count($r)) {
- $allow = $item->get_item_tags('http://purl.org/macgirvin/dfrn/1.0','comment-allow');
- if($allow && $allow[0]['data'] != $r[0]['last-child']) {
- $r = q("UPDATE `item` SET `last-child` = %d WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
- intval($allow[0]['data']),
- dbesc($item_id),
- intval($importer['uid'])
- );
+ $xml = fetch_url($contact['poll']);
+ }
+ elseif($contact['network'] === NETWORK_MAIL) {
+ if(! $mbox) {
+ $x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1",
+ intval($importer_uid)
+ );
+ $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
+ intval($importer_uid)
+ );
+ if(count($x) && count($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);
+ unset($password);
+ }
+ }
+ if($mbox) {
+ $msgs = email_poll($mbox,$contact['addr']);
+ if(count($msgs)) {
+ foreach($msgs as $msg_uid) {
+ $datarray = array();
+ $meta = email_msg_meta($mbox,$msg_uid);
+ $datarray['uri'] = trim($meta->message_id,'<>');
+//FIXME
+ $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),
+ dbesc($datarray['uri'])
+ );
+ if(count($r)) {
+ if($meta->deleted && ! $r[0]['deleted']) {
+ q("UPDATE `item` SET `deleted` = `, `changed` = '%s' WHERE `id` = %d LIMIT 1",
+ dbesc(datetime_convert()),
+ intval($r[0]['id'])
+ );
+ }
+ continue;
+ }
+ $datarray['title'] = notags(trim($meta->subject));
+ $datarray['created'] = datetime_convert('UTC','UTC',$meta->date);
+
+ $r = email_get_msg($mbox,$msg_uid);
+ if(! $r)
+ continue;
+ $datarray['body'] = escape_tags($r['body']);
+ $datarray['uid'] = $importer_uid;
+ $datarray['contact-id'] = $contact['id'];
+ $datarray['private'] = 1;
+ $datarray['author-name'] = $contact['name'];
+ $datarray['author-link'] = 'mailbox';
+ $datarray['author-avatar'] = $contact['photo'];
+
+ item_store($datarray);
+ }