make create_contact accept email addresses that parse into routable_email and display_name

This commit is contained in:
holger krekel
2020-03-29 13:53:04 +02:00
parent ca88c5b41c
commit 1b858393c5
2 changed files with 18 additions and 3 deletions

View File

@@ -3,6 +3,7 @@
from __future__ import print_function
import atexit
from contextlib import contextmanager
from email.utils import parseaddr
import queue
from threading import Event
import os
@@ -225,9 +226,12 @@ class Account(object):
:param name: display name for this contact (optional)
:returns: :class:`deltachat.contact.Contact` instance.
"""
name = as_dc_charpointer(name)
email = as_dc_charpointer(email)
contact_id = lib.dc_create_contact(self._dc_context, name, email)
realname, addr = parseaddr(email)
if name:
realname = name
realname = as_dc_charpointer(realname)
addr = as_dc_charpointer(addr)
contact_id = lib.dc_create_contact(self._dc_context, realname, addr)
assert contact_id > const.DC_CHAT_ID_LAST_SPECIAL
return Contact(self, contact_id)

View File

@@ -368,6 +368,17 @@ class TestOfflineChat:
assert msg2 != msg
assert msg2.filename != msg.filename
def test_create_contact(self, acfactory):
ac1 = acfactory.get_configured_offline_account()
email = "hello <hello@example.org>"
contact1 = ac1.create_contact(email)
assert contact1.addr == "hello@example.org"
assert contact1.display_name == "hello"
contact1 = ac1.create_contact(email, name="world")
assert contact1.display_name == "world"
contact2 = ac1.create_contact("display1 <x@example.org>", "real")
assert contact2.display_name == "real"
def test_create_chat_mismatch(self, acfactory):
ac1 = acfactory.get_configured_offline_account()
ac2 = acfactory.get_configured_offline_account()