[TikiWiki-commits] [Git][tikiwiki/tiki][29.x] [BP][FIX] IMAP mail-in error by requiring missing Hm_IMAP class

"ushindi bienvenu \(@usbbush\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <69206080ea2b0_2a17ee40892a2@gitlab-sidekiq-low-urgency-cpu-bound-v2-64b84c7ff5-72vwn.mail>

ushindi bienvenu pushed to branch 29.x at Tiki Wiki CMS Groupware / Tiki


Commits:
1d82de97 by ushindi bienvenu at 2025-11-21T12:43:59+00:00
[BP][FIX] IMAP mail-in error by requiring missing Hm_IMAP class
---
* [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

See merge request tikiwiki/tiki!9087

- - - - -


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
=====================================
@@ -341,6 +341,9 @@ class Comments extends TikiLib
         }
     }
 
+    /**
+     * @throws \Tiki\MailIn\Exception\TransportException
+     */
     public function process_inbound_mail($forumId, $maxImport = 5)
     {
         global $prefs, $user;
@@ -374,11 +377,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,
@@ -386,20 +391,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
@@ -658,8 +661,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/1d82de9794e796cb2761a7d06ccf00f251638b78

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/1d82de9794e796cb2761a7d06ccf00f251638b78
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.