diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/channel.php | 25 | ||||
-rw-r--r-- | include/conversation.php | 3 | ||||
-rw-r--r-- | include/import.php | 79 | ||||
-rw-r--r-- | include/items.php | 289 | ||||
-rw-r--r-- | include/text.php | 30 |
5 files changed, 0 insertions, 426 deletions
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) { |