summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmmanuel Cazenave <ecazenave@entrouvert.com>2022-01-17 14:18:22 (GMT)
committerEmmanuel Cazenave <ecazenave@entrouvert.com>2022-01-17 14:49:18 (GMT)
commitfcdd936ec6ba6f611b0de8037ce52c16b24edf93 (patch)
tree0d364a9adceb70aa8a7c792fffb9c17361f3c8f7
parentf99cbe5e9b9d8246b71046c34c8df7d3147c95c2 (diff)
downloadmail2redmine-fcdd936ec6ba6f611b0de8037ce52c16b24edf93.zip
mail2redmine-fcdd936ec6ba6f611b0de8037ce52c16b24edf93.tar.gz
mail2redmine-fcdd936ec6ba6f611b0de8037ce52c16b24edf93.tar.bz2
add python 3 compat (#60498)
And upgrade packaging.
-rw-r--r--Jenkinsfile4
-rw-r--r--debian/compat1
-rw-r--r--debian/control11
-rwxr-xr-xdebian/rules5
-rw-r--r--mail2redmine.py21
-rw-r--r--test_mail2redmine.py14
-rw-r--r--tox.ini2
7 files changed, 32 insertions, 26 deletions
diff --git a/Jenkinsfile b/Jenkinsfile
index b3ee5c3..353ae37 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -17,9 +17,9 @@ pipeline {
steps {
script {
if (env.JOB_NAME == 'mail2redmine' && env.GIT_BRANCH == 'origin/main') {
- sh 'sudo -H -u eobuilder /usr/local/bin/eobuilder -d stretch mail2redmine'
+ sh 'sudo -H -u eobuilder /usr/local/bin/eobuilder mail2redmine'
} else if (env.GIT_BRANCH.startsWith('hotfix/')) {
- sh "sudo -H -u eobuilder /usr/local/bin/eobuilder -d stretch --branch ${env.GIT_BRANCH} --hotfix mail2redmine"
+ sh "sudo -H -u eobuilder /usr/local/bin/eobuilder --branch ${env.GIT_BRANCH} --hotfix mail2redmine"
}
}
}
diff --git a/debian/compat b/debian/compat
deleted file mode 100644
index 7f8f011..0000000
--- a/debian/compat
+++ /dev/null
@@ -1 +0,0 @@
-7
diff --git a/debian/control b/debian/control
index ffc1a8d..7c79938 100644
--- a/debian/control
+++ b/debian/control
@@ -2,13 +2,18 @@ Source: mail2redmine
Maintainer: Serghei Mihai <smihai@entrouvert.com>
Section: python
Priority: optional
-Build-Depends: python-setuptools (>= 0.6b3), python-all (>= 2.6.6-3), debhelper (>= 7.4.3)
-Standards-Version: 3.9.1
+Build-Depends: debhelper-compat (= 12),
+ python3-setuptools,
+ python3-all,
+ dh-python
+Standards-Version: 3.9.6
Package: mail2redmine
Architecture: all
-Depends: ${misc:Depends}, ${python:Depends}
+Depends: ${python:Depends},
+ ${misc:Depends},
+ python3-setuptools
Description: Converts incoming exim emails to tickets
mail2redmine converts incoming email from Exim to Redmine tracker tickets by
using mail subject and body as ticket title and description respectively.
diff --git a/debian/rules b/debian/rules
index f9e8abf..e1734cc 100755
--- a/debian/rules
+++ b/debian/rules
@@ -4,7 +4,4 @@
# Mon, 09 May 2016 17:42:19 +0200
%:
- dh $@ --with python2
-
-
-
+ dh $@ --with python3 --buildsystem=pybuild
diff --git a/mail2redmine.py b/mail2redmine.py
index 5e4b348..ce5578e 100644
--- a/mail2redmine.py
+++ b/mail2redmine.py
@@ -27,17 +27,22 @@ class UnknownUser(Exception):
pass
def parse_header(header_text):
- if isinstance(header_text, unicode):
- return header_text
+ if not header_text:
+ return ''
default_charset = 'ascii'
try:
- headers = email.Header.decode_header(header_text)
- except email.Errors.HeaderParseError:
+ headers = email.header.decode_header(header_text)
+ except email.errors.HeaderParseError:
return header_text.encode(default_charset, 'replace').decode(default_charset)
else:
+ res = ''
for i, (text, charset) in enumerate(headers):
- headers[i] = unicode(text, charset or default_charset, errors='replace')
- return u' '.join(headers)
+ if isinstance(text, str):
+ res += text
+ else:
+ res += text.decode(charset or default_charset, errors='replace')
+ return res
+ return ''
def parse_attachment(data, blacklist=None):
@@ -54,6 +59,7 @@ def parse_attachment(data, blacklist=None):
with tempfile.NamedTemporaryFile(delete=False) as attachment:
attachment.write(file_data)
attachment.flush()
+
attachment = {'path': attachment.name,
'content_type': data.get_content_type(),
'filename': parse_header(data.get_filename())}
@@ -96,8 +102,7 @@ def create_ticket(mail):
if attachment:
attachments.append(attachment)
elif data.get_content_type() == "text/plain":
- body = data.get_payload(decode=True)
- body = unicode(body, data.get_content_charset('utf-8')).encode('utf-8')
+ body = data.get_payload()
# get project tech manager
tech_manager = None
diff --git a/test_mail2redmine.py b/test_mail2redmine.py
index 61f894e..51fbbc7 100644
--- a/test_mail2redmine.py
+++ b/test_mail2redmine.py
@@ -19,7 +19,7 @@ def test_parsing_subjects(dump):
mail = mail2redmine.email.message_from_file(dump)
subject = mail2redmine.parse_header(mail['Subject'])
assert subject
- assert isinstance(subject, unicode)
+ assert isinstance(subject, str)
assert subject in (u'Pour paiement immédiat', u'Facture Infopole à régler',
u'Тест на русском', u'test', u'Un ticket à tester',
u'[Fwd: A nouveau du code reçu]',
@@ -28,7 +28,7 @@ def test_parsing_subjects(dump):
@pytest.mark.parametrize('mail_dump', ('mail_dumps/3515ed61-bb12-4f41-ac25-81d468d2c80f.mail',
'mail_dumps/711d5ffc-b153-46e1-ba21-30c6a1b45444.mail'))
def test_parsing_attachments(mail_dump):
- mail = mail2redmine.email.message_from_file(file(mail_dump))
+ mail = mail2redmine.email.message_from_file(open(mail_dump))
attachments = []
for data in mail.walk():
attachment = mail2redmine.parse_attachment(data)
@@ -36,13 +36,13 @@ def test_parsing_attachments(mail_dump):
assert 'path' in attachment
assert 'content_type' in attachment
assert 'filename' in attachment
- assert isinstance(attachment['filename'], unicode)
+ assert isinstance(attachment['filename'], str)
attachments.append(attachment)
assert attachments
@pytest.mark.parametrize('message', ('mail_dumps/1461591292.25165_17.dor-lomin_2.mail',))
def test_mail_with_two_attachments(message):
- mail = mail2redmine.email.message_from_file(file(message))
+ mail = mail2redmine.email.message_from_file(open(message))
attachments = []
for data in mail.walk():
attachment = mail2redmine.parse_attachment(data)
@@ -50,7 +50,7 @@ def test_mail_with_two_attachments(message):
assert 'path' in attachment
assert 'content_type' in attachment
assert 'filename' in attachment
- assert isinstance(attachment['filename'], unicode)
+ assert isinstance(attachment['filename'], str)
assert attachment['filename'] in (u'201601-mise-a-jour-Publik.pdf',
u'Capture d\'écran de 2014-12-23 17:03:40.png')
attachments.append(attachment)
@@ -58,7 +58,7 @@ def test_mail_with_two_attachments(message):
@pytest.mark.parametrize('message', ('mail_dumps/1461591292.25165_17.dor-lomin_2.mail',))
def test_mail_attachment_blacklist(message):
- mail = mail2redmine.email.message_from_file(file(message))
+ mail = mail2redmine.email.message_from_file(open(message))
attachments = []
blacklist = {'sha1sums': ['ab7c57983551204500d67f8ec3dd54a01e81d75d']}
for data in mail.walk():
@@ -67,7 +67,7 @@ def test_mail_attachment_blacklist(message):
assert 'path' in attachment
assert 'content_type' in attachment
assert 'filename' in attachment
- assert isinstance(attachment['filename'], unicode)
+ assert isinstance(attachment['filename'], str)
assert attachment['filename'] == u'201601-mise-a-jour-Publik.pdf'
attachments.append(attachment)
assert len(attachments) == 1
diff --git a/tox.ini b/tox.ini
index 2a44100..66b5c55 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,5 +1,5 @@
[tox]
-envlist = py2-junit
+envlist = py3-junit
toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/mail2redmine/{env:BRANCH_NAME:}
[testenv]