mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-05 02:29:28 +02:00
move get_mime_headers() function to Message object where it belongs.
also simplify creating a mime object from the headers ...
This commit is contained in:
parent
e8a1d29125
commit
5ad5baa6ab
3 changed files with 18 additions and 24 deletions
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
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
|
||||||
|
@ -223,26 +222,6 @@ 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):
|
|
||||||
""" 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
|
|
||||||
msg_id = getattr(msg, "id", msg)
|
|
||||||
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.
|
||||||
|
|
||||||
|
|
|
@ -109,6 +109,22 @@ class Message(object):
|
||||||
if ts:
|
if ts:
|
||||||
return datetime.utcfromtimestamp(ts)
|
return datetime.utcfromtimestamp(ts)
|
||||||
|
|
||||||
|
def get_mime_headers(self):
|
||||||
|
""" return mime-header object for an incoming message.
|
||||||
|
|
||||||
|
This only returns a non-None object if ``save_mime_headers``
|
||||||
|
config option was set and the message is incoming.
|
||||||
|
|
||||||
|
:returns: email-mime message object (with headers only, no body).
|
||||||
|
"""
|
||||||
|
import email.parser
|
||||||
|
mime_headers = lib.dc_get_mime_headers(self._dc_context, self.id)
|
||||||
|
if mime_headers:
|
||||||
|
s = ffi.string(mime_headers)
|
||||||
|
if isinstance(s, bytes):
|
||||||
|
s = s.decode("ascii")
|
||||||
|
return email.message_from_string(s)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def chat(self):
|
def chat(self):
|
||||||
"""chat this message was posted in.
|
"""chat this message was posted in.
|
||||||
|
|
|
@ -291,15 +291,14 @@ class TestOnlineAccount:
|
||||||
lp.sec("sending text message from ac1 to ac2")
|
lp.sec("sending text message from ac1 to ac2")
|
||||||
msg_out = chat.send_text("message1")
|
msg_out = chat.send_text("message1")
|
||||||
ac1._evlogger.get_matching("DC_EVENT_MSG_DELIVERED")
|
ac1._evlogger.get_matching("DC_EVENT_MSG_DELIVERED")
|
||||||
assert ac1.get_mime_headers(msg_out.id) is None
|
assert msg_out.get_mime_headers() is None
|
||||||
|
|
||||||
lp.sec("wait for ac2 to receive message")
|
lp.sec("wait for ac2 to receive message")
|
||||||
ev = ac2._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")
|
ev = ac2._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")
|
||||||
in_id = ev[2]
|
in_id = ev[2]
|
||||||
mime = ac2.get_mime_headers(in_id)
|
mime = ac2.get_message_by_id(in_id).get_mime_headers()
|
||||||
assert mime.get_all("From")
|
assert mime.get_all("From")
|
||||||
assert mime.get_all("Received")
|
assert mime.get_all("Received")
|
||||||
assert ac2.get_mime_headers(ac2.get_message_by_id(in_id)).get_all("From")
|
|
||||||
|
|
||||||
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")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue