+ 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);
+ }