From 0718ac514d2421a96ab191f874a0cd8b120a5a78 Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 28 May 2021 08:11:40 +0000 Subject: remove deprecated mail code --- Zotlabs/Lib/Libsync.php | 3 - Zotlabs/Lib/Libzot.php | 86 ------------ Zotlabs/Module/Import.php | 6 - Zotlabs/Module/Manage.php | 11 -- Zotlabs/Module/Sse_bs.php | 31 ----- Zotlabs/Widget/Notifications.php | 17 +-- include/channel.php | 25 ---- include/conversation.php | 3 - include/import.php | 79 ----------- include/items.php | 289 --------------------------------------- include/text.php | 30 ---- view/tpl/channel.tpl | 4 - 12 files changed, 1 insertion(+), 583 deletions(-) diff --git a/Zotlabs/Lib/Libsync.php b/Zotlabs/Lib/Libsync.php index 5455aa2ea..67603a0e3 100644 --- a/Zotlabs/Lib/Libsync.php +++ b/Zotlabs/Lib/Libsync.php @@ -255,9 +255,6 @@ class Libsync { if (array_key_exists('chatroom', $arr) && $arr['chatroom']) sync_chatrooms($channel, $arr['chatroom']); - if (array_key_exists('conv', $arr) && $arr['conv']) - import_conv($channel, $arr['conv']); - if (array_key_exists('mail', $arr) && $arr['mail']) sync_mail($channel, $arr['mail']); diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index e44a82b71..b04c0ea3c 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1377,8 +1377,6 @@ class Libzot { $check_mentions = true; } } - elseif ($msg['type'] === 'mail') - $perm = 'post_mail'; $r = []; @@ -2210,90 +2208,6 @@ class Libzot { return $post_id; } - static function process_mail_delivery($sender, $arr, $deliveries) { - - $result = []; - - if ($sender != $arr['from_xchan']) { - logger('process_mail_delivery: sender is not mail author'); - return; - } - - foreach ($deliveries as $d) { - - $DR = new DReport(z_root(), $sender, $d, $arr['mid']); - - $r = q("select * from channel where channel_hash = '%s' limit 1", - dbesc($d['hash']) - ); - - if (!$r) { - $DR->update('recipient not found'); - $result[] = $DR->get(); - continue; - } - - $channel = $r[0]; - $DR->set_name($channel['channel_name'] . ' <' . channel_reddress($channel) . '>'); - - - if (!perm_is_allowed($channel['channel_id'], $sender, 'post_mail')) { - - /* - * Always allow somebody to reply if you initiated the conversation. It's anti-social - * and a bit rude to send a private message to somebody and block their ability to respond. - * If you are being harrassed and want to put an end to it, delete the conversation. - */ - - $return = false; - if ($arr['parent_mid']) { - $return = q("select * from mail where mid = '%s' and channel_id = %d limit 1", - dbesc($arr['parent_mid']), - intval($channel['channel_id']) - ); - } - if (!$return) { - logger("permission denied for mail delivery {$channel['channel_id']}"); - $DR->update('permission denied'); - $result[] = $DR->get(); - continue; - } - } - - - $r = q("select id from mail where mid = '%s' and channel_id = %d limit 1", - dbesc($arr['mid']), - intval($channel['channel_id']) - ); - if ($r) { - if (intval($arr['mail_recalled'])) { - $x = q("delete from mail where id = %d and channel_id = %d", - intval($r[0]['id']), - intval($channel['channel_id']) - ); - $DR->update('mail recalled'); - $result[] = $DR->get(); - logger('mail_recalled'); - } - else { - $DR->update('duplicate mail received'); - $result[] = $DR->get(); - logger('duplicate mail received'); - } - continue; - } - else { - $arr['account_id'] = $channel['channel_account_id']; - $arr['channel_id'] = $channel['channel_id']; - $item_id = mail_store($arr); - $DR->update('mail delivered'); - $result[] = $DR->get(); - } - } - - return $result; - } - /** * @brief Processes delivery of profile. diff --git a/Zotlabs/Module/Import.php b/Zotlabs/Module/Import.php index 59db7b4be..77a9ec844 100644 --- a/Zotlabs/Module/Import.php +++ b/Zotlabs/Module/Import.php @@ -494,12 +494,6 @@ class Import extends \Zotlabs\Web\Controller { if(is_array($data['chatroom'])) import_chatrooms($channel,$data['chatroom']); - if(is_array($data['conv'])) - import_conv($channel,$data['conv']); - - if(is_array($data['mail'])) - import_mail($channel,$data['mail']); - if(is_array($data['event'])) import_events($channel,$data['event']); diff --git a/Zotlabs/Module/Manage.php b/Zotlabs/Module/Manage.php index bc2034b95..d67b47437 100644 --- a/Zotlabs/Module/Manage.php +++ b/Zotlabs/Module/Manage.php @@ -84,16 +84,6 @@ class Manage extends \Zotlabs\Web\Controller { if($intr) $channels[$x]['intros'] = intval($intr[0]['total']); - - $mails = q("SELECT count(id) as total from mail WHERE channel_id = %d AND mail_seen = 0 and from_xchan != '%s' ", - intval($channels[$x]['channel_id']), - dbesc($channels[$x]['channel_hash']) - ); - - if($mails) - $channels[$x]['mail'] = intval($mails[0]['total']); - - $events = q("SELECT etype, dtstart, adjust FROM event WHERE event.uid = %d AND dtstart < '%s' AND dtstart > '%s' and dismissed = 0 ORDER BY dtstart ASC ", @@ -175,7 +165,6 @@ class Manage extends \Zotlabs\Web\Controller { '$msg_make_default' => t('Make Default'), '$create' => $create, '$all_channels' => $channels, - '$mail_format' => t('%d new messages'), '$intros_format' => t('%d new introductions'), '$channel_usage_message' => $channel_usage_message, '$delegated_desc' => t('Delegated Channel'), diff --git a/Zotlabs/Module/Sse_bs.php b/Zotlabs/Module/Sse_bs.php index cc67c8eb7..4c903aa2c 100644 --- a/Zotlabs/Module/Sse_bs.php +++ b/Zotlabs/Module/Sse_bs.php @@ -100,7 +100,6 @@ class Sse_bs extends Controller { self::bs_forums(), self::bs_pubs($pubs), self::bs_files(), - self::bs_mail(), self::bs_all_events(), self::bs_register(), self::bs_info_notice() @@ -618,36 +617,6 @@ class Sse_bs extends Controller { } - function bs_mail() { - - $result['mail']['notifications'] = []; - $result['mail']['count'] = 0; - $result['mail']['offset'] = -1; - - if(! self::$uid) - return $result; - - if(! (self::$vnotify & VNOTIFY_MAIL)) - return $result; - - $r = q("select mail.*, xchan.* from mail left join xchan on xchan_hash = from_xchan - where channel_id = %d and mail_seen = 0 and mail_deleted = 0 - and from_xchan != '%s' order by created desc", - intval(self::$uid), - dbesc(self::$ob_hash) - ); - - if($r) { - foreach($r as $rr) { - $result['mail']['notifications'][] = Enotify::format_mail($rr); - } - $result['mail']['count'] = count($r); - } - - return $result; - - } - function bs_all_events() { $result['all_events']['notifications'] = []; diff --git a/Zotlabs/Widget/Notifications.php b/Zotlabs/Widget/Notifications.php index dd5a6cd46..d59312148 100644 --- a/Zotlabs/Widget/Notifications.php +++ b/Zotlabs/Widget/Notifications.php @@ -67,21 +67,6 @@ class Notifications { ] ]; - $notifications[] = [ - 'type' => 'mail', - 'icon' => 'envelope', - 'severity' => 'danger', - 'label' => t('New Mails'), - 'title' => t('New Mails Notifications'), - 'viewall' => [ - 'url' => 'mail/combined', - 'label' => t('View your private mails') - ], - 'markall' => [ - 'label' => t('Mark all messages seen') - ] - ]; - $notifications[] = [ 'type' => 'all_events', 'icon' => 'calendar', @@ -187,4 +172,4 @@ class Notifications { } } - + diff --git a/include/channel.php b/include/channel.php index e44fa01f2..91e2c37bd 100644 --- a/include/channel.php +++ b/include/channel.php @@ -770,7 +770,6 @@ function get_default_export_sections() { 'chatrooms', 'events', 'webpages', - 'mail', 'wikis' ]; @@ -1091,30 +1090,6 @@ function identity_basic_export($channel_id, $sections = null, $zap_compat = fals } } - if(in_array('mail',$sections)) { - $r = q("select * from conv where uid = %d", - intval($channel_id) - ); - if($r) { - for($x = 0; $x < count($r); $x ++) { - $r[$x]['subject'] = base64url_decode(str_rot47($r[$x]['subject'])); - } - $ret['conv'] = $r; - } - - $r = q("select * from mail where channel_id = %d", - intval($channel_id) - ); - if($r) { - $m = array(); - foreach($r as $rr) { - xchan_mail_query($rr); - $m[] = encode_mail($rr,true); - } - $ret['mail'] = $m; - } - } - if(in_array('wikis',$sections)) { $r = q("select * from item where resource_type like 'nwiki%%' and uid = %d order by created", intval($channel_id) diff --git a/include/conversation.php b/include/conversation.php index 9fc70c511..a5fdb5fa1 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -1057,9 +1057,6 @@ function thread_author_menu($item, $mode = '') { $follow_url = z_root() . '/follow/?f=&url=' . urlencode($url) . '&interactive=0'; } } - if($item['uid'] > 0 && author_is_pmable($item['author'],$contact)) { - $pm_url = z_root() . '/mail/new/?f=&hash=' . urlencode($item['author_xchan']); - } } if($contact) { diff --git a/include/import.php b/include/import.php index 022440676..bf7f47c3e 100644 --- a/include/import.php +++ b/include/import.php @@ -1089,85 +1089,6 @@ function import_likes($channel, $likes) { } } -function import_conv($channel,$convs) { - if($channel && $convs) { - foreach($convs as $conv) { - if($conv['deleted']) { - q("delete from conv where guid = '%s' and uid = %d", - dbesc($conv['guid']), - intval($channel['channel_id']) - ); - continue; - } - - unset($conv['id']); - - $conv['uid'] = $channel['channel_id']; - $conv['subject'] = str_rot47(base64url_encode($conv['subject'])); - - $r = q("select id from conv where guid = '%s' and uid = %d limit 1", - dbesc($conv['guid']), - intval($channel['channel_id']) - ); - if($r) - continue; - - create_table_from_array('conv',$conv); - } - } -} - -/** - * @brief Import mails. - * - * @param array $channel - * @param array $mails - * @param boolean $sync (optional) default false - */ -function import_mail($channel, $mails, $sync = false) { - if($channel && $mails) { - foreach($mails as $mail) { - if(array_key_exists('flags',$mail) && in_array('deleted',$mail['flags'])) { - q("delete from mail where mid = '%s' and uid = %d", - dbesc($mail['message_id']), - intval($channel['channel_id']) - ); - continue; - } - if(array_key_exists('flags',$mail) && in_array('recalled',$mail['flags'])) { - q("update mail set mail_recalled = 1 where mid = '%s' and uid = %d", - dbesc($mail['message_id']), - intval($channel['channel_id']) - ); - continue; - } - - $m = get_mail_elements($mail); - if(! $m) - continue; - - $m['account_id'] = $channel['channel_account_id']; - $m['channel_id'] = $channel['channel_id']; - - $mail_id = mail_store($m); - if($sync && $mail_id) { - Zotlabs\Daemon\Master::Summon(array('Notifier','single_mail',$mail_id)); - } - } - } -} - -/** - * @brief Synchronise mails. - * - * @see import_mail() - * @param array $channel - * @param array $mails - */ -function sync_mail($channel, $mails) { - import_mail($channel, $mails, true); -} - /** * @brief Synchronise files. * diff --git a/include/items.php b/include/items.php index ba4e79a75..5bb99c91c 100644 --- a/include/items.php +++ b/include/items.php @@ -1502,143 +1502,6 @@ function encode_item_flags($item) { return $ret; } -function encode_mail($item,$extended = false) { - $x = []; - $x['type'] = 'mail'; - $x['encoding'] = 'zot'; - - if(array_key_exists('mail_obscured',$item) && intval($item['mail_obscured'])) { - if($item['title']) - $item['title'] = base64url_decode(str_rot47($item['title'])); - if($item['body']) - $item['body'] = base64url_decode(str_rot47($item['body'])); - } - - $x['message_id'] = $item['mid']; - $x['message_parent'] = $item['parent_mid']; - $x['created'] = $item['created']; - $x['expires'] = $item['expires']; - $x['title'] = $item['title']; - $x['body'] = $item['body']; - $x['from'] = encode_item_xchan($item['from']); - $x['to'] = encode_item_xchan($item['to']); - $x['raw'] = $item['mail_raw']; - $x['mimetype'] = $item['mail_mimetype']; - $x['sig'] = $item['sig']; - - if($item['attach']) - $x['attach'] = json_decode($item['attach'],true); - - $x['flags'] = array(); - - if(intval($item['mail_recalled'])) { - $x['flags'][] = 'recalled'; - $x['title'] = ''; - $x['body'] = ''; - } - - if($extended) { - $x['conv_guid'] = $item['conv_guid']; - if(intval($item['mail_deleted'])) - $x['flags'][] = 'deleted'; - if(intval($item['mail_replied'])) - $x['flags'][] = 'replied'; - if(intval($item['mail_isreply'])) - $x['flags'][] = 'isreply'; - if(intval($item['mail_seen'])) - $x['flags'][] = 'seen'; - } - - return $x; -} - - - -function get_mail_elements($x) { - - $arr = array(); - - if(intval($x['raw'])) { - $arr['mail_raw'] = intval($x['raw']); - $arr['body'] = $x['body']; - } - else { - $arr['body'] = (($x['body']) ? htmlspecialchars($x['body'], ENT_COMPAT,'UTF-8',false) : ''); - - $maxlen = get_max_import_size(); - - if($maxlen && mb_strlen($arr['body']) > $maxlen) { - $arr['body'] = mb_substr($arr['body'],0,$maxlen,'UTF-8'); - logger('message length exceeds max_import_size: truncated'); - } - } - - $arr['title'] = (($x['title'])? htmlspecialchars($x['title'],ENT_COMPAT,'UTF-8',false) : ''); - $arr['mail_mimetype'] = (($x['mimetype']) ? htmlspecialchars($x['mimetype'],ENT_COMPAT,'UTF-8',false) : 'text/bbcode'); - $arr['conv_guid'] = (($x['conv_guid'])? htmlspecialchars($x['conv_guid'],ENT_COMPAT,'UTF-8',false) : ''); - - $arr['created'] = datetime_convert('UTC','UTC',$x['created']); - if((! array_key_exists('expires',$x)) || ($x['expires'] <= NULL_DATE)) - $arr['expires'] = NULL_DATE; - else - $arr['expires'] = datetime_convert('UTC','UTC',$x['expires']); - - $arr['mail_flags'] = 0; - - if(array_key_exists('sig',$x)) - $arr['sig'] = $x['sig']; - - if($x['flags'] && is_array($x['flags'])) { - if(in_array('recalled',$x['flags'])) { - $arr['mail_recalled'] = 1; - } - if(in_array('replied',$x['flags'])) { - $arr['mail_replied'] = 1; - } - if(in_array('isreply',$x['flags'])) { - $arr['mail_isreply'] = 1; - } - if(in_array('seen',$x['flags'])) { - $arr['mail_seen'] = 1; - } - if(in_array('deleted',$x['flags'])) { - $arr['mail_deleted'] = 1; - } - } - - $key = get_config('system','pubkey'); - $arr['mail_obscured'] = 1; - if($arr['body']) { - $arr['body'] = str_rot47(base64url_encode($arr['body'])); - } - - if($arr['title']) { - $arr['title'] = str_rot47(base64url_encode($arr['title'])); - } - if($arr['created'] > datetime_convert()) - $arr['created'] = datetime_convert(); - - - $arr['mid'] = (($x['message_id']) ? htmlspecialchars($x['message_id'], ENT_COMPAT,'UTF-8',false) : ''); - $arr['parent_mid'] = (($x['message_parent']) ? htmlspecialchars($x['message_parent'], ENT_COMPAT,'UTF-8',false) : ''); - - if($x['attach']) - $arr['attach'] = activity_sanitise($x['attach']); - - if(($xchan_hash = import_author_xchan($x['from'])) !== false) - $arr['from_xchan'] = $xchan_hash; - else - return array(); - - if(($xchan_hash = import_author_xchan($x['to'])) !== false) - $arr['to_xchan'] = $xchan_hash; - else - return array(); - - return $arr; -} - - function get_profile_elements($x) { $arr = array(); @@ -3513,158 +3376,6 @@ function post_is_importable($item,$abook) { } - -function mail_store($arr) { - - if(! $arr['channel_id']) { - logger('mail_store: no uid'); - return 0; - } - - $channel = channelx_by_n($arr['channel_id']); - - if(! $arr['mail_obscured']) { - if((strpos($arr['body'],'<') !== false) || (strpos($arr['body'],'>') !== false)) - $arr['body'] = escape_tags($arr['body']); - } - - if(array_key_exists('attach',$arr)) { - if(is_array($arr['attach'])) { - $arr['attach'] = json_encode($arr['attach']); - } - } - else { - $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'])) : ''); - $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['expires'] = ((x($arr,'expires') !== false) ? datetime_convert('UTC','UTC',$arr['expires']) : NULL_DATE); - $arr['title'] = ((x($arr,'title')) ? trim($arr['title']) : ''); - $arr['parent_mid'] = ((x($arr,'parent_mid')) ? notags(trim($arr['parent_mid'])) : ''); - $arr['body'] = ((x($arr,'body')) ? trim($arr['body']) : ''); - $arr['sig'] = ((x($arr,'sig')) ? trim($arr['sig']) : ''); - $arr['conv_guid'] = ((x($arr,'conv_guid')) ? trim($arr['conv_guid']) : ''); - $arr['mail_mimetype'] = ((x($arr,'mail_mimetype')) ? trim($arr['mail_mimetype']) : 'text/bbcode'); - - $arr['mail_flags'] = ((x($arr,'mail_flags')) ? intval($arr['mail_flags']) : 0 ); - $arr['mail_raw'] = ((x($arr,'mail_raw')) ? intval($arr['mail_raw']) : 0 ); - - - if($arr['parent_mid']) { - $parent_item = q("select * from mail where mid = '%s' and channel_id = %d limit 1", - dbesc($arr['parent_mid']), - intval($arr['channel_id']) - ); - if(($parent_item) && (! $arr['conv_guid'])) { - $arr['conv_guid'] = $parent_item[0]['conv_guid']; - } - } - else { - logger('mail_store: missing parent'); - $arr['parent_mid'] = $arr['mid']; - } - - if($arr['from_xchan'] === $channel['channel_hash']) - $conversant = $arr['to_xchan']; - else - $conversant = $arr['from_xchan']; - - - if(! $arr['conv_guid']) { - $x = create_conversation($channel,$conversant,(($arr['title']) ? base64url_decode(str_rot47($arr['title'])) : '')); - $arr['conv_guid'] = (($x) ? $x['guid'] : ''); - } - - - $r = q("SELECT id FROM mail WHERE mid = '%s' AND channel_id = %d LIMIT 1", - dbesc($arr['mid']), - intval($arr['channel_id']) - ); - - if($r) { - logger('Duplicate item ignored. ' . print_r($arr,true)); - return 0; - } - - if(! $r && $arr['mail_recalled'] == 1) { - logger('Recalled item not found. ' . print_r($arr,true)); - return 0; - } - - /** - * @hooks post_mail - * Called when a mail message has been composed. - */ - call_hooks('post_mail', $arr); - - if(x($arr,'cancel')) { - logger('Post cancelled by plugin.'); - return 0; - } - - logger('mail_store: ' . print_r($arr,true), LOGGER_DATA); - - create_table_from_array('mail', $arr); - - // find the item we just created - - $r = q("SELECT id FROM mail WHERE mid = '%s' AND channel_id = %d ORDER BY id ASC ", - $arr['mid'], // already dbesc'd - intval($arr['channel_id']) - ); - - if($r) { - $current_post = $r[0]['id']; - logger('Created item ' . $current_post, LOGGER_DEBUG); - $arr['id'] = $current_post; // for notification - } - else { - logger('Could not locate created item'); - return 0; - } - if(count($r) > 1) { - logger('Duplicated post occurred. Removing duplicates.'); - q("DELETE FROM mail WHERE mid = '%s' AND channel_id = %d AND id != %d ", - $arr['mid'], - intval($arr['channel_id']), - intval($current_post) - ); - } - else { - - $notif_params = array( - 'from_xchan' => $arr['from_xchan'], - 'to_xchan' => $arr['to_xchan'], - 'type' => NOTIFY_MAIL, - 'item' => $arr, - 'verb' => ACTIVITY_POST, - 'otype' => 'mail' - ); - - Enotify::submit($notif_params); - } - - if($arr['conv_guid']) { - $c = q("update conv set updated = '%s' where guid = '%s' and uid = %d", - dbesc(datetime_convert()), - dbesc($arr['conv_guid']), - intval($arr['channel_id']) - ); - } - - /** - * @hooks post_mail_end - * Called when a mail message has been delivered. - */ - call_hooks('post_mail_end', $arr); - return $current_post; -} - - function fix_private_photos($s, $uid, $item = null, $cid = 0) { logger('fix_private_photos', LOGGER_DEBUG); diff --git a/include/text.php b/include/text.php index 35a65bcfb..2584a94b9 100644 --- a/include/text.php +++ b/include/text.php @@ -1523,15 +1523,6 @@ function unobscure(&$item) { return; } -function unobscure_mail(&$item) { - if(array_key_exists('mail_obscured',$item) && intval($item['mail_obscured'])) { - if($item['title']) - $item['title'] = base64url_decode(str_rot47($item['title'])); - if($item['body']) - $item['body'] = base64url_decode(str_rot47($item['body'])); - } -} - function theme_attachments(&$item) { @@ -2555,27 +2546,6 @@ function xchan_query(&$items, $abook = true, $effective_uid = 0) { } } -function xchan_mail_query(&$item) { - $arr = array(); - $chans = null; - if($item) { - if($item['from_xchan'] && (! in_array("'" . dbesc($item['from_xchan']) . "'",$arr))) - $arr[] = "'" . dbesc($item['from_xchan']) . "'"; - if($item['to_xchan'] && (! in_array("'" . dbesc($item['to_xchan']) . "'",$arr))) - $arr[] = "'" . dbesc($item['to_xchan']) . "'"; - } - - if(count($arr)) { - $chans = q("select xchan.*,hubloc.* from xchan left join hubloc on hubloc_hash = xchan_hash - where xchan_hash in (" . protect_sprintf(implode(',', $arr)) . ") and hubloc_primary = 1"); - } - if($chans) { - $item['from'] = find_xchan_in_array($item['from_xchan'],$chans); - $item['to'] = find_xchan_in_array($item['to_xchan'],$chans); - } -} - - function find_xchan_in_array($xchan,$arr) { if(count($arr)) { foreach($arr as $x) { diff --git a/view/tpl/channel.tpl b/view/tpl/channel.tpl index 63e09ec05..0ff52831d 100644 --- a/view/tpl/channel.tpl +++ b/view/tpl/channel.tpl @@ -36,10 +36,6 @@
{{if !$channel.delegate}} -