Skip to content

Commit

Permalink
[ENH] add functionality to send later scheduled sending
Browse files Browse the repository at this point in the history
  • Loading branch information
amaninyumu1 authored and Baraka24 committed Aug 2, 2024
1 parent 038a0da commit cf0574d
Show file tree
Hide file tree
Showing 32 changed files with 657 additions and 115 deletions.
1 change: 1 addition & 0 deletions language/az.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions language/de.php
Original file line number Diff line number Diff line change
Expand Up @@ -629,4 +629,5 @@
'Junk' => false,
'Trash' => false,
'Pasted text has leading or trailing spaces' => false,
'You have %d scheduled messages that won\'t be executed if you quit' => false,
);
2 changes: 1 addition & 1 deletion language/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,6 @@
'Are you sure you want to send this message?' => false,
'IMAP and JMAP Servers' => false,
'Junk' => false,
'Trash' => false,
'Pasted text has leading or trailing spaces' => false,
'You have %d scheduled messages that won\'t be executed if you quit' => false
);
1 change: 1 addition & 0 deletions language/es.php
Original file line number Diff line number Diff line change
Expand Up @@ -629,4 +629,5 @@
'Junk' => false,
'Trash' => false,
'Pasted text has leading or trailing spaces' => false,
'You have %d scheduled messages that won\'t be executed if you quit' => false,
);
1 change: 1 addition & 0 deletions language/et.php
Original file line number Diff line number Diff line change
Expand Up @@ -637,4 +637,5 @@
'Junk' => false,
'Trash' => false,
'Pasted text has leading or trailing spaces' => false,
'You have %d scheduled messages that won\'t be executed if you quit' => false,
);
2 changes: 1 addition & 1 deletion language/fa.php
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,6 @@
'Are you sure you want to send this message?' => false,
'IMAP and JMAP Servers' => false,
'Junk' => false,
'Trash' => false,
'Pasted text has leading or trailing spaces' => false,
'You have %d scheduled messages that won\'t be executed if you quit' => false,
);
1 change: 1 addition & 0 deletions language/fr.php
Original file line number Diff line number Diff line change
Expand Up @@ -628,4 +628,5 @@
'Junk' => false,
'Trash' => false,
'Pasted text has leading or trailing spaces' => false,
'You have %d scheduled messages that won\'t be executed if you quit' => false,
);
1 change: 1 addition & 0 deletions language/hu.php
Original file line number Diff line number Diff line change
Expand Up @@ -629,4 +629,5 @@
'Junk' => false,
'Trash' => false,
'Pasted text has leading or trailing spaces' => false,
'You have %d scheduled messages that won\'t be executed if you quit' => false,
);
1 change: 1 addition & 0 deletions language/id.php
Original file line number Diff line number Diff line change
Expand Up @@ -636,4 +636,5 @@
'Junk' => false,
'Trash' => false,
'Pasted text has leading or trailing spaces' => false,
'You have %d scheduled messages that won\'t be executed if you quit' => false,
);
1 change: 1 addition & 0 deletions language/it.php
Original file line number Diff line number Diff line change
Expand Up @@ -629,4 +629,5 @@
'Junk' => false,
'Trash' => false,
'Pasted text has leading or trailing spaces' => false,
'You have %d scheduled messages that won\'t be executed if you quit' => false,
);
1 change: 1 addition & 0 deletions language/ja.php
Original file line number Diff line number Diff line change
Expand Up @@ -629,4 +629,5 @@
'Junk' => false,
'Trash' => false,
'Pasted text has leading or trailing spaces' => false,
'You have %d scheduled messages that won\'t be executed if you quit' => false,
);
1 change: 1 addition & 0 deletions language/nl.php
Original file line number Diff line number Diff line change
Expand Up @@ -629,4 +629,5 @@
'Junk' => false,
'Trash' => false,
'Pasted text has leading or trailing spaces' => false,
'You have %d scheduled messages that won\'t be executed if you quit' => false,
);
1 change: 1 addition & 0 deletions language/pt-BR.php
Original file line number Diff line number Diff line change
Expand Up @@ -628,4 +628,5 @@
'Junk' => false,
'Trash' => false,
'Pasted text has leading or trailing spaces' => false,
'You have %d scheduled messages that won\'t be executed if you quit' => false,
);
1 change: 1 addition & 0 deletions language/ro.php
Original file line number Diff line number Diff line change
Expand Up @@ -628,4 +628,5 @@
'Junk' => false,
'Trash' => false,
'Pasted text has leading or trailing spaces' => false,
'You have %d scheduled messages that won\'t be executed if you quit' => false,
);
1 change: 1 addition & 0 deletions language/ru.php
Original file line number Diff line number Diff line change
Expand Up @@ -630,4 +630,5 @@
'Junk' => false,
'Trash' => false,
'Pasted text has leading or trailing spaces' => false,
'You have %d scheduled messages that won\'t be executed if you quit' => false,
);
1 change: 1 addition & 0 deletions language/zh-Hans.php
Original file line number Diff line number Diff line change
Expand Up @@ -650,4 +650,5 @@
'Junk' => '垃圾',
'Trash' => '已删除',
'Pasted text has leading or trailing spaces' => false,
'You have %d scheduled messages that won\'t be executed if you quit' => false,
);
99 changes: 99 additions & 0 deletions modules/core/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -607,3 +607,102 @@ function get_special_folders($mod, $id) {
}
return array();
}

