aboutsummaryrefslogtreecommitdiffstats
path: root/include/message.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/message.php')
-rw-r--r--include/message.php128
1 files changed, 84 insertions, 44 deletions
diff --git a/include/message.php b/include/message.php
index 4e8e44adc..3f003e020 100644
--- a/include/message.php
+++ b/include/message.php
@@ -5,10 +5,20 @@
require_once('include/crypto.php');
require_once('include/attach.php');
+
+function mail_prepare_binary($item) {
+
+ return replace_macros(get_markup_template('item_binary.tpl'), [
+ '$download' => t('Download binary/encrypted content'),
+ '$url' => z_root() . '/mail/' . $item['id'] . '/download'
+ ]);
+}
+
+
// send a private message
-function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $replyto = '', $expires = NULL_DATE) {
+function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $replyto = '', $expires = NULL_DATE, $mimetype = 'text/bbcode', $raw = false) {
$ret = array('success' => false);
$is_reply = false;
@@ -94,38 +104,9 @@ function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $rep
// create a new conversation
- $conv_guid = random_string();
-
- $recip = q("select * from xchan where xchan_hash = '%s' limit 1",
- dbesc($recipient)
- );
- if($recip)
- $recip_handle = $recip[0]['xchan_addr'];
-
- $sender_handle = channel_reddress($channel);
-
- $handles = $recip_handle . ';' . $sender_handle;
-
- if($subject)
- $nsubject = str_rot47(base64url_encode($subject));
-
- $r = q("insert into conv (uid,guid,creator,created,updated,subject,recips) values(%d, '%s', '%s', '%s', '%s', '%s', '%s') ",
- intval(local_channel()),
- dbesc($conv_guid),
- dbesc($sender_handle),
- dbesc(datetime_convert()),
- dbesc(datetime_convert()),
- dbesc($nsubject),
- dbesc($handles)
- );
-
- $r = q("select * from conv where guid = '%s' and uid = %d limit 1",
- dbesc($conv_guid),
- intval(local_channel())
- );
- if($r) {
- $retconv = $r[0];
- $retconv['subject'] = base64url_decode(str_rot47($retconv['subject']));
+ $retconv = create_conversation($channel,$recipient,$subject);
+ if($retconv) {
+ $conv_guid = $retconv['guid'];
}
}
@@ -136,7 +117,6 @@ function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $rep
);
if($r) {
$retconv = $r[0];
- $retconv['subject'] = base64url_decode(str_rot47($retconv['subject']));
}
}
@@ -145,6 +125,12 @@ function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $rep
return $ret;
}
+ $c = q("update conv set updated = '%s' where guid = '%s' and uid = %d",
+ dbesc(datetime_convert()),
+ dbesc($conv_guid),
+ intval(local_channel())
+ );
+
// generate a unique message_id
do {
@@ -192,8 +178,8 @@ function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $rep
$sig = ''; // placeholder
$mimetype = ''; //placeholder
- $r = q("INSERT INTO mail ( account_id, conv_guid, mail_obscured, channel_id, from_xchan, to_xchan, mail_mimetype, title, body, sig, attach, mid, parent_mid, created, expires, mail_isreply )
- VALUES ( %d, '%s', %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d )",
+ $r = q("INSERT INTO mail ( account_id, conv_guid, mail_obscured, channel_id, from_xchan, to_xchan, mail_mimetype, title, body, sig, attach, mid, parent_mid, created, expires, mail_isreply, mail_raw )
+ VALUES ( %d, '%s', %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d )",
intval($channel['channel_account_id']),
dbesc($conv_guid),
intval(1),
@@ -209,7 +195,8 @@ function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $rep
dbesc($replyto),
dbesc(datetime_convert()),
dbescdate($expires),
- intval($is_reply)
+ intval($is_reply),
+ intval($raw)
);
// verify the save
@@ -273,6 +260,49 @@ function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $rep
}
+function create_conversation($channel,$recipient,$subject) {
+
+ // create a new conversation
+
+ $conv_guid = random_string();
+
+ $recip = q("select * from xchan where xchan_hash = '%s' limit 1",
+ dbesc($recipient)
+ );
+ if($recip)
+ $recip_handle = $recip[0]['xchan_addr'];
+
+ $sender_handle = channel_reddress($channel);
+
+ $handles = $recip_handle . ';' . $sender_handle;
+
+ if($subject)
+ $nsubject = str_rot47(base64url_encode($subject));
+
+ $r = q("insert into conv (uid,guid,creator,created,updated,subject,recips) values(%d, '%s', '%s', '%s', '%s', '%s', '%s') ",
+ intval($channel['channel_id']),
+ dbesc($conv_guid),
+ dbesc($sender_handle),
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert()),
+ dbesc($nsubject),
+ dbesc($handles)
+ );
+
+ $r = q("select * from conv where guid = '%s' and uid = %d limit 1",
+ dbesc($conv_guid),
+ intval($channel['channel_id'])
+ );
+
+ return $r[0];
+
+}
+
+
+
+
+
+
function private_messages_list($uid, $mailbox = '', $start = 0, $numitems = 0) {
$where = '';
@@ -304,6 +334,8 @@ function private_messages_list($uid, $mailbox = '', $start = 0, $numitems = 0) {
break;
case 'combined':
+ default:
+
$parents = q("SELECT parent_mid FROM mail WHERE mid = parent_mid AND channel_id = %d ORDER BY created DESC",
dbesc($local_channel)
);
@@ -315,15 +347,21 @@ function private_messages_list($uid, $mailbox = '', $start = 0, $numitems = 0) {
}
+ $r = null;
+
if($parents) {
foreach($parents as $parent) {
- $all[] = q("SELECT * FROM mail WHERE parent_mid = '%s' AND channel_id = %d ORDER BY created DESC",
+ $all = q("SELECT * FROM mail WHERE parent_mid = '%s' AND channel_id = %d ORDER BY created DESC limit 1",
dbesc($parent['parent_mid']),
dbesc($local_channel)
);
+
+ if($all) {
+ foreach($all as $single) {
+ $r[] = $single;
+ }
+ }
}
- foreach($all as $single)
- $r[] = $single[0];
}
else {
$r = q($sql);
@@ -441,10 +479,12 @@ function private_messages_drop($channel_id, $messageitem_id, $drop_conversation
intval($channel_id)
);
if($z) {
- q("delete from conv where guid = '%s' and uid = %d",
- dbesc($x[0]['conv_guid']),
- intval($channel_id)
- );
+ if($x[0]['conv_guid']) {
+ q("delete from conv where guid = '%s' and uid = %d",
+ dbesc($x[0]['conv_guid']),
+ intval($channel_id)
+ );
+ }
$m['mail'] = array();
foreach($z as $zz) {
xchan_mail_query($zz);