parent
f99cbe5e9b
commit
fcdd936ec6
|
@ -17,9 +17,9 @@ pipeline {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
if (env.JOB_NAME == 'mail2redmine' && env.GIT_BRANCH == 'origin/main') {
|
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/')) {
|
} 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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
7
|
|
|
@ -2,13 +2,18 @@ Source: mail2redmine
|
||||||
Maintainer: Serghei Mihai <smihai@entrouvert.com>
|
Maintainer: Serghei Mihai <smihai@entrouvert.com>
|
||||||
Section: python
|
Section: python
|
||||||
Priority: optional
|
Priority: optional
|
||||||
Build-Depends: python-setuptools (>= 0.6b3), python-all (>= 2.6.6-3), debhelper (>= 7.4.3)
|
Build-Depends: debhelper-compat (= 12),
|
||||||
Standards-Version: 3.9.1
|
python3-setuptools,
|
||||||
|
python3-all,
|
||||||
|
dh-python
|
||||||
|
Standards-Version: 3.9.6
|
||||||
|
|
||||||
|
|
||||||
Package: mail2redmine
|
Package: mail2redmine
|
||||||
Architecture: all
|
Architecture: all
|
||||||
Depends: ${misc:Depends}, ${python:Depends}
|
Depends: ${python:Depends},
|
||||||
|
${misc:Depends},
|
||||||
|
python3-setuptools
|
||||||
Description: Converts incoming exim emails to tickets
|
Description: Converts incoming exim emails to tickets
|
||||||
mail2redmine converts incoming email from Exim to Redmine tracker tickets by
|
mail2redmine converts incoming email from Exim to Redmine tracker tickets by
|
||||||
using mail subject and body as ticket title and description respectively.
|
using mail subject and body as ticket title and description respectively.
|
||||||
|
|
|
@ -4,7 +4,4 @@
|
||||||
# Mon, 09 May 2016 17:42:19 +0200
|
# Mon, 09 May 2016 17:42:19 +0200
|
||||||
|
|
||||||
%:
|
%:
|
||||||
dh $@ --with python2
|
dh $@ --with python3 --buildsystem=pybuild
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,17 +27,22 @@ class UnknownUser(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def parse_header(header_text):
|
def parse_header(header_text):
|
||||||
if isinstance(header_text, unicode):
|
if not header_text:
|
||||||
return header_text
|
return ''
|
||||||
default_charset = 'ascii'
|
default_charset = 'ascii'
|
||||||
try:
|
try:
|
||||||
headers = email.Header.decode_header(header_text)
|
headers = email.header.decode_header(header_text)
|
||||||
except email.Errors.HeaderParseError:
|
except email.errors.HeaderParseError:
|
||||||
return header_text.encode(default_charset, 'replace').decode(default_charset)
|
return header_text.encode(default_charset, 'replace').decode(default_charset)
|
||||||
else:
|
else:
|
||||||
|
res = ''
|
||||||
for i, (text, charset) in enumerate(headers):
|
for i, (text, charset) in enumerate(headers):
|
||||||
headers[i] = unicode(text, charset or default_charset, errors='replace')
|
if isinstance(text, str):
|
||||||
return u' '.join(headers)
|
res += text
|
||||||
|
else:
|
||||||
|
res += text.decode(charset or default_charset, errors='replace')
|
||||||
|
return res
|
||||||
|
return ''
|
||||||
|
|
||||||
|
|
||||||
def parse_attachment(data, blacklist=None):
|
def parse_attachment(data, blacklist=None):
|
||||||
|
@ -54,6 +59,7 @@ def parse_attachment(data, blacklist=None):
|
||||||
with tempfile.NamedTemporaryFile(delete=False) as attachment:
|
with tempfile.NamedTemporaryFile(delete=False) as attachment:
|
||||||
attachment.write(file_data)
|
attachment.write(file_data)
|
||||||
attachment.flush()
|
attachment.flush()
|
||||||
|
|
||||||
attachment = {'path': attachment.name,
|
attachment = {'path': attachment.name,
|
||||||
'content_type': data.get_content_type(),
|
'content_type': data.get_content_type(),
|
||||||
'filename': parse_header(data.get_filename())}
|
'filename': parse_header(data.get_filename())}
|
||||||
|
@ -96,8 +102,7 @@ def create_ticket(mail):
|
||||||
if attachment:
|
if attachment:
|
||||||
attachments.append(attachment)
|
attachments.append(attachment)
|
||||||
elif data.get_content_type() == "text/plain":
|
elif data.get_content_type() == "text/plain":
|
||||||
body = data.get_payload(decode=True)
|
body = data.get_payload()
|
||||||
body = unicode(body, data.get_content_charset('utf-8')).encode('utf-8')
|
|
||||||
|
|
||||||
# get project tech manager
|
# get project tech manager
|
||||||
tech_manager = None
|
tech_manager = None
|
||||||
|
|
|
@ -19,7 +19,7 @@ def test_parsing_subjects(dump):
|
||||||
mail = mail2redmine.email.message_from_file(dump)
|
mail = mail2redmine.email.message_from_file(dump)
|
||||||
subject = mail2redmine.parse_header(mail['Subject'])
|
subject = mail2redmine.parse_header(mail['Subject'])
|
||||||
assert subject
|
assert subject
|
||||||
assert isinstance(subject, unicode)
|
assert isinstance(subject, str)
|
||||||
assert subject in (u'Pour paiement immédiat', u'Facture Infopole à régler',
|
assert subject in (u'Pour paiement immédiat', u'Facture Infopole à régler',
|
||||||
u'Тест на русском', u'test', u'Un ticket à tester',
|
u'Тест на русском', u'test', u'Un ticket à tester',
|
||||||
u'[Fwd: A nouveau du code reçu]',
|
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',
|
@pytest.mark.parametrize('mail_dump', ('mail_dumps/3515ed61-bb12-4f41-ac25-81d468d2c80f.mail',
|
||||||
'mail_dumps/711d5ffc-b153-46e1-ba21-30c6a1b45444.mail'))
|
'mail_dumps/711d5ffc-b153-46e1-ba21-30c6a1b45444.mail'))
|
||||||
def test_parsing_attachments(mail_dump):
|
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 = []
|
attachments = []
|
||||||
for data in mail.walk():
|
for data in mail.walk():
|
||||||
attachment = mail2redmine.parse_attachment(data)
|
attachment = mail2redmine.parse_attachment(data)
|
||||||
|
@ -36,13 +36,13 @@ def test_parsing_attachments(mail_dump):
|
||||||
assert 'path' in attachment
|
assert 'path' in attachment
|
||||||
assert 'content_type' in attachment
|
assert 'content_type' in attachment
|
||||||
assert 'filename' in attachment
|
assert 'filename' in attachment
|
||||||
assert isinstance(attachment['filename'], unicode)
|
assert isinstance(attachment['filename'], str)
|
||||||
attachments.append(attachment)
|
attachments.append(attachment)
|
||||||
assert attachments
|
assert attachments
|
||||||
|
|
||||||
@pytest.mark.parametrize('message', ('mail_dumps/1461591292.25165_17.dor-lomin_2.mail',))
|
@pytest.mark.parametrize('message', ('mail_dumps/1461591292.25165_17.dor-lomin_2.mail',))
|
||||||
def test_mail_with_two_attachments(message):
|
def test_mail_with_two_attachments(message):
|
||||||
mail = mail2redmine.email.message_from_file(file(message))
|
mail = mail2redmine.email.message_from_file(open(message))
|
||||||
attachments = []
|
attachments = []
|
||||||
for data in mail.walk():
|
for data in mail.walk():
|
||||||
attachment = mail2redmine.parse_attachment(data)
|
attachment = mail2redmine.parse_attachment(data)
|
||||||
|
@ -50,7 +50,7 @@ def test_mail_with_two_attachments(message):
|
||||||
assert 'path' in attachment
|
assert 'path' in attachment
|
||||||
assert 'content_type' in attachment
|
assert 'content_type' in attachment
|
||||||
assert 'filename' 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',
|
assert attachment['filename'] in (u'201601-mise-a-jour-Publik.pdf',
|
||||||
u'Capture d\'écran de 2014-12-23 17:03:40.png')
|
u'Capture d\'écran de 2014-12-23 17:03:40.png')
|
||||||
attachments.append(attachment)
|
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',))
|
@pytest.mark.parametrize('message', ('mail_dumps/1461591292.25165_17.dor-lomin_2.mail',))
|
||||||
def test_mail_attachment_blacklist(message):
|
def test_mail_attachment_blacklist(message):
|
||||||
mail = mail2redmine.email.message_from_file(file(message))
|
mail = mail2redmine.email.message_from_file(open(message))
|
||||||
attachments = []
|
attachments = []
|
||||||
blacklist = {'sha1sums': ['ab7c57983551204500d67f8ec3dd54a01e81d75d']}
|
blacklist = {'sha1sums': ['ab7c57983551204500d67f8ec3dd54a01e81d75d']}
|
||||||
for data in mail.walk():
|
for data in mail.walk():
|
||||||
|
@ -67,7 +67,7 @@ def test_mail_attachment_blacklist(message):
|
||||||
assert 'path' in attachment
|
assert 'path' in attachment
|
||||||
assert 'content_type' in attachment
|
assert 'content_type' in attachment
|
||||||
assert 'filename' 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'
|
assert attachment['filename'] == u'201601-mise-a-jour-Publik.pdf'
|
||||||
attachments.append(attachment)
|
attachments.append(attachment)
|
||||||
assert len(attachments) == 1
|
assert len(attachments) == 1
|
||||||
|
|
Loading…
Reference in New Issue