+ $ismail = false;
+
+ $rawmail = $feed->get_feed_tags( NAMESPACE_DFRN, 'mail' );
+ if(isset($rawmail[0]['child'][NAMESPACE_DFRN])) {
+
+ logger('dfrn_notify: private message received');
+
+ $ismail = true;
+ $base = $rawmail[0]['child'][NAMESPACE_DFRN];
+
+ $msg = array();
+ $msg['uid'] = $importer['importer_uid'];
+ $msg['from-name'] = notags(unxmlify($base['sender'][0]['child'][NAMESPACE_DFRN]['name'][0]['data']));
+ $msg['from-photo'] = notags(unxmlify($base['sender'][0]['child'][NAMESPACE_DFRN]['avatar'][0]['data']));
+ $msg['from-url'] = notags(unxmlify($base['sender'][0]['child'][NAMESPACE_DFRN]['uri'][0]['data']));
+ $msg['contact-id'] = $importer['id'];
+ $msg['title'] = notags(unxmlify($base['subject'][0]['data']));
+ $msg['body'] = escape_tags(unxmlify($base['content'][0]['data']));
+ $msg['seen'] = 0;
+ $msg['replied'] = 0;
+ $msg['uri'] = notags(unxmlify($base['id'][0]['data']));
+ $msg['parent-uri'] = notags(unxmlify($base['in-reply-to'][0]['data']));
+ $msg['created'] = datetime_convert(notags(unxmlify('UTC','UTC',$base['sentdate'][0]['data'])));
+
+ dbesc_array($msg);
+
+ $r = dbq("INSERT INTO `mail` (`" . implode("`, `", array_keys($msg))
+ . "`) VALUES ('" . implode("', '", array_values($msg)) . "')" );
+
+ // send email notification if requested.
+
+ require_once('bbcode.php');
+ if($importer['notify-flags'] & NOTIFY_MAIL) {
+
+ $body = html_entity_decode(strip_tags(bbcode(stripslashes($msg['body']))),ENT_QUOTES,'UTF-8');
+
+ if(function_exists('quoted_printable_encode'))
+ $body = quoted_printable_encode($body);
+ else
+ $body = qp($body);
+
+ $tpl = load_view_file('view/mail_received_eml.tpl');
+ $email_tpl = replace_macros($tpl, array(
+ '$sitename' => $a->config['sitename'],
+ '$siteurl' => $a->get_baseurl(),
+ '$username' => $importer['username'],
+ '$email' => $importer['email'],
+ '$from' => $msg['from-name'],
+ '$title' => stripslashes($msg['title']),
+ '$body' => $body
+ ));
+
+ $res = mail($importer['email'], t('New mail received at ') . $a->config['sitename'],
+ $email_tpl, 'From: ' . t('Administrator') . '@' . $a->get_hostname() . "\r\n"
+ . 'MIME-Version: 1.0' . "\r\n"
+ . 'Content-type: text/plain; charset=UTF-8' . "\r\n"
+ . 'Content-transfer-encoding: quoted-printable' . "\r\n"
+ );
+ }
+ xml_status(0);
+ // NOTREACHED
+ }
+
+ logger('dfrn_notify: feed item count = ' . $feed->get_item_quantity());
+