Skip to content

Commit

Permalink
Merge pull request #144 from gisce/fix-message-id-outlook
Browse files Browse the repository at this point in the history
Fix strange space before Message-Id
  • Loading branch information
ecarreras authored Dec 29, 2023
2 parents 783ac2a + b0d317d commit 962d5fb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
32 changes: 32 additions & 0 deletions migrations/5.0.23.12.0/post-0001_trim_message_id_database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 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.close()


def down(cursor, installed_version):
pass


migrate = up
5 changes: 3 additions & 2 deletions poweremail_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit 962d5fb

Please sign in to comment.