diff --git a/boot.php b/boot.php
index 7b2d72f3c..10f951b6a 100755
--- a/boot.php
+++ b/boot.php
@@ -43,7 +43,7 @@ require_once('include/taxonomy.php');
define ( 'RED_PLATFORM', 'Red Matrix' );
define ( 'RED_VERSION', trim(file_get_contents('version.inc')) . 'R');
define ( 'ZOT_REVISION', 1 );
-define ( 'DB_UPDATE_VERSION', 1059 );
+define ( 'DB_UPDATE_VERSION', 1060 );
define ( 'EOL', '
' . "\r\n" );
define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );
diff --git a/include/items.php b/include/items.php
index ba0867562..10bdcb38f 100755
--- a/include/items.php
+++ b/include/items.php
@@ -840,6 +840,9 @@ function encode_mail($item) {
$x['from'] = encode_item_xchan($item['from']);
$x['to'] = encode_item_xchan($item['to']);
+ if($item['attach'])
+ $x['attach'] = json_decode_plus($item['attach']);
+
$x['flags'] = array();
if($item['mail_flags'] & MAIL_RECALLED) {
@@ -885,6 +888,9 @@ function get_mail_elements($x) {
$arr['mid'] = (($x['message_id']) ? htmlentities($x['message_id'], ENT_COMPAT,'UTF-8',false) : '');
$arr['parent_mid'] = (($x['message_parent']) ? htmlentities($x['message_parent'], ENT_COMPAT,'UTF-8',false) : '');
+ if($x['attach'])
+ $arr['attach'] = activity_sanitise($x['attach']);
+
if(import_author_xchan($x['from']))
$arr['from_xchan'] = base64url_encode(hash('whirlpool',$x['from']['guid'] . $x['from']['guid_sig'], true));
@@ -2202,6 +2208,9 @@ function mail_store($arr) {
if((strpos($arr['body'],'<') !== false) || (strpos($arr['body'],'>') !== false))
$arr['body'] = escape_tags($arr['body']);
+ if(array_key_exists('attach',$arr) && is_array($arr['attach']))
+ $arr['attach'] = json_encode($arr['attach']);
+
$arr['account_id'] = ((x($arr,'account_id')) ? intval($arr['account_id']) : 0);
$arr['mid'] = ((x($arr,'mid')) ? notags(trim($arr['mid'])) : random_string());
$arr['from_xchan'] = ((x($arr,'from_xchan')) ? notags(trim($arr['from_xchan'])) : '');
@@ -2210,6 +2219,7 @@ function mail_store($arr) {
$arr['title'] = ((x($arr,'title')) ? notags(trim($arr['title'])) : '');
$arr['parent_mid'] = ((x($arr,'parent_mid')) ? notags(trim($arr['parent_mid'])) : '');
$arr['body'] = ((x($arr,'body')) ? trim($arr['body']) : '');
+
$arr['mail_flags'] = ((x($arr,'mail_flags')) ? intval($arr['mail_flags']) : 0 );
diff --git a/include/message.php b/include/message.php
index fc0d5f2b3..e54a6cd83 100644
--- a/include/message.php
+++ b/include/message.php
@@ -3,6 +3,7 @@
/* Private Message backend API */
require_once('include/crypto.php');
+require_once('include/attach.php');
// send a private message
@@ -74,14 +75,44 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto='
if(preg_match_all("/\[img\](.*?)\[\/img\]/",$body,$match))
$images = $match[1];
+ $match = false;
+
+ if(preg_match_all("/\[attachment\](.*?)\[\/attachment\]/",$body,$match))
+ $attaches = $match[1];
+
+ $attachments = '';
+
+ if(preg_match_all('/(\[attachment\](.*?)\[\/attachment\])/',$body,$match)) {
+ $attachments = array();
+ foreach($match[2] as $mtch) {
+ $hash = substr($mtch,0,strpos($mtch,','));
+ $rev = intval(substr($mtch,strpos($mtch,',')));
+ $r = attach_by_hash_nodata($hash,$rev);
+ if($r['success']) {
+ $attachments[] = array(
+ 'href' => $a->get_baseurl() . '/attach/' . $r['data']['hash'],
+ 'length' => $r['data']['filesize'],
+ 'type' => $r['data']['filetype'],
+ 'title' => urlencode($r['data']['filename']),
+ 'revision' => $r['data']['revision']
+ );
+ }
+ $body = str_replace($match[1],'',$body);
+ }
+ }
+
+ $jattach = (($attachments) ? json_encode($attachments) : '');
+
$key = get_config('system','pubkey');
if($subject)
$subject = json_encode(aes_encapsulate($subject,$key));
if($body)
$body = json_encode(aes_encapsulate($body,$key));
- $r = q("INSERT INTO mail ( account_id, mail_flags, channel_id, from_xchan, to_xchan, title, body, mid, parent_mid, created )
- VALUES ( %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' )",
+
+
+ $r = q("INSERT INTO mail ( account_id, mail_flags, channel_id, from_xchan, to_xchan, title, body, attach, mid, parent_mid, created )
+ VALUES ( %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )",
intval($channel['channel_account_id']),
intval(MAIL_OBSCURED),
intval($channel['channel_id']),
@@ -89,6 +120,7 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto='
dbesc($recipient),
dbesc($subject),
dbesc($body),
+ dbesc($jattach),
dbesc($mid),
dbesc($replyto),
dbesc(datetime_convert())
@@ -122,6 +154,19 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto='
}
}
+ if($attaches) {
+ foreach($attaches as $attach) {
+ $hash = substr($attach,0,strpos($attach,','));
+ $rev = intval(substr($attach,strpos($attach,',')));
+ attach_store($channel,$observer_hash,$options = 'update', array(
+ 'hash' => $hash,
+ 'revision' => $rev,
+ 'allow_cid' => '<' . $recipient . '>',
+
+ ));
+ }
+ }
+
proc_run('php','include/notifier.php','mail',$post_id);
$ret['success'] = true;
diff --git a/install/database.sql b/install/database.sql
index 0a86b8321..4a519adbb 100644
--- a/install/database.sql
+++ b/install/database.sql
@@ -504,6 +504,7 @@ CREATE TABLE IF NOT EXISTS `mail` (
`channel_id` int(10) unsigned NOT NULL,
`title` text NOT NULL,
`body` mediumtext NOT NULL,
+ `attach` mediumtext NOT NULL DEFAULT '',
`mid` char(255) NOT NULL,
`parent_mid` char(255) NOT NULL,
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
diff --git a/install/update.php b/install/update.php
index c97b5619f..682ee2aea 100644
--- a/install/update.php
+++ b/install/update.php
@@ -1,6 +1,6 @@
page['htmlhead'] .= replace_macros($tpl, array(
'$baseurl' => $a->get_baseurl(true),
'$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
- '$nickname' => $channel['channel_addr'],
+ '$nickname' => $channel['channel_address'],
'$linkurl' => t('Please enter a link URL:')
));
@@ -293,6 +293,7 @@ function message_content(&$a) {
'$select' => $select,
'$parent' => '',
'$upload' => t('Upload photo'),
+ '$attach' => t('Attach file'),
'$insert' => t('Insert web link'),
'$wait' => t('Please wait'),
'$submit' => t('Submit')
@@ -371,10 +372,39 @@ function message_content(&$a) {
foreach($messages as $message) {
-// FIXME
-// $extracted = item_extract_images($message['body']);
-// if($extracted['images'])
-// $message['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $message['contact-id']);
+ $s = $arr = '';
+
+ if($message['attach'])
+ $arr = json_decode_plus($message['attach']);
+ if($arr) {
+ $s .= '