1
0
Fork 0
mirror of https://github.com/deltachat/deltachat-core.git synced 2025-10-06 03:50:08 +02:00

add python tests for new save_mime_headers config and get_mime_headers function

This commit is contained in:
holger krekel 2018-10-16 00:15:54 +02:00
parent e0f3f038fd
commit 50a9afa7ea
3 changed files with 46 additions and 1 deletions

View file

@ -12,7 +12,7 @@ def main():
long_description = long_description, long_description = long_description,
author='holger krekel, bjoern petersen and contributors', author='holger krekel, bjoern petersen and contributors',
setup_requires=['cffi>=1.0.0'], setup_requires=['cffi>=1.0.0'],
install_requires=['cffi>=1.0.0', 'requests', 'attrs'], install_requires=['cffi>=1.0.0', 'requests', 'attrs', 'six'],
packages=setuptools.find_packages('src'), packages=setuptools.find_packages('src'),
package_dir={'': 'src'}, package_dir={'': 'src'},
cffi_modules=['src/deltachat/_build.py:ffibuilder'], cffi_modules=['src/deltachat/_build.py:ffibuilder'],

View file

@ -2,6 +2,7 @@
from __future__ import print_function from __future__ import print_function
import threading import threading
import six
import re import re
import time import time
import requests import requests
@ -222,6 +223,25 @@ class Account(object):
""" return Message instance. """ """ return Message instance. """
return Message.from_db(self._dc_context, msg_id) return Message.from_db(self._dc_context, msg_id)
def get_mime_headers(self, msg_id):
""" return mime-header object for an incoming message.
This only returns a non-None object if ``save_mime_headers``
config option was set and ``msg_id`` refers to an incoming
message.
:param msg_id: integer message id
:returns: email-mime message object.
"""
import email.parser
mime_headers = lib.dc_get_mime_headers(self._dc_context, msg_id)
if mime_headers:
s = ffi.string(mime_headers)
if isinstance(s, bytes):
s = s.decode("ascii")
fp = six.StringIO(s)
return email.parser.Parser().parse(fp)
def mark_seen_messages(self, messages): def mark_seen_messages(self, messages):
""" mark the given set of messages as seen. """ mark the given set of messages as seen.

View file

@ -20,6 +20,10 @@ class TestOfflineAccount:
with pytest.raises(KeyError): with pytest.raises(KeyError):
ac1.get_config("lqkwje") ac1.get_config("lqkwje")
def test_has_savemime(self, acfactory):
ac1 = acfactory.get_unconfigured_account()
assert "save_mime_headers" in ac1.get_config("sys.config_keys").split()
def test_selfcontact_if_unconfigured(self, acfactory): def test_selfcontact_if_unconfigured(self, acfactory):
ac1 = acfactory.get_unconfigured_account() ac1 = acfactory.get_unconfigured_account()
with pytest.raises(ValueError): with pytest.raises(ValueError):
@ -273,6 +277,27 @@ class TestOnlineAccount:
ac1._evlogger.get_info_matching("Message marked as seen") ac1._evlogger.get_info_matching("Message marked as seen")
assert msg_out.get_state().is_out_mdn_received() assert msg_out.get_state().is_out_mdn_received()
def test_saved_mime_on_received_message(self, acfactory, lp):
lp.sec("starting accounts, waiting for configuration")
ac1 = acfactory.get_online_configuring_account()
ac2 = acfactory.get_online_configuring_account()
ac2.set_config("save_mime_headers", "1")
c2 = ac1.create_contact(email=ac2.get_config("addr"))
chat = ac1.create_chat_by_contact(c2)
wait_configuration_progress(ac1, 1000)
wait_configuration_progress(ac2, 1000)
lp.sec("sending text message from ac1 to ac2")
msg_out = chat.send_text("message1")
ac1._evlogger.get_matching("DC_EVENT_MSG_DELIVERED")
assert ac1.get_mime_headers(msg_out.id) is None
lp.sec("wait for ac2 to receive message")
ev = ac2._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")
in_id = ev[2]
mime = ac2.get_mime_headers(in_id)
assert mime.get_all("From")
assert mime.get_all("Received")
def test_send_and_receive_image(self, acfactory, lp, data): def test_send_and_receive_image(self, acfactory, lp, data):
lp.sec("starting accounts, waiting for configuration") lp.sec("starting accounts, waiting for configuration")
ac1 = acfactory.get_online_configuring_account() ac1 = acfactory.get_online_configuring_account()