Skip to content

Commit

Permalink
feat(backend): Removing SMTP connections using the Mailbox class
Browse files Browse the repository at this point in the history
  • Loading branch information
amaninyumu1 committed Jan 29, 2025
1 parent 96ce315 commit 4264295
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions modules/imap/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1668,32 +1668,32 @@ function flattenMessagesLists($messagesLists, $listSize) {
}

if (!hm_exists('save_sent_msg')) {
function save_sent_msg($handler, $imap_id, $imap, $imap_details, $msg, $msg_id, $show_errors = true) {
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 = $imap->get_special_use_mailboxes('sent');
$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']));
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 IMAP server %s in folder %s", $imap_details['server'], $sent_folder));
if (! $imap->store_message($sent_folder, $msg)) {
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 = $imap->get_messages($sent_folder, 'ARRIVAL', true, 'ALL', 0, 10);
foreach ($mailbox_page[1] as $mail) {
$msg_header = $imap->get_message_headers($sent_folder, $mail['uid']);
$msg_header = $mailbox->get_message_headers($sent_folder, $mail['uid']);
if ($msg_header['Message-Id'] === $msg_id) {
$uid = $mail['uid'];
break;
Expand Down
8 changes: 4 additions & 4 deletions modules/smtp/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ function get_reply_type($request) {
if (!hm_exists('send_scheduled_message')) {
function send_scheduled_message($handler, $mailbox, $folder, $msg_id, $send_now = false) {
$msg_headers = $mailbox->get_message_headers($folder, $msg_id);
$mailbox_details = $mailbox->get_config();

$mailbox_details = $mailbox->get_config();
$imap_profile = Hm_IMAP_List::fetch($mailbox_details['user'], $mailbox_details['server']);
try {
if (empty($msg_headers['X-Schedule'])) {
return false;
Expand All @@ -87,9 +87,9 @@ function send_scheduled_message($handler, $mailbox, $folder, $msg_id, $send_now
$profile = $profiles[0];
}

$smtp = Hm_SMTP_List::connect($profile['smtp_id'], false);
$smtp = new Hm_Mailbox($imap_profile['id'], $handler->user_config, $handler->session, $imap_profile);

if ($smtp && $smtp->authed()) {
if ($smtp && $smtp->connect()) {
$delivery_receipt = isset($msg_headers['X-Delivery']);

$recipients = [];
Expand Down
4 changes: 2 additions & 2 deletions modules/smtp/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -1576,7 +1576,7 @@ public function process() {

foreach ($servers as $server_id => $config) {
$mailbox = new Hm_Mailbox($server_id, $this->user_config, $this->session, $config);
if ($mailbox && $mailbox->connect()) {
if ($mailbox->get_connection() != null && $mailbox->connect()) {
$folder = 'Scheduled';
$ret = $mailbox->get_messages($folder, 'DATE', false, 'ALL');
foreach ($ret[1] as $msg) {
Expand Down Expand Up @@ -2050,7 +2050,7 @@ function save_imap_draft($atts, $id, $session, $mod, $mod_cache, $uploaded_files
if (! $mailbox || ! $mailbox->connect()) {
return -1;
}

if (!empty($atts['schedule'])) {
$folder ='Scheduled';
if (!count($mailbox->get_folder_status($folder))) {
Expand Down

0 comments on commit 4264295

Please sign in to comment.