allow private mail sender to set an expiration on their messages. Once expired the message is destroyed at both ends (subject to the granularity of the polling interval) and is gone. Officially it takes some form of language independent string like 2013/11/22, but English speakers can use anything that strtotime() understands, like "+30 minutes" or "next Tuesday".

This commit is contained in:
friendica 2013-11-06 18:28:36 -08:00
parent 8b9633e46b
commit 6162de142c
6 changed files with 32 additions and 13 deletions

View File

@ -910,6 +910,7 @@ function encode_mail($item) {
$x['message_id'] = $item['mid']; $x['message_id'] = $item['mid'];
$x['message_parent'] = $item['parent_mid']; $x['message_parent'] = $item['parent_mid'];
$x['created'] = $item['created']; $x['created'] = $item['created'];
$x['expires'] = $item['expires'];
$x['title'] = $item['title']; $x['title'] = $item['title'];
$x['body'] = $item['body']; $x['body'] = $item['body'];
$x['from'] = encode_item_xchan($item['from']); $x['from'] = encode_item_xchan($item['from']);
@ -939,6 +940,10 @@ function get_mail_elements($x) {
$arr['title'] = (($x['title'])? htmlentities($x['title'],ENT_COMPAT,'UTF-8',false) : ''); $arr['title'] = (($x['title'])? htmlentities($x['title'],ENT_COMPAT,'UTF-8',false) : '');
$arr['created'] = datetime_convert('UTC','UTC',$x['created']); $arr['created'] = datetime_convert('UTC','UTC',$x['created']);
if((! array_key_exists('expires',$x)) || ($x['expires'] === '0000-00-00 00:00:00'))
$arr['expires'] = '0000-00-00 00:00:00';
else
$arr['expires'] = datetime_convert('UTC','UTC',$x['expires']);
$arr['mail_flags'] = 0; $arr['mail_flags'] = 0;
@ -2465,6 +2470,7 @@ function mail_store($arr) {
$arr['from_xchan'] = ((x($arr,'from_xchan')) ? notags(trim($arr['from_xchan'])) : ''); $arr['from_xchan'] = ((x($arr,'from_xchan')) ? notags(trim($arr['from_xchan'])) : '');
$arr['to_xchan'] = ((x($arr,'to_xchan')) ? notags(trim($arr['to_xchan'])) : ''); $arr['to_xchan'] = ((x($arr,'to_xchan')) ? notags(trim($arr['to_xchan'])) : '');
$arr['created'] = ((x($arr,'created') !== false) ? datetime_convert('UTC','UTC',$arr['created']) : datetime_convert()); $arr['created'] = ((x($arr,'created') !== false) ? datetime_convert('UTC','UTC',$arr['created']) : datetime_convert());
$arr['expires'] = ((x($arr,'expires') !== false) ? datetime_convert('UTC','UTC',$arr['expires']) : '0000-00-00 00:00:00');
$arr['title'] = ((x($arr,'title')) ? notags(trim($arr['title'])) : ''); $arr['title'] = ((x($arr,'title')) ? notags(trim($arr['title'])) : '');
$arr['parent_mid'] = ((x($arr,'parent_mid')) ? notags(trim($arr['parent_mid'])) : ''); $arr['parent_mid'] = ((x($arr,'parent_mid')) ? notags(trim($arr['parent_mid'])) : '');
$arr['body'] = ((x($arr,'body')) ? trim($arr['body']) : ''); $arr['body'] = ((x($arr,'body')) ? trim($arr['body']) : '');

View File

@ -8,7 +8,7 @@ require_once('include/attach.php');
// send a private message // send a private message
function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto=''){ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto='',$expires = ''){
$ret = array('success' => false); $ret = array('success' => false);
@ -22,6 +22,10 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto='
if(! strlen($subject)) if(! strlen($subject))
$subject = t('[no subject]'); $subject = t('[no subject]');
// if(! $expires)
// $expires = '0000-00-00 00:00:00';
// else
// $expires = datetime_convert(date_default_timezone_get(),'UTC',$expires);
if($uid) { if($uid) {
$r = q("select * from channel where channel_id = %d limit 1", $r = q("select * from channel where channel_id = %d limit 1",
@ -111,8 +115,8 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto='
$r = q("INSERT INTO mail ( account_id, mail_flags, channel_id, from_xchan, to_xchan, title, body, attach, mid, parent_mid, created ) $r = q("INSERT INTO mail ( account_id, mail_flags, channel_id, from_xchan, to_xchan, title, body, attach, mid, parent_mid, created, expires )
VALUES ( %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )", VALUES ( %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )",
intval($channel['channel_account_id']), intval($channel['channel_account_id']),
intval(MAIL_OBSCURED), intval(MAIL_OBSCURED),
intval($channel['channel_id']), intval($channel['channel_id']),
@ -123,7 +127,8 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto='
dbesc($jattach), dbesc($jattach),
dbesc($mid), dbesc($mid),
dbesc($replyto), dbesc($replyto),
dbesc(datetime_convert()) dbesc(datetime_convert()),
dbesc($expires)
); );
// verify the save // verify the save

View File

@ -43,6 +43,11 @@ function poller_run($argv, $argc){
intval(ACCOUNT_EXPIRED) intval(ACCOUNT_EXPIRED)
); );
// expire any expired mail
q("delete from mail where expires != '0000-00-00 00:00:00' and expires < UTC_TIMESTAMP() ");
// Ensure that every channel pings a directory server once a month. This way we can discover // Ensure that every channel pings a directory server once a month. This way we can discover
// channels and sites that quietly vanished and prevent the directory from accumulating stale // channels and sites that quietly vanished and prevent the directory from accumulating stale
// or dead entries. // or dead entries.

View File

@ -40,6 +40,7 @@ function message_post(&$a) {
$body = ((x($_REQUEST,'body')) ? escape_tags(trim($_REQUEST['body'])) : ''); $body = ((x($_REQUEST,'body')) ? escape_tags(trim($_REQUEST['body'])) : '');
$recipient = ((x($_REQUEST,'messageto')) ? notags(trim($_REQUEST['messageto'])) : ''); $recipient = ((x($_REQUEST,'messageto')) ? notags(trim($_REQUEST['messageto'])) : '');
$rstr = ((x($_REQUEST,'messagerecip')) ? notags(trim($_REQUEST['messagerecip'])) : ''); $rstr = ((x($_REQUEST,'messagerecip')) ? notags(trim($_REQUEST['messagerecip'])) : '');
$expires = ((x($_REQUEST,'expires')) ? datetime_convert(date_default_timezone_get(),'UTC', $_REQUEST['expires']) : '0000-00-00 00:00:00');
// If we have a raw string for a recipient which hasn't been auto-filled, // If we have a raw string for a recipient which hasn't been auto-filled,
// it means they probably aren't in our address book, hence we don't know // it means they probably aren't in our address book, hence we don't know
@ -111,7 +112,7 @@ function message_post(&$a) {
// We have a local_user, let send_message use the session channel and save a lookup // We have a local_user, let send_message use the session channel and save a lookup
$ret = send_message(0, $recipient, $body, $subject, $replyto); $ret = send_message(0, $recipient, $body, $subject, $replyto, $expires);
if(! $ret['success']) { if(! $ret['success']) {
notice($ret['message']); notice($ret['message']);
@ -322,7 +323,8 @@ function message_content(&$a) {
'$attach' => t('Attach file'), '$attach' => t('Attach file'),
'$insert' => t('Insert web link'), '$insert' => t('Insert web link'),
'$wait' => t('Please wait'), '$wait' => t('Please wait'),
'$submit' => t('Submit') '$submit' => t('Submit'),
'$expires' => t('Expires: (leave blank for never)')
)); ));
return $o; return $o;
@ -463,8 +465,6 @@ function message_content(&$a) {
} }
logger('mails: ' . print_r($mails,true), LOGGER_DATA);
$recp = (($message['from_xchan'] === $channel['channel_hash']) ? 'to' : 'from'); $recp = (($message['from_xchan'] === $channel['channel_hash']) ? 'to' : 'from');
// FIXME - move this HTML to template // FIXME - move this HTML to template
@ -498,8 +498,8 @@ function message_content(&$a) {
'$attach' => t('Attach file'), '$attach' => t('Attach file'),
'$insert' => t('Insert web link'), '$insert' => t('Insert web link'),
'$submit' => t('Submit'), '$submit' => t('Submit'),
'$wait' => t('Please wait') '$wait' => t('Please wait'),
'$expires' => t('Expires: (leave blank for never)')
)); ));
return $o; return $o;

View File

@ -1693,7 +1693,7 @@ tr.mceLast {
} }
#prvmail-to-label, #prvmail-subject-label, #prvmail-message-label { #prvmail-to-label, #prvmail-subject-label, #prvmail-expires-label, #prvmail-message-label {
margin-bottom: 10px; margin-bottom: 10px;
margin-top: 20px; margin-top: 20px;
} }

View File

@ -17,12 +17,15 @@
<div id="prvmail-subject-label">{{$subject}}</div> <div id="prvmail-subject-label">{{$subject}}</div>
<input type="text" size="64" maxlength="255" id="prvmail-subject" name="subject" value="{{$subjtxt}}" {{$readonly}} tabindex="11" /> <input type="text" size="64" maxlength="255" id="prvmail-subject" name="subject" value="{{$subjtxt}}" {{$readonly}} tabindex="11" />
<div id="prvmail-expires-label">{{$expires}}</div>
<input type="text" size="64" maxlength="255" id="prvmail-expires" name="expires" value="" tabindex="12" />
<div id="prvmail-message-label">{{$yourmessage}}</div> <div id="prvmail-message-label">{{$yourmessage}}</div>
<textarea rows="8" cols="72" class="prvmail-text" id="prvmail-text" name="body" tabindex="12">{{$text}}</textarea> <textarea rows="8" cols="72" class="prvmail-text" id="prvmail-text" name="body" tabindex="13">{{$text}}</textarea>
<div id="prvmail-submit-wrapper" > <div id="prvmail-submit-wrapper" >
<input type="submit" id="prvmail-submit" name="submit" value="{{$submit}}" tabindex="13" /> <input type="submit" id="prvmail-submit" name="submit" value="{{$submit}}" tabindex="14" />
<div id="prvmail-upload-wrapper" > <div id="prvmail-upload-wrapper" >
<i id="prvmail-upload" class="icon-camera jot-icons" title="{{$upload}}"></i> <i id="prvmail-upload" class="icon-camera jot-icons" title="{{$upload}}"></i>
</div> </div>