You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2021/02/23 03:45:22 UTC

[james-project] 09/14: JAMES-3477 JDBCMailRepository should always update email content

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 97ad5331f0b1531b8daa8d3bdab8d0f8fb17755e
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Dec 31 10:45:29 2020 +0700

    JAMES-3477 JDBCMailRepository should always update email content
---
 .../mailrepository/jdbc/JDBCMailRepository.java    | 26 ++--------------------
 1 file changed, 2 insertions(+), 24 deletions(-)

diff --git a/server/data/data-jdbc/src/main/java/org/apache/james/mailrepository/jdbc/JDBCMailRepository.java b/server/data/data-jdbc/src/main/java/org/apache/james/mailrepository/jdbc/JDBCMailRepository.java
index 78e66f0..2fd79f9 100644
--- a/server/data/data-jdbc/src/main/java/org/apache/james/mailrepository/jdbc/JDBCMailRepository.java
+++ b/server/data/data-jdbc/src/main/java/org/apache/james/mailrepository/jdbc/JDBCMailRepository.java
@@ -45,7 +45,6 @@ import java.util.StringTokenizer;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.mail.MessagingException;
-import javax.mail.internet.MimeMessage;
 import javax.sql.DataSource;
 
 import org.apache.commons.configuration2.BaseHierarchicalConfiguration;
@@ -383,10 +382,7 @@ public class JDBCMailRepository implements MailRepository, Configurable, Initial
             // Need to determine whether need to insert this record, or update
             // it.
 
-            // Determine whether the message body has changed, and possibly
-            // avoid
-            // updating the database.
-            boolean saveBody = saveBodyRequired(mc);
+            mc.getMessage().saveChanges();
             MessageInputStream is = new MessageInputStream(mc, sr, inMemorySizeLimit, true);
 
             // Begin a transaction
@@ -405,9 +401,7 @@ public class JDBCMailRepository implements MailRepository, Configurable, Initial
                     updateMailAttributes(mc, conn);
                 }
 
-                if (saveBody) {
-                    updateMessageBody(mc, conn, is);
-                }
+                updateMessageBody(mc, conn, is);
 
             } else {
                 // Insert the record into the database
@@ -551,22 +545,6 @@ public class JDBCMailRepository implements MailRepository, Configurable, Initial
         }
     }
 
-    private boolean saveBodyRequired(Mail mc) throws MessagingException {
-        boolean saveBody;
-        MimeMessage messageBody = mc.getMessage();
-
-        if (messageBody instanceof MimeMessageWrapper) {
-            MimeMessageWrapper message = (MimeMessageWrapper) messageBody;
-            saveBody = message.isModified();
-            if (saveBody) {
-                message.loadMessage();
-            }
-        } else {
-            saveBody = true;
-        }
-        return saveBody;
-    }
-
     @Override
     @SuppressWarnings("unchecked")
     public Mail retrieve(MailKey key) throws MessagingException {


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org