[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] IMAP mail-in error by requiring missing Hm_IMAP class
"Victor Emanouilov \(@kroky\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <6917770ab0840_2a6830a1c99838@gitlab-sidekiq-low-urgency-cpu-bound-v2-59ccd46784-bs2hc.mail> |
Victor Emanouilov pushed to branch master at Tiki Wiki CMS Groupware / Tiki
Commits:
189908cf by ushindi bienvenu at 2025-11-14T18:30:00+00:00
[FIX] IMAP mail-in error by requiring missing Hm_IMAP class
---
* [FIX] IMAP mail-in error by requiring missing Hm_IMAP class
See merge request tikiwiki/tiki!8961
- - - - -
4 changed files:
- db/tiki.sql
- + installer/schema/20251104_update_messageid_from_tiki_comments_tiki.sql
- lib/comments/commentslib.php
- lib/core/Tiki/MailIn/Source/Imap.php
Changes:
=====================================
db/tiki.sql
=====================================
@@ -717,8 +717,8 @@ CREATE TABLE `tiki_comments` (
`user_ip` varchar(39) default NULL,
`summary` varchar(240) default NULL,
`smiley` varchar(80) default NULL,
- `message_id` varchar(128) default NULL,
- `in_reply_to` varchar(128) default NULL,
+ `message_id` TEXT default NULL,
+ `in_reply_to` varchar(255) default NULL,
`comment_rating` tinyint(2) default NULL,
`archived` char(1) default NULL,
`approved` char(1) NOT NULL default 'y',
=====================================
installer/schema/20251104_update_messageid_from_tiki_comments_tiki.sql
=====================================
@@ -0,0 +1,2 @@
+ALTER TABLE `tiki_comments` MODIFY `message_id` TEXT default NULL;
+ALTER TABLE `tiki_comments` MODIFY `in_reply_to` varchar(255) default NULL;
\ No newline at end of file
=====================================
lib/comments/commentslib.php
=====================================
@@ -342,6 +342,9 @@ class Comments extends TikiLib
}
}
+ /**
+ * @throws \Tiki\MailIn\Exception\TransportException
+ */
public function process_inbound_mail($forumId, $maxImport = 5)
{
global $prefs, $user;
@@ -375,11 +378,13 @@ class Comments extends TikiLib
$rawEmailContent = $imap->get_message_content($uid, 0);
$parsedMessage = $mailMimeParser->parse($rawEmailContent, true);
+
+ // $subject = $parsedMessage->getHeaderValue('Subject');
// If the mail came from Tiki, we don't need to add it again
$xTikiHeader = $parsedMessage->getHeaderValue('X-Tiki');
if ($xTikiHeader === 'yes') {
$source_imap->deleteMessages($imap, [$uid]);
- error_log("Skipping email with X-Tiki: yes. Message ID: " . $messageFromImap->getNumber());
+ error_log("[MAIL-IMPORT][SKIP] Message UID=$uid came from Tiki (X-Tiki=yes)");
continue;
}
// If the connection is done, or the mail has an error, or whatever,
@@ -387,20 +392,18 @@ class Comments extends TikiLib
// and continue on. --rlpowell
if (! count($parsedMessage->getAllHeaders())) {
$source_imap->deleteMessages($imap, [$uid]);
- error_log("Skipping email with no headers. Raw content length: " . strlen($rawEmailContent));
+ error_log("[MAIL-IMPORT][SKIP] Message UID=$uid has no headers.");
continue;
}
-// https://mail-mime-parser.org/usage-guide-0.4.html
- $addressHeader = $parsedMessage->getHeader('From'); // getHeader('From') returns an AddressHeader object
- $fromAddress = $addressHeader?->getAddresses()[0] ?? null;
- $aux['From'] = $fromAddress ? $fromAddress->toString() : '';
- if ($addressHeader) {
- $returnPath = $parsedMessage->getHeaderValue('Return-path');
- if ($returnPath) {
- $aux['From'] = $returnPath;
- } else {
- $aux['Return-path'] = "";
- }
+
+ $addressHeader = $parsedMessage->getHeader('From');
+ $fromAddressPart = $addressHeader?->getAddresses()[0] ?? null;
+ $aux['From'] = $fromAddressPart ? $fromAddressPart->getEmail() : '(none)';
+
+ // Optionally override with Return-Path if available
+ $returnPath = $parsedMessage->getHeaderValue('Return-Path');
+ if ($returnPath) {
+ $aux['From'] = $returnPath;
}
//try to get the date from the email:
$postDate = $parsedMessage->getHeader('Date')?->getDateTime(); // getHeader('Date') returns an DateHeader object
@@ -659,8 +662,10 @@ class Comments extends TikiLib
// mark the message to be deleted and keep processing
$source_imap->deleteMessages($imap, [$uid]);
} catch (Exception $e) {
+ error_log("[MAIL-IMPORT][ERROR] Failed to post email UID=$uid: " . $e->getMessage());
Feedback::error(tr('Adding email %0 to the forum failed due to "%1"', $title, $e->getMessage()));
}
+ $importedCount++;
}
if ($imap) {
$imap->disconnect();
=====================================
lib/core/Tiki/MailIn/Source/Imap.php
=====================================
@@ -125,16 +125,21 @@ class Imap implements SourceInterface
*/
public function connect(): Hm_IMAP
{
+ global $tikipath;
try {
$config = [
'server' => $this->host,
'port' => $this->port,
- 'tls' => stripos($this->ssl, 'TLS') !== false,
+ 'tls' => $this->port === 993,
'type' => 'imap',
'username' => $this->username ,
'password' => $this->password,
'use_cache' => true,
];
+ require_once $tikipath . '/lib/cypht/integration/classes.php';
+ require_once APP_PATH . 'modules/core/message_functions.php';
+ require_once APP_PATH . 'modules/imap/hm-imap.php';
+
$imap = new Hm_IMAP();
$authenticate = $imap->connect($config);
if (! $authenticate) {
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/189908cf2f39c5545ad7946acb112e55c3b34722
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/189908cf2f39c5545ad7946acb112e55c3b34722
You're receiving this email because of your account on gitlab.com.
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs