+ $a = get_app();
+ $myaddr = $owner['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
+
+ $r = q("select * from conv where id = %d and uid = %d limit 1",
+ intval($item['convid']),
+ intval($item['uid'])
+ );
+
+ if(! count($r)) {
+ logger('diaspora_send_mail: conversation not found.');
+ return;
+ }
+ $cnv = $r[0];
+
+ $conv = array(
+ 'guid' => xmlify($cnv['guid']),
+ 'subject' => xmlify($cnv['subject']),
+ 'created_at' => xmlify(datetime_convert('UTC','UTC',$cnv['created'],'Y-m-d H:i:s \U\T\C')),
+ 'diaspora_handle' => xmlify($cnv['creator']),
+ 'participant_handles' => xmlify($cnv['recips'])
+ );
+
+ $body = bb2diaspora($item['body']);
+ $created = datetime_convert('UTC','UTC',$item['created'],'Y-m-d H:i:s \U\T\C');
+
+ $signed_text = $item['guid'] . ';' . $cnv['guid'] . ';' . $body . ';'
+ . $created . ';' . $myaddr . ';' . $cnv['guid'];
+
+ $sig = base64_encode(rsa_sign($signed_text,$owner['uprvkey'],'sha256'));
+
+ $msg = array(
+ 'guid' => xmlify($item['guid']),
+ 'parent_guid' => xmlify($cnv['guid']),
+ 'parent_author_signature' => (($item['reply']) ? null : xmlify($sig)),
+ 'author_signature' => xmlify($sig),
+ 'text' => xmlify($body),
+ 'created_at' => xmlify($created),
+ 'diaspora_handle' => xmlify($myaddr),
+ 'conversation_guid' => xmlify($cnv['guid'])
+ );
+
+ if($item['reply']) {
+ $tpl = get_markup_template('diaspora_message.tpl');
+ $xmsg = replace_macros($tpl, array('$msg' => $msg));
+ }
+ else {
+ $conv['messages'] = array($msg);
+ $tpl = get_markup_template('diaspora_conversation.tpl');
+ $xmsg = replace_macros($tpl, array('$conv' => $conv));
+ }
+
+ logger('diaspora_conversation: ' . print_r($xmsg,true), LOGGER_DATA);
+
+ $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($xmsg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],false)));
+
+ return(diaspora_transmit($owner,$contact,$slap,false));
+
+
+}