Skip to content

Commit

Permalink
[FIX]smtp/modules.php: Fix "Message contains more than the maximum nu…
Browse files Browse the repository at this point in the history
…mber of recipients" on reply
  • Loading branch information
IrAlfred committed May 26, 2024
1 parent 492f634 commit 92ffa5a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
21 changes: 21 additions & 0 deletions lib/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,27 @@ public function save_hm_msgs() {
}
}

/**
* Determine the reply type from the request parameters
*
* This method checks the request parameters to determine if the request
* is a 'reply', 'reply_all', or 'forward'. It returns the corresponding
* string if a match is found, or `false` if none of these are present.
*
* @param array $request The request parameters to check
* @return string|false The reply type ('reply', 'reply_all', 'forward') or `false` if none are found
*/
public function get_reply_type($request) {
if (array_key_exists('reply', $request) && $request['reply']) {
return 'reply';
} elseif (array_key_exists('reply_all', $request) && $request['reply_all']) {
return 'reply_all';
} elseif (array_key_exists('forward', $request) && $request['forward']) {
return 'forward';
}
return false;
}

/**
* Handler modules need to override this method to do work
*/
Expand Down
31 changes: 15 additions & 16 deletions modules/smtp/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ public function process() {
$this->request->get['uid']
);
$reply_details = $this->session->get($cache_name, false);

$reply_type = '';
if ($reply_details) {
recip_count_check($reply_details['msg_headers'], $this);
$reply_type = $this->get_reply_type($this->request->get);
recip_count_check($reply_details['msg_headers'], $this, $reply_type);
$this->out('reply_details', $reply_details);
}
}
Expand Down Expand Up @@ -310,21 +313,13 @@ public function process() {
}
$draft = array();
$draft_id = next_draft_key($this->session);
$reply_type = false;
if (array_key_exists('reply', $this->request->get) && $this->request->get['reply']) {
$reply_type = 'reply';
}
elseif (array_key_exists('reply_all', $this->request->get) && $this->request->get['reply_all']) {
$reply_type = 'reply_all';
}
elseif (array_key_exists('forward', $this->request->get) && $this->request->get['forward']) {
$reply_type = 'forward';
$reply_type = $this->get_reply_type($this->request->get);
if ($reply_type == 'forward') {
$draft_id = $this->get('compose_draft_id', -1);
if ($draft_id >= 0) {
$draft = get_draft($draft_id, $this->session);
}
}
elseif (array_key_exists('draft_id', $this->request->get)) {
} elseif (array_key_exists('draft_id', $this->request->get)) {
$draft = get_draft($this->request->get['draft_id'], $this->session);
$draft_id = $this->request->get['draft_id'];
}
Expand Down Expand Up @@ -2157,15 +2152,19 @@ function default_smtp_server($user_config, $session, $request, $config, $user, $
* @subpackage smtp/functions
*/
if (!hm_exists('recip_count_check')) {
function recip_count_check($headers, $omod) {
function recip_count_check($headers, $omod, $reply_type='reply_all') {
$headers = lc_headers($headers);
$recip_count = 0;
if (array_key_exists('to', $headers) && $headers['to']) {
$recip_count = 1;

if (array_key_exists('to', $headers) && $headers['to'] && $reply_type == 'reply_all') {
$recip_count += count(process_address_fld($headers['to']));
}
if (array_key_exists('cc', $headers) && $headers['cc']) {

if (array_key_exists('cc', $headers) && $headers['cc'] && $reply_type == 'reply_all') {
$recip_count += count(process_address_fld($headers['cc']));

}

if ($recip_count > MAX_RECIPIENT_WARNING) {
Hm_Msgs::add('ERRMessage contains more than the maximum number of recipients, proceed with caution');
}
Expand Down

0 comments on commit 92ffa5a

Please sign in to comment.