/**
* @subpackage core/functions
*/
if (!hm_exists('get_nexter_date')) {
function get_nexter_date($format, $only_label = false) {
if ($format == 'later_in_day') {
$date_string = 'today 18:00';
$label = 'Later in the day';
} elseif ($format == 'tomorrow') {
$date_string = '+1 day 08:00';
$label = 'Tomorrow';
} elseif ($format == 'next_weekend') {
$date_string = 'next Saturday 08:00';
$label = 'Next weekend';
} elseif ($format == 'next_week') {
$date_string = 'next week 08:00';
$label = 'Next week';
} elseif ($format == 'next_month') {
$date_string = 'next month 08:00';
$label = 'Next month';
} else {
$date_string = $format;
$label = 'Certain date';
}
$time = strtotime($date_string);
if ($only_label) {
return [$label, date('D, H:i', $time)];
}
return date('D, d M Y H:i', $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 .= '<div class="dropdown d-inline-block">
<button type="button" class="btn btn-light btn-sm dropdown-toggle" id="dropdownMenuNexterDate" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="true">'.$output->trans('Schedule sending').'</button>';
}
$txt .= '<ul class="dropdown-menu nexter_dropdown schedule_dropdown" aria-labelledby="dropdownMenuNexterDate">';
foreach ($values as $format) {
$labels = get_nexter_date($format, true);
$txt .= '<li><a href="#" class="nexter_date_helper dropdown-item d-flex justify-content-between gap-5" data-value="'.$format.'"><span>'.$output->trans($labels[0]).'</span> <span class="text-end">'.$labels[1].'</span></a></li>';
}
$txt .= '<li><hr class="dropdown-divider"></li>';
$txt .= '<li><label for="nexter_input_date" class="nexter_date_picker dropdown-item cursor-pointer">'.$output->trans('Pick a date').'</label>';
$txt .= '<input id="nexter_input_date" type="datetime-local" min="'.date('Y-m-d\Th:m').'" class="nexter_input_date" style="visibility: hidden; position: absolute; height: 0;">';
$txt .= '<input class="nexter_input" style="display:none;"></li>';
if ($send_now) {
$txt .= '<li><hr class="dropdown-divider"></li>';
$txt .= '<li><a href="#" data-value="now" class="nexter_date_helper dropdown-item"">'.$output->trans('Send now').'</a></li>';
}
$txt .= '</ul>';
if ($send_now) {
$txt .= '</div>';
}

return $txt;
}}

