From c9d4718837a86fd23cce74047296ebd63376d2bb Mon Sep 17 00:00:00 2001 From: Eduard Carrerars Date: Wed, 27 Dec 2023 17:47:39 +0100 Subject: [PATCH 1/3] Fix strange space before Message-Id --- poweremail_core.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/poweremail_core.py b/poweremail_core.py index 2aad258..c4b2d21 100644 --- a/poweremail_core.py +++ b/poweremail_core.py @@ -775,10 +775,11 @@ def save_fullmail(self, cr, uid, mail, coreaccountid, serv_ref, context=None): logger = netsvc.Logger() mail_obj = self.pool.get('poweremail.mailbox') # Check for existing mails + message_id = mail['Message-ID'].strip() existing_mails = mail_obj.search( cr, uid, [ ('pem_account_id', '=', coreaccountid), - ('pem_message_id', '=', mail['Message-Id']) + ('pem_message_id', '=', message_id) ] ) if existing_mails: @@ -805,7 +806,7 @@ def save_fullmail(self, cr, uid, mail, coreaccountid, serv_ref, context=None): 'pem_body_text': parsed_mail['text'], 'pem_body_html': parsed_mail['html'], 'pem_account_id':coreaccountid, - 'pem_message_id': mail['Message-Id'], + 'pem_message_id': message_id, 'pem_mail_orig': six.text_type(parsed.mime_string, errors='ignore') } #Create the mailbox item now From 44bcbec4dd0d6fa2d218c5fa6f3ac5419373dcdf Mon Sep 17 00:00:00 2001 From: Eduard Carrerars Date: Wed, 27 Dec 2023 18:27:48 +0100 Subject: [PATCH 2/3] Add migration script --- .../post-0001_trim_message_id_database.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 migrations/5.0.23.12.0/post-0001_trim_message_id_database.py diff --git a/migrations/5.0.23.12.0/post-0001_trim_message_id_database.py b/migrations/5.0.23.12.0/post-0001_trim_message_id_database.py new file mode 100644 index 0000000..b1ce2bb --- /dev/null +++ b/migrations/5.0.23.12.0/post-0001_trim_message_id_database.py @@ -0,0 +1,33 @@ +# coding=utf-8 +import logging +from tqdm import tqdm + + +logger = logging.getLogger('openerp.migration.' + __name__) + + +def up(cursor, installed_version): + if not installed_version: + return + cursor.execute("SELECT count(id) FROM poweremail_mailbox where pem_message_id ilike ' %'") + total_to_migrate = cursor.fetchone()[0] + t = tqdm(total=total_to_migrate, desc='Migrating messages') + remaining_to_migrate = total_to_migrate + while remaining_to_migrate: + cursor.execute( + "UPDATE poweremail_mailbox SET pem_message_id = trim(pem_message_id) WHERE id in (" + "SELECT id from poweremail_mailbox WHERE pem_message_id ilike ' %' LIMIT 1000" + ")" + ) + cursor.execute("SELECT count(id) FROM poweremail_mailbox where pem_message_id ilike ' %'") + remaining_to_migrate = cursor.fetchone()[0] + t.update(1000) + t.display() + t.close() + + +def down(cursor, installed_version): + pass + + +migrate = up From b0d317ddaa4fc4d24031fc227e6fd8ee7dededb9 Mon Sep 17 00:00:00 2001 From: Eduard Carrerars Date: Wed, 27 Dec 2023 18:51:54 +0100 Subject: [PATCH 3/3] Remove .display() --- migrations/5.0.23.12.0/post-0001_trim_message_id_database.py | 1 - 1 file changed, 1 deletion(-) diff --git a/migrations/5.0.23.12.0/post-0001_trim_message_id_database.py b/migrations/5.0.23.12.0/post-0001_trim_message_id_database.py index b1ce2bb..1281924 100644 --- a/migrations/5.0.23.12.0/post-0001_trim_message_id_database.py +++ b/migrations/5.0.23.12.0/post-0001_trim_message_id_database.py @@ -22,7 +22,6 @@ def up(cursor, installed_version): cursor.execute("SELECT count(id) FROM poweremail_mailbox where pem_message_id ilike ' %'") remaining_to_migrate = cursor.fetchone()[0] t.update(1000) - t.display() t.close()