diff --git a/language/az.php b/language/az.php
index 5e1c54a187..e3f91e1ced 100755
--- a/language/az.php
+++ b/language/az.php
@@ -621,6 +621,7 @@
'You must provide a name for your script' => false,
'Empty script' => false,
'Please create a profile for saving sent messages option' => false,
+ 'You have %d scheduled messages that won\'t be executed if you quit' => false,
'Attachment storage unavailable, please contact your site administrator' => false,
'Your subject is empty!' => false,
'Your body is empty!' => false,
diff --git a/language/de.php b/language/de.php
index 7150e9c182..8bd66b1a43 100755
--- a/language/de.php
+++ b/language/de.php
@@ -618,6 +618,7 @@
'You must provide a name for your script' => false,
'Empty script' => false,
'Please create a profile for saving sent messages option' => false,
+ 'You have %d scheduled messages that won\'t be executed if you quit' => false,
'Attachment storage unavailable, please contact your site administrator' => false,
'Your subject is empty!' => false,
'Your body is empty!' => false,
diff --git a/language/en.php b/language/en.php
index f630f6a2d3..5cd8c300ef 100755
--- a/language/en.php
+++ b/language/en.php
@@ -636,6 +636,7 @@
'You must provide a name for your script' => false,
'Empty script' => false,
'Please create a profile for saving sent messages option' => false,
+ 'You have %d scheduled messages that won\'t be executed if you quit' => false,
'Attachment storage unavailable, please contact your site administrator' => false,
'Your subject is empty!' => false,
'Your body is empty!' => false,
diff --git a/language/es.php b/language/es.php
index fa551b1ea9..c253b1f363 100755
--- a/language/es.php
+++ b/language/es.php
@@ -618,6 +618,7 @@
'You must provide a name for your script' => false,
'Empty script' => false,
'Please create a profile for saving sent messages option' => false,
+ 'You have %d scheduled messages that won\'t be executed if you quit' => false,
'Attachment storage unavailable, please contact your site administrator' => false,
'Your subject is empty!' => false,
'Your body is empty!' => false,
diff --git a/language/et.php b/language/et.php
index 61b7b6addb..53e6207a9f 100755
--- a/language/et.php
+++ b/language/et.php
@@ -626,6 +626,7 @@
'You must provide a name for your script' => false,
'Empty script' => false,
'Please create a profile for saving sent messages option' => false,
+ 'You have %d scheduled messages that won\'t be executed if you quit' => false,
'Attachment storage unavailable, please contact your site administrator' => false,
'Your subject is empty!' => false,
'Your body is empty!' => false,
diff --git a/language/fa.php b/language/fa.php
index b2ad0e2221..9431100de7 100755
--- a/language/fa.php
+++ b/language/fa.php
@@ -670,6 +670,7 @@
'You must provide a name for your script' => false,
'Empty script' => false,
'Please create a profile for saving sent messages option' => false,
+ 'You have %d scheduled messages that won\'t be executed if you quit' => false,
'Attachment storage unavailable, please contact your site administrator' => false,
'Your subject is empty!' => false,
'Your body is empty!' => false,
diff --git a/language/fr.php b/language/fr.php
index b60c7c3592..8e0550fc0e 100755
--- a/language/fr.php
+++ b/language/fr.php
@@ -617,6 +617,7 @@
'You must provide a name for your script' => false,
'Empty script' => false,
'Please create a profile for saving sent messages option' => false,
+ 'You have %d scheduled messages that won\'t be executed if you quit' => 'Vous avez %d messages programmés qui ne seront pas exécutés si vous quittez',
'Attachment storage unavailable, please contact your site administrator' => false,
'Your subject is empty!' => false,
'Your body is empty!' => false,
diff --git a/language/hu.php b/language/hu.php
index e91cd6a66d..7e9b587059 100755
--- a/language/hu.php
+++ b/language/hu.php
@@ -618,6 +618,7 @@
'You must provide a name for your script' => false,
'Empty script' => false,
'Please create a profile for saving sent messages option' => false,
+ 'You have %d scheduled messages that won\'t be executed if you quit' => false,
'Attachment storage unavailable, please contact your site administrator' => false,
'Your subject is empty!' => false,
'Your body is empty!' => false,
diff --git a/language/id.php b/language/id.php
index 07b205ab8b..95c4ac6a5f 100755
--- a/language/id.php
+++ b/language/id.php
@@ -625,6 +625,7 @@
'You must provide a name for your script' => false,
'Empty script' => false,
'Please create a profile for saving sent messages option' => false,
+ 'You have %d scheduled messages that won\'t be executed if you quit' => false,
'Attachment storage unavailable, please contact your site administrator' => false,
'Your subject is empty!' => false,
'Your body is empty!' => false,
diff --git a/language/it.php b/language/it.php
index 5147b4e8ad..d720e4214a 100755
--- a/language/it.php
+++ b/language/it.php
@@ -618,6 +618,7 @@
'You must provide a name for your script' => false,
'Empty script' => false,
'Please create a profile for saving sent messages option' => false,
+ 'You have %d scheduled messages that won\'t be executed if you quit' => false,
'Attachment storage unavailable, please contact your site administrator' => false,
'Your subject is empty!' => false,
'Your body is empty!' => false,
diff --git a/language/ja.php b/language/ja.php
index 30596c066d..7c7d601ac5 100755
--- a/language/ja.php
+++ b/language/ja.php
@@ -618,6 +618,7 @@
'You must provide a name for your script' => false,
'Empty script' => false,
'Please create a profile for saving sent messages option' => false,
+ 'You have %d scheduled messages that won\'t be executed if you quit' => false,
'Attachment storage unavailable, please contact your site administrator' => false,
'Your subject is empty!' => false,
'Your body is empty!' => false,
diff --git a/language/nl.php b/language/nl.php
index 1d1db295cc..82e94158d6 100755
--- a/language/nl.php
+++ b/language/nl.php
@@ -618,6 +618,7 @@
'You must provide a name for your script' => false,
'Empty script' => false,
'Please create a profile for saving sent messages option' => false,
+ 'You have %d scheduled messages that won\'t be executed if you quit' => false,
'Attachment storage unavailable, please contact your site administrator' => false,
'Your subject is empty!' => false,
'Your body is empty!' => false,
diff --git a/language/pt-BR.php b/language/pt-BR.php
index 1fcf9142ec..7ad23625b8 100755
--- a/language/pt-BR.php
+++ b/language/pt-BR.php
@@ -617,6 +617,7 @@
'You must provide a name for your script' => false,
'Empty script' => false,
'Please create a profile for saving sent messages option' => false,
+ 'You have %d scheduled messages that won\'t be executed if you quit' => false,
'Attachment storage unavailable, please contact your site administrator' => false,
'Your subject is empty!' => false,
'Your body is empty!' => false,
diff --git a/language/ro.php b/language/ro.php
index 5a52506d25..c019b88263 100755
--- a/language/ro.php
+++ b/language/ro.php
@@ -617,6 +617,7 @@
'You must provide a name for your script' => false,
'Empty script' => false,
'Please create a profile for saving sent messages option' => false,
+ 'You have %d scheduled messages that won\'t be executed if you quit' => false,
'Attachment storage unavailable, please contact your site administrator' => false,
'Your subject is empty!' => false,
'Your body is empty!' => false,
diff --git a/language/ru.php b/language/ru.php
index 60813edac2..70cd16aa1c 100755
--- a/language/ru.php
+++ b/language/ru.php
@@ -619,6 +619,7 @@
'You must provide a name for your script' => false,
'Empty script' => false,
'Please create a profile for saving sent messages option' => false,
+ 'You have %d scheduled messages that won\'t be executed if you quit' => false,
'Attachment storage unavailable, please contact your site administrator' => false,
'Your subject is empty!' => false,
'Your body is empty!' => false,
diff --git a/language/zh-Hans.php b/language/zh-Hans.php
index 8baf2310ff..526e932c4a 100644
--- a/language/zh-Hans.php
+++ b/language/zh-Hans.php
@@ -639,6 +639,7 @@
'You must provide a name for your script' => '请提供脚本名称',
'Empty script' => '空脚本',
'Please create a profile for saving sent messages option' => '请创建用于保存已发送信息选项的配置文件',
+ 'You have %d scheduled messages that won\'t be executed if you quit' => false,
'Attachment storage unavailable, please contact your site administrator' => '附件存储不可用,请联系您的网站管理员',
'Your subject is empty!' => '主题为空!',
'Your body is empty!' => '内容为空!',
diff --git a/lib/servers.php b/lib/servers.php
index 9e37fdb967..a1537b470e 100644
--- a/lib/servers.php
+++ b/lib/servers.php
@@ -273,4 +273,30 @@ private static function match($server, $user, $name) {
}
return false;
}
+
+ private static function appendPasswordAndUsername(array $server) {
+ $server['password'] = $server['pass'];
+ $server['username'] = $server['user'];
+ return $server;
+ }
+
+ public static function getForMailbox($id) {
+ $server = self::get($id, true);
+ if ($server) {
+ return self::appendPasswordAndUsername($server);
+ }
+ return false;
+ }
+
+ public static function dumpForMailbox($id = false) {
+ $list = self::dump($id, true);
+ if ($id !== false) {
+ return self::appendPasswordAndUsername($list);
+ }
+ foreach ($list as $index => $server) {
+ $server = self::appendPasswordAndUsername($server);
+ $list[$index] = $server;
+ }
+ return $list;
+ }
}
diff --git a/modules/core/functions.php b/modules/core/functions.php
index 1e224fff70..d9dfcf197d 100644
--- a/modules/core/functions.php
+++ b/modules/core/functions.php
@@ -637,3 +637,112 @@ function privacy_setting_callback($val, $key, $mod) {
}
return $val;
}
+
+if (!hm_exists('get_scheduled_date')) {
+ function get_scheduled_date($format, $only_label = false) {
+ switch ($format) {
+ case 'later_in_day':
+ $date_string = 'today 18:00';
+ $label = 'Later in the day';
+ break;
+ case 'tomorrow':
+ $date_string = '+1 day 08:00';
+ $label = 'Tomorrow';
+ break;
+ case 'next_weekend':
+ $date_string = 'next Saturday 08:00';
+ $label = 'Next weekend';
+ break;
+ case 'next_week':
+ $date_string = 'next week 08:00';
+ $label = 'Next week';
+ break;
+ case 'next_month':
+ $date_string = 'next month 08:00';
+ $label = 'Next month';
+ break;
+ default:
+ $date_string = $format;
+ $label = 'Certain date';
+ break;
+ }
+
+ $time = strtotime($date_string);
+
+ if ($only_label) {
+ return [$label, date('D, H:i', $time)];
+ }
+
+ return date('D, d M Y H:i T', $time);
+ }
+}
+
+
+/**
+ * @subpackage imap/functions
+ */
+if (!hm_exists('nexter_formats')) {
+function nexter_formats() {
+ $values = array(
+ 'tomorrow',
+ 'next_weekend',
+ 'next_week',
+ 'next_month'
+ );
+ if (date('H') <= 16) {
+ array_push($values, 'later_in_day');
+ }
+ return $values;
+}}
+
+if (!hm_exists('schedule_dropdown')) {
+function schedule_dropdown($output, $send_now = false) {
+ $values = nexter_formats();
+
+ $txt = '';
+ if ($send_now) {
+ $txt .= '
+ ';
+ }
+ $txt .= '';
+ if ($send_now) {
+ $txt .= '
';
+ }
+
+ return $txt;
+}}
+
+/**
+ * @subpackage imap/functions
+ */
+if (!hm_exists('parse_delayed_header')) {
+ function parse_delayed_header($header, $name)
+ {
+ $header = str_replace("$name: ", '', $header);
+ $result = [];
+ foreach (explode(';', $header) as $keyValue)
+ {
+ $keyValue = trim($keyValue);
+ $spacePos = strpos($keyValue, ' ');
+ if ($spacePos > 0) {
+ $result[rtrim(substr($keyValue, 0, $spacePos), ':')] = trim(substr($keyValue, $spacePos+1));
+ } else {
+ $result[$keyValue] = true;
+ }
+ }
+ return $result;
+ }
+}
\ No newline at end of file
diff --git a/modules/core/handler_modules.php b/modules/core/handler_modules.php
index 6fab55ab51..25270cc12d 100644
--- a/modules/core/handler_modules.php
+++ b/modules/core/handler_modules.php
@@ -1159,7 +1159,7 @@ public function process() {
return;
}
- add_profile($profileName, $profileSignature, $profileReplyTo, $profileIsDefault, $email, $imapAddress, $email, $this->smtp_server_id, $this->imap_server_id, $this);
+ add_profile($profileName, $profileSignature, $profileReplyTo, $profileIsDefault, $email, $onlyJmap? $jmapAddress: $imapAddress, $email, $this->smtp_server_id, $this->imap_server_id, $this);
}
if ($this->module_is_supported('imap_folders')) {
diff --git a/modules/core/hm-mailbox.php b/modules/core/hm-mailbox.php
index 819733d3da..ff9f538517 100644
--- a/modules/core/hm-mailbox.php
+++ b/modules/core/hm-mailbox.php
@@ -74,6 +74,9 @@ public function server_type() {
}
public function authed() {
+ if (! $this->connection) {
+ return false;
+ }
if ($this->is_imap()) {
return $this->connection->get_state() == 'authenticated' || $this->connection->get_state() == 'selected';
} elseif ($this->is_smtp()) {
@@ -586,4 +589,8 @@ public function select_folder($folder) {
}
return true;
}
+
+ public function get_config() {
+ return $this->config;
+ }
}
diff --git a/modules/core/message_list_functions.php b/modules/core/message_list_functions.php
index c580ae339c..7950c36860 100644
--- a/modules/core/message_list_functions.php
+++ b/modules/core/message_list_functions.php
@@ -336,11 +336,11 @@ function subject_callback($vals, $style, $output_mod) {
*/
if (!hm_exists('date_callback')) {
function date_callback($vals, $style, $output_mod) {
- $snooze_class = isset($vals[2]) && $vals[2]? ' snoozed_date': '';
+ $delayed_class = isset($vals[2]) && $vals[2]? ' delayed_date': '';
if ($style == 'news') {
- return sprintf('%s
', $snooze_class, $output_mod->html_safe($vals[0]), $output_mod->html_safe($vals[1]));
+ return sprintf('%s
', $delayed_class, $output_mod->html_safe($vals[0]), $output_mod->html_safe($vals[1]));
}
- return sprintf('%s ', $snooze_class, $output_mod->html_safe(date('r', $vals[1])), $output_mod->html_safe($vals[0]), $output_mod->html_safe($vals[1]));
+ return sprintf('%s ', $delayed_class, $output_mod->html_safe(date('r', $vals[1])), $output_mod->html_safe($vals[0]), $output_mod->html_safe($vals[1]));
}}
function dates_holders_callback($vals) {
diff --git a/modules/core/site.css b/modules/core/site.css
index 61b290d146..612b492aa4 100644
--- a/modules/core/site.css
+++ b/modules/core/site.css
@@ -1276,7 +1276,7 @@ div.unseen,
.mobile .imap_sort {
width: 100%;
}
-.snoozed_date {
+.delayed_date {
color: var(--bs-primary) !important;
}
diff --git a/modules/core/site.js b/modules/core/site.js
index 4fe5d652e0..9bdd0948c2 100644
--- a/modules/core/site.js
+++ b/modules/core/site.js
@@ -2405,3 +2405,57 @@ const observeMessageTextMutationAndHandleExternalResources = (inline) => {
});
}
};
+
+function setupActionSchedule(callback) {
+ $(document).on('click', '.nexter_date_picker', function (e) {
+ document.querySelector('.nexter_input_date').showPicker();
+ });
+ $(document).on('click', '.nexter_date_helper', function (e) {
+ e.preventDefault();
+ $('.nexter_input').val($(this).attr('data-value')).trigger('change');
+ });
+ $(document).on('input', '.nexter_input_date', function (e) {
+ var now = new Date();
+ now.setMinutes(now.getMinutes() + 1);
+ $(this).attr('min', now.toJSON().slice(0, 16));
+ if (new Date($(this).val()).getTime() <= now.getTime()) {
+ $('.nexter_date_picker').css('border', '1px solid red');
+ } else {
+ $('.nexter_date_picker').css({ 'border': 'unset', 'border-top': '1px solid #ddd' });
+ }
+ });
+ $(document).on('change', '.nexter_input_date', function (e) {
+ const selectedDate = new Date($(this).val());
+ if ($(this).val() && new Date().getTime() < selectedDate.getTime()) {
+ $('.nexter_input').val(selectedDate.toISOString()).trigger('change');
+ }
+ });
+ $(document).on('change', '.nexter_input', callback);
+}
+
+function setupActionSnooze(callback) {
+ $(document).on('click', '.nexter_date_picker_snooze', function (e) {
+ document.querySelector('.nexter_input_date_snooze').showPicker();
+ });
+ $(document).on('click', '.nexter_date_helper_snooze', function (e) {
+ e.preventDefault();
+ $('.nexter_input_snooze').val($(this).attr('data-value')).trigger('change');
+ });
+ $(document).on('input', '.nexter_input_date_snooze', function (e) {
+ var now = new Date();
+ now.setMinutes(now.getMinutes() + 1);
+ $(this).attr('min', now.toJSON().slice(0, 16));
+ if (new Date($(this).val()).getTime() <= now.getTime()) {
+ $('.nexter_date_picker_snooze').css('border', '1px solid red');
+ } else {
+ $('.nexter_date_picker_snooze').css({ 'border': 'unset', 'border-top': '1px solid #ddd' });
+ }
+ });
+ $(document).on('change', '.nexter_input_date_snooze', function (e) {
+ const selectedDate = new Date($(this).val());
+ if ($(this).val() && new Date().getTime() < selectedDate.getTime()) {
+ $('.nexter_input_snooze').val(selectedDate.toISOString()).trigger('change');
+ }
+ });
+ $(document).on('change', '.nexter_input_snooze', callback);
+}
diff --git a/modules/imap/functions.php b/modules/imap/functions.php
index 5f41493923..cecd7d4536 100644
--- a/modules/imap/functions.php
+++ b/modules/imap/functions.php
@@ -252,10 +252,14 @@ function format_imap_message_list($msg_list, $output_module, $parent_list=false,
$nofrom = ' nofrom';
}
$is_snoozed = !empty($msg['x_snoozed']) && hex2bin($msg['folder']) == 'Snoozed';
+ $is_scheduled = !empty($msg['x_schedule']) && hex2bin($msg['folder']) == 'Scheduled';
if ($is_snoozed) {
- $snooze_header = parse_snooze_header('X-Snoozed: '.$msg['x_snoozed']);
+ $snooze_header = parse_delayed_header('X-Snoozed: '.$msg['x_snoozed'], 'X-Snoozed');
$date = $snooze_header['until'];
$timestamp = strtotime($date);
+ } elseif ($is_scheduled) {
+ $date = $msg['x_schedule'];
+ $timestamp = strtotime($date);
} else {
if ($list_sort == 'date') {
$date_field = 'date';
@@ -316,7 +320,7 @@ function format_imap_message_list($msg_list, $output_module, $parent_list=false,
array('subject_callback', $subject, $url, $flags, $icon, $preview_msg),
array('safe_output_callback', 'source', $source),
array('safe_output_callback', 'from'.$nofrom, $from, null, str_replace(array($from, '<', '>'), '', $msg['from'])),
- array('date_callback', $date, $timestamp),
+ array('date_callback', $date, $timestamp, $is_snoozed || $is_scheduled),
array('dates_holders_callback', $msg['internal_date'], $msg['date']),
),
$id,
@@ -331,7 +335,7 @@ function format_imap_message_list($msg_list, $output_module, $parent_list=false,
array('safe_output_callback', 'source', $source, $icon),
array('safe_output_callback', 'from'.$nofrom, $from, null, str_replace(array($from, '<', '>'), '', $msg['from'])),
array('subject_callback', $subject, $url, $flags, null, $preview_msg),
- array('date_callback', $date, $timestamp, $is_snoozed),
+ array('date_callback', $date, $timestamp, $is_snoozed || $is_scheduled),
array('icon_callback', $flags),
array('dates_holders_callback', $msg['internal_date'], $msg['date']),
),
@@ -1343,7 +1347,7 @@ function snooze_message($mailbox, $msg_id, $folder, $snooze_tag) {
preg_match("/^X-Snoozed:.*(\r?\n[ \t]+.*)*\r?\n?/im", $msg, $matches);
if (count($matches)) {
$msg = str_replace($matches[0], '', $msg);
- $old_folder = parse_snooze_header($matches[0])['from'];
+ $old_folder = parse_delayed_header($matches[0], 'X-Snoozed')['from'];
}
if ($snooze_tag) {
$from = $old_folder ?? $folder;
@@ -1370,7 +1374,7 @@ function snooze_message($mailbox, $msg_id, $folder, $snooze_tag) {
}
}
} else {
- $snooze_headers = parse_snooze_header($matches[0]);
+ $snooze_headers = parse_delayed_header($matches[0], 'X-Snoozed');
$original_folder = $snooze_headers['from'];
if ($mailbox->store_message($original_folder, $msg)) {
$deleteResult = $mailbox->message_action($snooze_folder, 'DELETE', array($msg_id));
@@ -1457,21 +1461,21 @@ function snooze_formats() {
*/
if (!hm_exists('snooze_dropdown')) {
function snooze_dropdown($output, $unsnooze = false) {
- $values = snooze_formats();
+ $values = nexter_formats();
$txt = '
-
-
';
@@ -1728,3 +1732,39 @@ function sortCombinedMessages($list, $sort) {
return $list;
}
+
+if (!hm_exists('save_sent_msg')) {
+function save_sent_msg($handler, $imap_id, $mailbox, $imap_details, $msg, $msg_id, $show_errors = true) {
+ $specials = get_special_folders($handler, $imap_id);
+ if (array_key_exists('sent', $specials) && $specials['sent']) {
+ $sent_folder = $specials['sent'];
+ }
+
+ if (!$sent_folder) {
+ $auto_sent = $mailbox->get_special_use_mailboxes('sent');
+ if (!array_key_exists('sent', $auto_sent)) {
+ return;
+ }
+ $sent_folder = $auto_sent['sent'];
+ }
+ if (!$sent_folder) {
+ Hm_Debug::add(sprintf("Unable to save sent message, no sent folder for server %s %s", $mailbox->server_type(), $imap_details['server']));
+ }
+ $uid = null;
+ if ($sent_folder) {
+ Hm_Debug::add(sprintf("Attempting to save sent message for server %s in folder %s", $mailbox->server_type(), $imap_details['server'], $sent_folder));
+ if (! $mailbox->store_message($sent_folder, $msg)) {
+ Hm_Msgs::add('ERRAn error occurred saving the sent message');
+ }
+
+ $mailbox_page = $mailbox->get_messages($sent_folder, 'ARRIVAL', true, 'ALL', 0, 10);
+ foreach ($mailbox_page[1] as $mail) {
+ $msg_header = $mailbox->get_message_headers($sent_folder, $mail['uid']);
+ if ($msg_header['Message-Id'] === $msg_id) {
+ $uid = $mail['uid'];
+ break;
+ }
+ }
+ }
+ return $uid;
+}}
diff --git a/modules/imap/handler_modules.php b/modules/imap/handler_modules.php
index a172bdac89..97f8eaffdc 100644
--- a/modules/imap/handler_modules.php
+++ b/modules/imap/handler_modules.php
@@ -332,38 +332,9 @@ public function process() {
$sent_folder = false;
$mailbox = Hm_IMAP_List::get_connected_mailbox($imap_id, $this->cache);
if ($mailbox && $mailbox->authed()) {
- $specials = get_special_folders($this, $imap_id);
- if (array_key_exists('sent', $specials) && $specials['sent']) {
- $sent_folder = $specials['sent'];
- }
-
- if (!$sent_folder) {
- $auto_sent = $mailbox->get_special_use_mailboxes('sent');
- if (!array_key_exists('sent', $auto_sent)) {
- return;
- }
- $sent_folder = $auto_sent['sent'];
- }
- if (!$sent_folder) {
- Hm_Debug::add(sprintf("Unable to save sent message, no sent folder for IMAP %s", $imap_details['server']));
- }
- if ($sent_folder) {
- Hm_Debug::add(sprintf("Attempting to save sent message for IMAP server %s in folder %s", $imap_details['server'], $sent_folder));
- if (! $mailbox->store_message($sent_folder, $msg)) {
- Hm_Msgs::add('ERRAn error occurred saving the sent message');
- }
- $uid = null;
- $mailbox_page = $mailbox->get_messages($sent_folder, 'ARRIVAL', true, 'ALL', 0, 10);
- foreach ($mailbox_page[1] as $mail) {
- $msg_header = $mailbox->get_message_headers($sent_folder, $mail['uid']);
- if ($msg_header['Message-Id'] === $mime->get_headers()['Message-Id']) {
- $uid = $mail['uid'];
- break;
- }
- }
- if ($uid && $this->user_config->get('review_sent_email_setting', true)) {
- $this->out('redirect_url', '?page=message&uid='.$uid.'&list_path=imap_'.$imap_id.'_'.bin2hex($sent_folder));
- }
+ $uid = save_sent_msg($this, $imap_id, $mailbox, $imap_details, $msg, $mime->get_headers()['Message-Id']);
+ if ($uid && $this->user_config->get('review_sent_email_setting', false)) {
+ $this->out('redirect_url', '?page=message&uid='.$uid.'&list_path=imap_'.$imap_id.'_'.bin2hex($sent_folder));
}
}
}
@@ -1037,7 +1008,7 @@ public function process() {
$snooze_tag = null;
if ($form['imap_snooze_until'] != 'unsnooze') {
$at = date('D, d M Y H:i:s O');
- $until = get_snooze_date($form['imap_snooze_until']);
+ $until = get_scheduled_date($form['imap_snooze_until']);
$snooze_tag = "X-Snoozed: at $at; until $until";
}
$ids = explode(',', $form['imap_snooze_ids']);
@@ -1088,7 +1059,7 @@ public function process() {
$msg_headers = $mailbox->get_message_headers($folder, $msg['uid']);
if (isset($msg_headers['X-Snoozed'])) {
try {
- $snooze_headers = parse_snooze_header($msg_headers['X-Snoozed']);
+ $snooze_headers = parse_delayed_header($msg_headers['X-Snoozed'], 'X-Snoozed');
if (new DateTime($snooze_headers['until']) <= new DateTime()) {
snooze_message($mailbox, $msg['uid'], $folder, null);
}
@@ -1752,7 +1723,8 @@ public function process() {
'port' => $auth_server['port'],
'tls' => $auth_server['tls'],
'user' => $auth_server['username'],
- 'pass' => $auth_server['password']
+ 'pass' => $auth_server['password'],
+ 'type' => 'imap',
);
if (! empty($auth_server['sieve_config_host'])) {
$imap_details['sieve_config_host'] = $auth_server['sieve_config_host'];
diff --git a/modules/imap/hm-ews.php b/modules/imap/hm-ews.php
index bae8f093b3..80b815066e 100644
--- a/modules/imap/hm-ews.php
+++ b/modules/imap/hm-ews.php
@@ -541,9 +541,12 @@ public function get_message_list($itemIds, $include_preview = false) {
'message_id' => $message->get('internetMessageId'),
'x_auto_bcc' => null,
'x_snoozed' => null,
+ 'x_schedule' => null,
+ 'x_profile_id' => null,
+ 'x_delivery' => null,
];
foreach ($message->get('internetMessageHeaders')->InternetMessageHeader as $header) {
- foreach (['x-gm-msgid' => 'google_msg_id', 'x-gm-thrid' => 'google_thread_id', 'x-gm-labels' => 'google_labels', 'x-auto-bcc' => 'x_auto_bcc', 'message-id' => 'message_id', 'references' => 'references', 'x-snoozed' => 'x_snoozed', 'list-archive' => 'list_archive', 'content-type' => 'content-type', 'x-priority' => 'x-priority'] as $hname => $key) {
+ foreach (['x-gm-msgid' => 'google_msg_id', 'x-gm-thrid' => 'google_thread_id', 'x-gm-labels' => 'google_labels', 'x-auto-bcc' => 'x_auto_bcc', 'message-id' => 'message_id', 'references' => 'references', 'x-snoozed' => 'x_snoozed', 'x-schedule' => 'x_schedule', 'x-profile-id' => 'x_profile_id', 'x-delivery' => 'x_delivery', 'list-archive' => 'list_archive', 'content-type' => 'content-type', 'x-priority' => 'x-priority'] as $hname => $key) {
if (strtolower($header->get('headerName')) == $hname) {
$msg[$key] = (string) $header;
}
diff --git a/modules/imap/hm-imap.php b/modules/imap/hm-imap.php
index b60599f018..c73d53dda1 100644
--- a/modules/imap/hm-imap.php
+++ b/modules/imap/hm-imap.php
@@ -970,7 +970,7 @@ public function get_message_list($uids, $raw=false, $include_content_body = fals
if ($this->is_supported( 'X-GM-EXT-1' )) {
$command .= 'X-GM-MSGID X-GM-THRID X-GM-LABELS ';
}
- $command .= "BODY.PEEK[HEADER.FIELDS (SUBJECT X-AUTO-BCC FROM DATE CONTENT-TYPE X-PRIORITY TO LIST-ARCHIVE REFERENCES MESSAGE-ID X-SNOOZED)]";
+ $command .= "BODY.PEEK[HEADER.FIELDS (SUBJECT X-AUTO-BCC FROM DATE CONTENT-TYPE X-PRIORITY TO LIST-ARCHIVE REFERENCES MESSAGE-ID X-SNOOZED X-SCHEDULE X-PROFILE-ID X-DELIVERY)]";
if ($include_content_body) {
$command .= " BODY.PEEK[0.1]";
}
@@ -984,8 +984,8 @@ public function get_message_list($uids, $raw=false, $include_content_body = fals
$res = $this->get_response(false, true);
$status = $this->check_response($res, true);
$tags = array('X-GM-MSGID' => 'google_msg_id', 'X-GM-THRID' => 'google_thread_id', 'X-GM-LABELS' => 'google_labels', 'UID' => 'uid', 'FLAGS' => 'flags', 'RFC822.SIZE' => 'size', 'INTERNALDATE' => 'internal_date');
- $junk = array('X-AUTO-BCC', 'MESSAGE-ID', 'REFERENCES', 'X-SNOOZED', 'LIST-ARCHIVE', 'SUBJECT', 'FROM', 'CONTENT-TYPE', 'TO', '(', ')', ']', 'X-PRIORITY', 'DATE');
- $flds = array('x-auto-bcc' => 'x_auto_bcc', 'message-id' => 'message_id', 'references' => 'references', 'x-snoozed' => 'x_snoozed', 'list-archive' => 'list_archive', 'date' => 'date', 'from' => 'from', 'to' => 'to', 'subject' => 'subject', 'content-type' => 'content_type', 'x-priority' => 'x_priority', 'body' => 'content_body');
+ $junk = array('X-AUTO-BCC', 'MESSAGE-ID', 'REFERENCES', 'X-SNOOZED', 'X-SCHEDULE', 'X-PROFILE-ID', 'X-DELIVERY', 'LIST-ARCHIVE', 'SUBJECT', 'FROM', 'CONTENT-TYPE', 'TO', '(', ')', ']', 'X-PRIORITY', 'DATE');
+ $flds = array('x-auto-bcc' => 'x_auto_bcc', 'message-id' => 'message_id', 'references' => 'references', 'x-snoozed' => 'x_snoozed', 'x-schedule' => 'x_schedule', 'x-profile-id' => 'x_profile_id', 'x-delivery' => 'x_delivery', 'list-archive' => 'list_archive', 'date' => 'date', 'from' => 'from', 'to' => 'to', 'subject' => 'subject', 'content-type' => 'content_type', 'x-priority' => 'x_priority', 'body' => 'content_body');
$headers = array();
foreach ($res as $n => $vals) {
@@ -1008,6 +1008,9 @@ public function get_message_list($uids, $raw=false, $include_content_body = fals
$google_labels = '';
$x_auto_bcc = '';
$x_snoozed = '';
+ $x_schedule = '';
+ $x_profile_id = '';
+ $x_delivery = '';
$count = count($vals);
for ($i=0;$i<$count;$i++) {
if ($vals[$i] == 'BODY[HEADER.FIELDS') {
@@ -1070,7 +1073,7 @@ public function get_message_list($uids, $raw=false, $include_content_body = fals
'timestamp' => time(), 'charset' => $cset, 'x-priority' => $x_priority, 'google_msg_id' => $google_msg_id,
'google_thread_id' => $google_thread_id, 'google_labels' => $google_labels, 'list_archive' => $list_archive,
'references' => $references, 'message_id' => $message_id, 'x_auto_bcc' => $x_auto_bcc,
- 'x_snoozed' => $x_snoozed);
+ 'x_snoozed' => $x_snoozed, 'x_schedule' => $x_schedule, 'x_profile_id' => $x_profile_id, 'x_delivery' => $x_delivery);
$headers[$uid]['preview_msg'] = $flds['body'] != "content_body" ? $flds['body'] : "";
if ($raw) {
diff --git a/modules/imap/js_modules/route_handlers.js b/modules/imap/js_modules/route_handlers.js
index 7f9d9ab0a4..9e3b00edd1 100644
--- a/modules/imap/js_modules/route_handlers.js
+++ b/modules/imap/js_modules/route_handlers.js
@@ -4,6 +4,8 @@ function applyImapMessageListPageHandlers(routeParams) {
imap_setup_snooze();
imap_setup_tags();
+ processNextActionDate();
+
if (window.inlineMessageMessageListAndSearchPageHandler) inlineMessageMessageListAndSearchPageHandler(routeParams);
if (window.wpMessageListPageHandler) wpMessageListPageHandler(routeParams);
diff --git a/modules/imap/js_modules/utils/handleNexterDateAction.js b/modules/imap/js_modules/utils/handleNexterDateAction.js
new file mode 100644
index 0000000000..201a60f35d
--- /dev/null
+++ b/modules/imap/js_modules/utils/handleNexterDateAction.js
@@ -0,0 +1,55 @@
+function processNextActionDate(e) {
+ let reload_and_redirect = async function () {
+ Hm_Folders.reload_folders(true);
+ let path = getListPathParam();
+ await navigate(`?page=message_list&list_path=${path}`);
+ };
+
+ let collectCheckedIds = function () {
+ let ids = [];
+ $('input[type=checkbox]').each(function () {
+ if (this.checked && this.id.search('imap') !== -1) {
+ let parts = this.id.split('_');
+ ids.push(parts[1] + '_' + parts[2] + '_' + parts[3]);
+ }
+ });
+ if (ids.length === 0) {
+ return;
+ }
+ return ids;
+ };
+
+ setupActionSchedule(function () {
+ let ids = collectCheckedIds();
+
+ Hm_Ajax.request(
+ [
+ { 'name': 'hm_ajax_hook', 'value': 'ajax_re_schedule_message_sending' },
+ { 'name': 'scheduled_msg_ids', 'value': ids },
+ { 'name': 'schedule_date', 'value': $(this).val() }
+ ],
+ function (res) {
+ if (res.scheduled_msg_count > 0) {
+ reload_and_redirect();
+ }
+ }
+ );
+ });
+
+ setupActionSnooze(function () {
+ let ids = collectCheckedIds();
+
+ Hm_Ajax.request(
+ [
+ { 'name': 'hm_ajax_hook', 'value': 'ajax_imap_snooze' },
+ { 'name': 'imap_snooze_ids', 'value': ids },
+ { 'name': 'imap_snooze_until', 'value': $(this).val() }
+ ],
+ function (res) {
+ if (res.snoozed_messages > 0) {
+ reload_and_redirect();
+ }
+ }
+ );
+ });
+}
\ No newline at end of file
diff --git a/modules/imap/output_modules.php b/modules/imap/output_modules.php
index d0128dfdc3..fb58bae0e4 100644
--- a/modules/imap/output_modules.php
+++ b/modules/imap/output_modules.php
@@ -206,9 +206,9 @@ protected function output() {
$txt .= $this->html_safe($value).'';
}
elseif ($fld == 'x-snoozed') {
- $snooze_header = parse_snooze_header($value);
+ $snooze_header = parse_delayed_header($value, 'X-Snoozed');
$txt .= '';
+ $txt .= $this->trans('Snoozed').''.$this->trans('Until').' '.$this->html_safe($snooze_header['until']).' Unsnooze ';
}
elseif ($fld == 'date') {
try {
@@ -390,6 +390,9 @@ protected function output() {
if($this->get('tags')){
$txt .= ' | '. tags_dropdown($this, $headers);
}
+ if (isset($headers['X-Schedule'])) {
+ $txt .= ' | ' . schedule_dropdown($this, true);
+ }
$is_draft = isset($headers['Flags']) && mb_stristr($headers['Flags'], 'draft');
if ($this->get('sieve_filters_enabled') && !$is_draft) {
diff --git a/modules/imap/site.css b/modules/imap/site.css
index f291345bab..d4a3c5ead1 100644
--- a/modules/imap/site.css
+++ b/modules/imap/site.css
@@ -126,7 +126,7 @@
.header_links {
padding-top: 10px !important;
}
-.header_links #dropdownMenuSnooze {
+.header_links #dropdownMenuNexterDate {
padding: 0;
border: unset;
font-variant: inherit;
@@ -134,7 +134,7 @@
font-size: inherit;
vertical-align: baseline;
}
-.header_links #dropdownMenuSnooze:hover {
+.header_links #dropdownMenuNexterDate:hover {
background-color: inherit;
color: inherit;
}
@@ -280,7 +280,8 @@
}
.jmap_section,
.sent_setting,
-.imap_section {
+.imap_section,
+.ews_server_config_section {
display: none;
}
.imap_server_setup .content_title {
diff --git a/modules/profiles/hm-profiles.php b/modules/profiles/hm-profiles.php
index 16997e0582..046d6e6648 100644
--- a/modules/profiles/hm-profiles.php
+++ b/modules/profiles/hm-profiles.php
@@ -109,4 +109,19 @@ public static function loadLegacy($hmod) {
}
}
}
+
+ /**
+ * @param string $field The name of the field to search within.
+ * @param mixed $value The value to search for within the specified field.
+ * @return array An array containing profiles that match the search criteria.
+ */
+ public static function search($field, $value) {
+ $res = array();
+ foreach (self::getAll() as $profile) {
+ if (!empty($profile[$field]) && $profile[$field] == $value) {
+ $res[] = $profile;
+ }
+ }
+ return $res;
+ }
}
diff --git a/modules/smtp/functions.php b/modules/smtp/functions.php
index 68a8db3b16..d3752e6e31 100644
--- a/modules/smtp/functions.php
+++ b/modules/smtp/functions.php
@@ -61,3 +61,91 @@ function get_reply_type($request) {
return false;
}
}
+
+/**
+ * @subpackage smtp/functions
+ */
+if (!hm_exists('send_scheduled_message')) {
+function send_scheduled_message($handler, $imapMailbox, $folder, $msg_id, $send_now = false) {
+ $msg_headers = $imapMailbox->get_message_headers($folder, $msg_id);
+ $mailbox_details = $imapMailbox->get_config();
+ try {
+ if (empty($msg_headers['X-Schedule'])) {
+ return false;
+ }
+
+ if (new DateTime($msg_headers['X-Schedule']) <= new DateTime() || $send_now) {
+ $profile = Hm_Profiles::get($msg_headers['X-Profile-ID']);
+ if (!$profile) {
+ $profiles = Hm_Profiles::search('server', $mailbox_details['server']);
+
+ if (!$profiles) {
+ Hm_Debug::add(sprintf('ERRCannot find profiles corresponding with MAILBOX server: %s', $mailbox_details['server']));
+ return false;
+ }
+ $profile = $profiles[0];
+ }
+ $smtpMailbox = Hm_SMTP_List::connect($profile['smtp_id'], false);
+ if (! $smtpMailbox->authed()) {
+ Hm_Msgs::add("ERRFailed to authenticate to the SMTP server");
+ return;
+ }
+
+ $delivery_receipt = isset($msg_headers['X-Delivery']);
+
+ $recipients = [];
+ foreach (['To', 'Cc', 'Bcc'] as $fld) {
+ if (array_key_exists($fld, $msg_headers)) {
+ $recipients = array_merge($recipients, Hm_MIME_Msg::find_addresses($msg_headers[$fld]));
+ }
+ }
+
+ $msg_content = $imapMailbox->get_message_content($folder, $msg_id, 0);
+ $from = process_address_fld($msg_headers['From']);
+
+ $err_msg = $smtpMailbox->send_message($from[0]['email'], $recipients, $msg_content, $delivery_receipt);
+ if (!$err_msg) {
+ $imapMailbox->delete_message($folder, $msg_id, false);
+ save_sent_msg($handler, $imapMailbox->get_config()['id'], $imapMailbox, $mailbox_details, $msg_content, $msg_id, false);
+ return true;
+ }
+ }
+ } catch (Exception $e) {
+ Hm_Debug::add(sprintf('ERRCannot send message: %s', $msg_headers['subject']));
+ }
+ return false;
+}}
+
+/**
+ * @subpackage smtp/functions
+ */
+if (!hm_exists('reschedule_message_sending')) {
+function reschedule_message_sending($handler, $mailbox, $msg_id, $folder, $new_date) {
+ if ($new_date == 'now') {
+ return send_scheduled_message($handler, $mailbox, $folder, $msg_id, true);
+ }
+ $msg = $mailbox->get_message_content($folder, $msg_id, 0);
+ $new_date = get_scheduled_date($new_date);
+ preg_match("/^X-Schedule:.*(\r?\n[ \t]+.*)*\r?\n?/im", $msg, $matches);
+
+ if (count($matches)) {
+ $msg = str_replace($matches[0], "X-Schedule: {$new_date}\n", $msg);
+ } else {
+ return;
+ }
+ $msg = str_replace("\r\n", "\n", $msg);
+ $msg = str_replace("\n", "\r\n", $msg);
+ $msg = rtrim($msg)."\r\n";
+
+ $schedule_folder = 'Scheduled';
+ if (!count($mailbox->get_folder_status($schedule_folder))) {
+ return;
+ }
+ $res = false;
+ if ($mailbox->store_message($schedule_folder, $msg)) {
+ if ($mailbox->delete_message($folder, $msg_id, false)) {
+ $res = true;
+ }
+ }
+ return $res;
+}}
diff --git a/modules/smtp/hm-mime-message.php b/modules/smtp/hm-mime-message.php
index 74a856c2fb..5329c6a5fe 100644
--- a/modules/smtp/hm-mime-message.php
+++ b/modules/smtp/hm-mime-message.php
@@ -21,10 +21,15 @@ class Hm_MIME_Msg {
private $final_msg = '';
/* build mime message data */
- function __construct($to, $subject, $body, $from, $html=false, $cc='', $bcc='', $in_reply_to_id='', $from_name='', $reply_to='') {
+ function __construct($to, $subject, $body, $from, $html=false, $cc='', $bcc='', $in_reply_to_id='', $from_name='', $reply_to='', $delivery_receipt='', $schedule='', $profile_id = '') {
if ($cc) {
$this->headers['Cc'] = $cc;
}
+ if ($schedule) {
+ $this->headers['X-Schedule'] = $schedule;
+ $this->headers['X-Profile-ID'] = $profile_id;
+ }
+
if ($in_reply_to_id) {
$this->headers['In-Reply-To'] = $in_reply_to_id;
}
@@ -41,6 +46,9 @@ function __construct($to, $subject, $body, $from, $html=false, $cc='', $bcc='',
else {
$this->headers['Reply-To'] = $from;
}
+ if ($delivery_receipt) {
+ $this->headers['X-Delivery'] = $delivery_receipt;
+ }
$this->headers['To'] = $to;
$this->headers['Subject'] = html_entity_decode($subject, ENT_QUOTES);
$this->headers['Date'] = date('r');
@@ -190,7 +198,7 @@ function prep_fld($val, $name) {
return $this->encode_fld($val);
}
- function find_addresses($str) {
+ static function find_addresses($str) {
$res = array();
foreach (process_address_fld($str) as $vals) {
$res[] = $vals['email'];
@@ -210,7 +218,7 @@ function get_recipient_addresses() {
else {
continue;
}
- $res = array_merge($res, $this->find_addresses($v));
+ $res = array_merge($res, self::find_addresses($v));
}
return $res;
}
diff --git a/modules/smtp/js_modules/route_handlers.js b/modules/smtp/js_modules/route_handlers.js
index 5179c5e495..5eb22f5c39 100644
--- a/modules/smtp/js_modules/route_handlers.js
+++ b/modules/smtp/js_modules/route_handlers.js
@@ -2,6 +2,10 @@
function applySmtpComposePageHandlers() {
init_resumable_upload()
+ setupActionSchedule(function () {
+ $('.smtp_send_placeholder').trigger('click');
+ });
+
if (window.HTMLEditor) {
useKindEditor();
}
@@ -109,16 +113,22 @@ function applySmtpComposePageHandlers() {
}
async function handleSendAnyway() {
-
- if ($('.compose_draft_id').val() == '0') {
- Hm_Notices.show([hm_trans('Please wait, sending message...')]);
- await waitForValueChange('.compose_draft_id', '0');
+ if ($('.saving_draft').val() !== '0') {
+ Hm_Notices.show([hm_trans('Please wait, sending message...')]);
+ await waitForValueChange('.saving_draft', '0');
}
-
-
if (handleMissingAttachment()) {
- document.getElementsByClassName("smtp_send")[0].click();
+ if ($('.nexter_input').val()) {
+ save_compose_state(false, true, $('.nexter_input').val(), function(res) {
+ if (res.draft_id) {
+ reset_smtp_form(false);
+ Hm_Notices.show([hm_trans('Operation successful')]);
+ }
+ });
+ } else {
+ document.getElementsByClassName("smtp_send")[0].click();
+ }
} else {
e.preventDefault();
}
diff --git a/modules/smtp/modules.php b/modules/smtp/modules.php
index 6c2b2e41fb..62b1411e8c 100644
--- a/modules/smtp/modules.php
+++ b/modules/smtp/modules.php
@@ -317,6 +317,8 @@ public function process() {
$draft_id = array_key_exists('draft_id', $this->request->post) ? $this->request->post['draft_id'] : false;
$draft_notice = array_key_exists('draft_notice', $this->request->post) ? $this->request->post['draft_notice'] : false;
$uploaded_files = array_key_exists('uploaded_files', $this->request->post) ? $this->request->post['uploaded_files'] : false;
+ $delivery_receipt = array_key_exists('compose_delivery_receipt', $this->request->post) ? $this->request->post['compose_delivery_receipt'] : false;
+ $schedule = array_key_exists('schedule', $this->request->post) ? $this->request->post['schedule'] : '';
if (array_key_exists('delete_uploaded_files', $this->request->post) && $this->request->post['delete_uploaded_files']) {
delete_uploaded_files($this->session, $draft_id);
@@ -333,7 +335,7 @@ public function process() {
if ($this->get('save_draft_to_imap') === false) {
$from = isset($profile) ? $profile['replyto'] : '';
$name = isset($profile) ? $profile['name'] : '';
- $mime = prepare_draft_mime($msg_attrs, $uploaded_files, $from, $name);
+ $mime = prepare_draft_mime($msg_attrs, $uploaded_files, $from, $name, $profile['id']);
$this->out('draft_mime', $mime);
return;
}
@@ -343,15 +345,20 @@ public function process() {
foreach($uploaded_files as $key => $file) {
$uploaded_files[$key] = $this->config->get('attachment_dir').DIRECTORY_SEPARATOR.$userpath.DIRECTORY_SEPARATOR.$file;
}
- $new_draft_id = save_imap_draft($msg_attrs, $draft_id, $this->session, $this, $this->cache, $uploaded_files, $profile);
+ $new_draft_id = save_imap_draft(array('draft_smtp' => $smtp, 'draft_to' => $to, 'draft_body' => $body,
+ 'draft_subject' => $subject, 'draft_cc' => $cc, 'draft_bcc' => $bcc,
+ 'draft_in_reply_to' => $inreplyto, 'delivery_receipt' => $delivery_receipt, 'schedule' => $schedule), $draft_id, $this->session,
+ $this, $this->cache, $uploaded_files, $profile);
if ($new_draft_id >= 0) {
if ($draft_notice) {
- Hm_Msgs::add('Draft saved');
+ $msg = $schedule ? 'Message scheduled to be sent later' : 'Draft saved';
+ Hm_Msgs::add($msg);
}
$this->out('draft_id', $new_draft_id);
}
elseif ($draft_notice) {
- Hm_Msgs::add('ERRUnable to save draft');
+ $msg = $schedule ? 'Something went wrong when scheduling draft' : 'Unable to save draft';
+ Hm_Msgs::add('ERR' . $msg);
}
return;
}
@@ -550,8 +557,8 @@ public function process() {
}
$imap_profile = Hm_IMAP_List::fetch($profile['user'], $profile['server']);
$specials = get_special_folders($this, $imap_profile['id']);
- if (!array_key_exists('sent', $specials) || !$specials['sent']) {
- Hm_Msgs::add('ERRPlease configure a sent folder for this IMAP account');
+ if ($imap_profile && (!array_key_exists('sent', $specials) || !$specials['sent'])) {
+ Hm_Msgs::add('ERRPlease configure a sent folder for account ' . $imap_profile['name']);
}
}
}
@@ -662,6 +669,9 @@ public function process() {
'draft_subject' => $form['compose_subject'],
'draft_smtp' => $smtp_id
);
+ $delivery_receipt = !empty($this->request->post['compose_delivery_receipt']);
+ $from_params = '';
+ $recipients_params = '';
/* parse attachments */
$uploaded_files = [];
@@ -706,7 +716,7 @@ public function process() {
}
/* build message */
- $mime = new Hm_MIME_Msg($to, $subject, $body, $from, $body_type, $cc, $bcc, $in_reply_to, $from_name, $reply_to);
+ $mime = new Hm_MIME_Msg($to, $subject, $body, $from, $body_type, $cc, $bcc, $in_reply_to, $from_name, $reply_to, $delivery_receipt);
/* add attachments */
$mime->add_attachments($uploaded_files);
@@ -1149,6 +1159,7 @@ protected function output() {
' '.
' '.
' '.
+ ' '.
' '.
''.
@@ -1242,7 +1253,13 @@ protected function output() {
$res .= ''.
smtp_server_dropdown($this->module_output(), $this, $recip, $selected_id).
- '
'.$this->trans('Send').' ';
+ '
+ '.$this->trans('Send').'
+
+ Toggle Dropdown
+ '.
+ schedule_dropdown($this).
+ '
';
if ($this->get('list_path') && ($reply_type == 'reply' || $reply_type == 'reply_all')) {
$res .= '
';
@@ -1540,6 +1557,104 @@ protected function output() {
}
}
+/**
+ * Send scheduled messages
+ * @subpackage smtp/handler
+ */
+class Hm_Handler_send_scheduled_messages extends Hm_Handler_Module {
+ /**
+ * Send delayed messages
+ * This should use cron
+ */
+ public function process() {
+ if (!($this->module_is_supported('imap') || $this->module_is_supported('profiles'))) {
+ return;
+ }
+
+ $servers = Hm_IMAP_List::dumpForMailbox();
+ $scheduled_msg_count = 0;
+
+ foreach ($servers as $server_id => $config) {
+ $mailbox = new Hm_Mailbox($server_id, $this->user_config, $this->session, $config);
+ if ($mailbox->connect()) {
+ $folder = 'Scheduled';
+ $ret = $mailbox->get_messages($folder, 'DATE', false, 'ALL');
+ foreach ($ret[1] as $msg) {
+ $msg_headers = $mailbox->get_message_headers($folder, $msg['uid']);
+ if (! empty($msg_headers['X-Schedule'])) {
+ $scheduled_msg_count++;
+ } else {
+ continue;
+ }
+ if (send_scheduled_message($this, $mailbox, $folder, $msg['uid'])) {
+ $scheduled_msg_count++;
+ }
+ }
+ }
+ }
+
+ $this->out('scheduled_msg_count', $scheduled_msg_count);
+ }
+}
+
+/**
+ * Changes the schedule of the message
+ * @subpackage smtp/handler
+ */
+class Hm_Handler_re_schedule_message_sending extends Hm_Handler_Module {
+ public function process() {
+ if (!($this->module_is_supported('imap') || $this->module_is_supported('profiles'))) {
+ return;
+ }
+ list($success, $form) = $this->process_form(array('schedule_date', 'scheduled_msg_ids'));
+ if (!$success) {
+ return;
+ }
+ $scheduled_msg_count = 0;
+ $new_schedule_date = $form['schedule_date'];
+ if ($form['schedule_date'] != 'now') {
+ $new_schedule_date = get_scheduled_date($form['schedule_date']);
+ }
+ $ids = explode(',', $form['scheduled_msg_ids']);
+ foreach ($ids as $msg_part) {
+ list($imap_server_id, $msg_id, $folder) = explode('_', $msg_part);
+ $imap_server = Hm_IMAP_List::getForMailbox($imap_server_id);
+
+ $mailbox = new Hm_Mailbox($imap_server_id, $this->user_config, $this->session, $imap_server);
+ if ($mailbox->connect()) {
+ $folder = hex2bin($folder);
+ if (reschedule_message_sending($this, $mailbox, $msg_id, $folder, $new_schedule_date)) {
+ $scheduled_msg_count++;
+ }
+ }
+ }
+ $this->out('scheduled_msg_count', $scheduled_msg_count);
+ if ($scheduled_msg_count == count($ids)) {
+ $msg = 'Operation successful';
+ } elseif ($scheduled_msg_count > 0) {
+ $msg = 'Some messages have been scheduled for sending';
+ } else {
+ $msg = 'ERRFailed to schedule sending for messages';
+ }
+ Hm_Msgs::add($msg);
+ $this->save_hm_msgs();
+ }
+}
+
+/**
+ * Add scheduled send to the message list controls
+ * @subpackage imap/output
+ */
+class Hm_Output_scheduled_send_msg_control extends Hm_Output_Module {
+ protected function output() {
+ $parts = explode('_', $this->get('list_path'));
+ if ($parts[0] == 'imap' && hex2bin($parts[2]) == 'Scheduled') {
+ $res = schedule_dropdown($this, true);
+ $this->concat('msg_controls_extra', $res);
+ }
+ }
+}
+
/**
* @subpackage smtp/functions
*/
@@ -1768,19 +1883,17 @@ function delete_draft($id, $cache, $imap_server_id, $folder) {
*/
if (!hm_exists('find_imap_by_smtp')) {
function find_imap_by_smtp($imap_profiles, $smtp_profile) {
- $id = 0;
foreach ($imap_profiles as $profile) {
if ($smtp_profile['user'] == $profile['user']) {
- return array_merge(['id' => $id], $profile);
+ return $profile;
}
if (explode('@', $smtp_profile['user'])[0]
== explode('@', $profile['user'])[0]) {
- return array_merge(['id' => $id], $profile);
+ return $profile;
}
if ($smtp_profile['user'] == $profile['name']) {
- return array_merge(['id' => $id], $profile);
+ return $profile;
}
- $id++;
}
}}
@@ -1875,10 +1988,8 @@ function get_uploaded_files_from_array($uploaded_files) {
}
}
-function prepare_draft_mime($atts, $uploaded_files, $from = false, $name = '') {
- if (! empty($uploaded_files) && ! is_array($uploaded_files[0])) {
- $uploaded_files = get_uploaded_files_from_array($uploaded_files);
- }
+function prepare_draft_mime($atts, $uploaded_files, $from = false, $name = '', $profile_id = null) {
+ $uploaded_files = get_uploaded_files_from_array($uploaded_files);
$mime = new Hm_MIME_Msg(
$atts['draft_to'],
$atts['draft_subject'],
@@ -1889,7 +2000,10 @@ function prepare_draft_mime($atts, $uploaded_files, $from = false, $name = '') {
$atts['draft_bcc'],
'',
$name,
- $atts['draft_in_reply_to']
+ $atts['draft_in_reply_to'],
+ $atts['delivery_receipt'],
+ $atts['schedule'],
+ $profile_id
);
$mime->add_attachments($uploaded_files);
@@ -1912,7 +2026,6 @@ function save_imap_draft($atts, $id, $session, $mod, $mod_cache, $uploaded_files
$name = $profile['name'];
$imap_profile = Hm_IMAP_List::fetch($profile['user'], $profile['server']);
}
-
if (!$imap_profile || empty($imap_profile)) {
$imap_profile = find_imap_by_smtp(
$mod->user_config->get('imap_servers'),
@@ -1922,43 +2035,59 @@ function save_imap_draft($atts, $id, $session, $mod, $mod_cache, $uploaded_files
$from = $mod->user_config->get('smtp_servers')[$atts['draft_smtp']]['user'];
}
}
- if (!$imap_profile || empty($imap_profile)) {
+ if (empty($imap_profile)) {
return -1;
}
+ $imap_profile = Hm_IMAP_List::getForMailbox($imap_profile['id']);
$specials = get_special_folders($mod, $imap_profile['id']);
- if (!array_key_exists('draft', $specials) || !$specials['draft']) {
+ if ((!array_key_exists('draft', $specials) || !$specials['draft']) && !array_key_exists('schedule', $atts)) {
Hm_Msgs::add('ERRThere is no draft directory configured for this account.');
return -1;
}
- $mailbox = Hm_IMAP_List::get_connected_mailbox($imap_profile['id'], $mod_cache);
- if (! $mailbox || ! $mailbox->authed()) {
+ $mailbox = new Hm_Mailbox($imap_profile['id'], $mod->user_config, $session, $imap_profile);
+ if (! $mailbox->connect()) {
return -1;
}
+
+ if (!empty($atts['schedule'])) {
+ $folder ='Scheduled';
+ if (!count($mailbox->get_folder_status($folder))) {
+ $mailbox->create_folder($folder);
+ }
+ $atts['schedule'] = get_scheduled_date($atts['schedule']);
+ } else {
+ $folder = $specials['draft'];
+ }
- $mime = prepare_draft_mime($atts, $uploaded_files, $from, $name);
+ $mime = prepare_draft_mime($atts, $uploaded_files, $from, $name, $profile['id']);
$res = $mime->process_attachments();
+ if (! empty($atts['schedule']) && empty($mime->get_recipient_addresses())) {
+ Hm_Msgs::add("ERRNo valid recipients found");
+ return -1;
+ }
+
$msg = str_replace("\r\n", "\n", $mime->get_mime_msg());
$msg = str_replace("\n", "\r\n", $msg);
$msg = rtrim($msg)."\r\n";
- if (! $mailbox->store_message($specials['draft'], $msg, false, true)) {
+ if (! $mailbox->store_message($folder, $msg, false, true)) {
Hm_Msgs::add('ERRAn error occurred saving the draft message');
return -1;
}
- $messages = $mailbox->get_messages($specials['draft'], 'ARRIVAL', true, 'DRAFT', 0, 10);
+ $messages = $mailbox->get_messages($folder, 'ARRIVAL', true, 'DRAFT', 0, 10);
// Remove old version from the mailbox
if ($id) {
- $mailbox->message_action($specials['draft'], 'DELETE', array($id));
- $mailbox->message_action($specials['draft'], 'EXPUNGE', array($id));
+ $mailbox->message_action($folder, 'DELETE', array($id));
+ $mailbox->message_action($folder, 'EXPUNGE', array($id));
}
foreach ($messages[1] as $mail) {
- $msg_header = $mailbox->get_message_headers($specials['draft'], $mail['uid']);
+ $msg_header = $mailbox->get_message_headers($folder, $mail['uid']);
// Convert all header keys to lowercase
$msg_header_lower = array_change_key_case($msg_header, CASE_LOWER);
$mime_headers_lower = array_change_key_case($mime->get_headers(), CASE_LOWER);
diff --git a/modules/smtp/setup.php b/modules/smtp/setup.php
index 8d1cb62fb3..4ea4455e54 100644
--- a/modules/smtp/setup.php
+++ b/modules/smtp/setup.php
@@ -22,6 +22,7 @@
add_handler('compose', 'load_smtp_is_imap_forward_as_attachment', true, 'smtp', 'load_user_data', 'after');
add_handler('compose', 'load_smtp_is_imap_forward', true, 'smtp', 'load_smtp_is_imap_forward_as_attachment', 'after');
+
add_handler('functional_api', 'default_smtp_server', true, 'smtp');
add_handler('profiles', 'load_smtp_servers_from_config', true, 'smtp', 'load_user_data', 'after');
@@ -103,6 +104,20 @@
add_handler('settings', 'process_enable_compose_delivery_receipt_setting', true, 'core', 'save_user_settings', 'before');
add_output('settings', 'enable_compose_delivery_receipt_setting', true, 'core', 'start_general_settings', 'after');
+/* send delayed emails */
+setup_base_ajax_page('ajax_send_scheduled_messages', 'core');
+add_handler('ajax_send_scheduled_messages', 'load_imap_servers_from_config', true, 'imap', 'load_user_data', 'after');
+add_handler('ajax_send_scheduled_messages', 'load_smtp_servers_from_config', true, 'smtp', 'load_user_data', 'after');
+add_handler('ajax_send_scheduled_messages', 'compose_profile_data', true, 'profiles');
+add_handler('ajax_send_scheduled_messages', 'send_scheduled_messages', true, 'smtp');
+
+setup_base_ajax_page('ajax_re_schedule_message_sending', 'core');
+add_handler('ajax_re_schedule_message_sending', 'load_imap_servers_from_config', true, 'imap', 'load_user_data', 'after');
+add_handler('ajax_re_schedule_message_sending', 'load_smtp_servers_from_config', true, 'smtp', 'load_user_data', 'after');
+add_handler('ajax_re_schedule_message_sending', 'compose_profile_data', true, 'profiles');
+add_handler('ajax_re_schedule_message_sending', 're_schedule_message_sending', true, 'smtp');
+
+add_output('message_list', 'scheduled_send_msg_control', true, 'smtp', 'imap_custom_controls', 'after');
return array(
'allowed_pages' => array(
@@ -113,7 +128,9 @@
'ajax_profiles_status',
'ajax_attachment_reminder_check',
'ajax_get_test_chunk',
- 'ajax_upload_chunk'
+ 'ajax_upload_chunk',
+ 'ajax_send_scheduled_messages',
+ 'ajax_re_schedule_message_sending'
),
'allowed_get' => array(
'imap_draft' => FILTER_VALIDATE_INT,
@@ -146,9 +163,13 @@
'msg_sent_and_archived' => array(FILTER_VALIDATE_BOOLEAN, false),
'sent_msg_id' => array(FILTER_VALIDATE_BOOLEAN, false),
'enable_attachment_reminder' => array(FILTER_VALIDATE_BOOLEAN, false),
+ 'scheduled_msg_count' => array(FILTER_VALIDATE_INT, false),
),
'allowed_post' => array(
'post_archive' => FILTER_VALIDATE_INT,
+ 'send_tomorrow_morning' => FILTER_DEFAULT,
+ 'send_today_afternoon' => FILTER_DEFAULT,
+ 'schedule_sending' => FILTER_DEFAULT,
'attachment_id' => FILTER_DEFAULT,
'smtp_compose_type' => FILTER_VALIDATE_INT,
'new_smtp_name' => FILTER_DEFAULT,
@@ -187,6 +208,9 @@
'uploaded_files' => FILTER_DEFAULT,
'send_uploaded_files' => FILTER_DEFAULT,
'next_email_post' => FILTER_DEFAULT,
- 'enable_attachment_reminder' => FILTER_VALIDATE_INT
+ 'enable_attachment_reminder' => FILTER_VALIDATE_INT,
+ 'schedule' => FILTER_DEFAULT,
+ 'schedule_date' => FILTER_DEFAULT,
+ 'scheduled_msg_ids' => FILTER_DEFAULT,
)
);
diff --git a/modules/smtp/site.js b/modules/smtp/site.js
index 67db768f89..edbb1026f7 100644
--- a/modules/smtp/site.js
+++ b/modules/smtp/site.js
@@ -28,7 +28,7 @@ var smtp_test_action = function(event) {
false,
{'smtp_connect': 1}
);
-};
+};
var smtp_delete_action = function(event) {
if (!hm_delete_prompt()) {
@@ -69,7 +69,7 @@ var send_archive = function() {
document.getElementsByClassName("smtp_send_placeholder")[0].click();
}
-var save_compose_state = function(no_files, notice) {
+var save_compose_state = function(no_files, notice, schedule, callback) {
var no_icon = true;
if (notice) {
no_icon = false;
@@ -82,6 +82,7 @@ var save_compose_state = function(no_files, notice) {
var cc = $('.compose_cc').val();
var bcc = $('.compose_bcc').val();
var inreplyto = $('.compose_in_reply_to').val();
+ var delivery_receipt = $('#compose_delivery_receipt').prop('checked');
var draft_id = $('.compose_draft_id').val();
if (globals.draft_state == body+subject+to+smtp+cc+bcc+uploaded_files) {
@@ -92,9 +93,8 @@ var save_compose_state = function(no_files, notice) {
if (!body && !subject && !to && !cc && !bcc) {
return;
}
- $('.compose_draft_id').val(0)
- Hm_Ajax.request(
- [{'name': 'hm_ajax_hook', 'value': 'ajax_smtp_save_draft'},
+ $('.saving_draft').val(1);
+ Hm_Ajax.request([{'name': 'hm_ajax_hook', 'value': 'ajax_smtp_save_draft'},
{'name': 'draft_body', 'value': body},
{'name': 'draft_id', 'value': draft_id},
{'name': 'draft_smtp', 'value': smtp},
@@ -105,17 +105,28 @@ var save_compose_state = function(no_files, notice) {
{'name': 'draft_in_reply_to', 'value': inreplyto},
{'name': 'delete_uploaded_files', 'value': no_files},
{'name': 'draft_to', 'value': to},
- {'name': 'uploaded_files', 'value': uploaded_files}],
+ {'name': 'uploaded_files', 'value': uploaded_files},
+ {'name': 'schedule', 'value': schedule ?? ''},
+ {'name': 'compose_delivery_receipt', 'value': delivery_receipt ?? ''}],
function(res) {
+ $('.saving_draft').val(0);
if (res.draft_id) {
$('.compose_draft_id').val(res.draft_id);
}
if (res.draft_subject) {
$('.draft_list .draft_'+draft_id+' a').text(res.draft_subject);
}
+
+ if (callback) {
+ callback(res);
+ }
},
[],
- no_icon
+ no_icon,
+ false,
+ function () {
+ $('.saving_draft').val(0);
+ }
);
};
@@ -138,7 +149,7 @@ function smtpServersPageHandler() {
}
}
-var reset_smtp_form = function() {
+var reset_smtp_form = function(save = true) {
$('.compose_body').val('');
$('.compose_subject').val('');
$('.compose_to').val('');
@@ -146,7 +157,10 @@ var reset_smtp_form = function() {
$('.compose_bcc').val('');
$('.ke-content', $('iframe').contents()).html('');
$('.uploaded_files').html('');
- save_compose_state(true);
+ $('#compose_delivery_receipt').prop('checked', false);
+ if (save) {
+ save_compose_state(true);
+ }
};
var replace_cursor_positon = function (txtElement) {
@@ -375,3 +389,25 @@ function smtpSettingsPageHandler() {
);
});
}
+
+$(function() {
+ if (hm_is_logged()) {
+ let scheduled_msg_count = 0;
+ let sendScheduledMessages = function() {
+ Hm_Ajax.request(
+ [{'name': 'hm_ajax_hook', 'value': 'ajax_send_scheduled_messages'}],
+ function(res) {
+ scheduled_msg_count = res.scheduled_msg_count;
+ },
+ );
+ }
+
+ sendScheduledMessages();
+ setInterval(sendScheduledMessages, 60000);
+ window.onbeforeunload = (e) => {
+ if (scheduled_msg_count > 0 && e.currentTarget.location.hostname !== document.location.hostname) {
+ return sprintf(hm_trans("You have %d scheduled messages that won\'t be executed if you quit"), scheduled_msg_count);
+ }
+ };
+ }
+});
\ No newline at end of file