/**
* @subpackage imap/functions
*/
if (!hm_exists('parse_nexter_header')) {
function parse_nexter_header($header, $name)
{
$header = str_replace("$name: ", '', $header);
$result = [];
foreach (explode(';', $header) as $kv)
{
$kv = trim($kv);
$spacePos = strpos($kv, ' ');
if ($spacePos > 0) {
$result[rtrim(substr($kv, 0, $spacePos), ':')] = trim(substr($kv, $spacePos+1));
} else {
$result[$kv] = true;
}
}
return $result;
}}
6 changes: 3 additions & 3 deletions modules/core/message_list_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,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': '';
$nexter_class = isset($vals[2]) && $vals[2]? ' nexter_date': '';
if ($style == 'news') {
return sprintf('<div class="msg_date%s">%s<input type="hidden" class="msg_timestamp" value="%s" /></div>', $snooze_class, $output_mod->html_safe($vals[0]), $output_mod->html_safe($vals[1]));
return sprintf('<div class="msg_date%s">%s<input type="hidden" class="msg_timestamp" value="%s" /></div>', $nexter_class, $output_mod->html_safe($vals[0]), $output_mod->html_safe($vals[1]));
}
return sprintf('<td class="msg_date%s" title="%s">%s<input type="hidden" class="msg_timestamp" value="%s" /></td>', $snooze_class, $output_mod->html_safe(date('r', $vals[1])), $output_mod->html_safe($vals[0]), $output_mod->html_safe($vals[1]));
return sprintf('<td class="msg_date%s" title="%s">%s<input type="hidden" class="msg_timestamp" value="%s" /></td>', $nexter_class, $output_mod->html_safe(date('r', $vals[1])), $output_mod->html_safe($vals[0]), $output_mod->html_safe($vals[1]));
}}

/**
Expand Down
2 changes: 1 addition & 1 deletion modules/core/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ div.unseen,
.mobile .imap_sort {
width: 100%;
}
.snoozed_date {
.nexter_date {
color: var(--bs-primary) !important;
}

Expand Down
49 changes: 44 additions & 5 deletions modules/core/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -1944,10 +1944,23 @@ var imap_smtp_edit_action = function(event) {
}
};


var hasLeadingOrTrailingSpaces = function(str) {
return str !== str.trim();
};

var sprintf = function(format, ...args) {
let i = 0;
return format.replace(/%([sd])/g, (match, type) => {
let arg = args[i++];
switch (type) {
case 's': return String(arg);
case 'd': return Number(arg);
default: return match;
}
});
}

/* create a default message list object */
var Hm_Message_List = new Message_List();

Expand Down Expand Up @@ -1980,7 +1993,7 @@ $(function() {

/* fire up the job scheduler */
Hm_Timer.fire();

/* show any pending notices */
Hm_Utils.show_sys_messages();

Expand Down Expand Up @@ -2010,7 +2023,7 @@ $(function() {
}
if (hm_page_name() == 'servers') {
$('.edit_server_connection').on('click', imap_smtp_edit_action);
}
}
if (hm_mobile()) {
swipe_event(document.body, function() { Hm_Folders.open_folder_list(); }, 'right');
swipe_event(document.body, function() { Hm_Folders.hide_folder_list(); }, 'left');
Expand Down Expand Up @@ -2368,7 +2381,7 @@ function handleSmtpImapCheckboxChange(checkbox) {
if ($('#srv_setup_stepper_is_sender').prop('checked') && $('#srv_setup_stepper_is_receiver').prop('checked')) {
$('#srv_setup_stepper_profile_bloc').show();
$('#srv_setup_stepper_profile_checkbox_bloc').show();

} else if(! $('#srv_setup_stepper_is_sender').prop('checked') || ! $('#srv_setup_stepper_is_receiver').prop('checked')) {
$('#srv_setup_stepper_profile_bloc').hide();
$('#srv_setup_stepper_profile_checkbox_bloc').hide();
Expand Down Expand Up @@ -2420,7 +2433,7 @@ function display_config_step(stepNumber) {
$(`#${item.key}-error`).text('Required');
isValid = false;
}

} else {
$(`#${item.key}-error`).text('');
}
Expand Down Expand Up @@ -2698,7 +2711,7 @@ const observeMessageTextMutationAndHandleExternalResources = (inline) => {
if (mutation.addedNodes.length > 0) {
mutation.addedNodes.forEach(function (node) {
if (node.classList.contains('msg_text_inner')) {
handleExternalResources(inline);
handleExternalResources(inline);
}
});
}
Expand All @@ -2708,3 +2721,29 @@ const observeMessageTextMutationAndHandleExternalResources = (inline) => {
});
}
};

var setup_nexter_date = function(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) {
if ($(this).val() && new Date().getTime() < new Date($(this).val()).getTime()) {
$('.nexter_input').val($(this).val()).trigger('change');
}
});
$(document).on('change', '.nexter_input', callback);
}
Loading

0 comments on commit cf0574d

Please sign in to comment.