def test_ab_contact_searchpath(ab, gab_contact_folder): searchpath = ab.GetSearchPath(MAPI_UNICODE) assert len(searchpath) == 2 assert PpropFindProp(searchpath[0], PR_DISPLAY_NAME_W) == SPropValue( 0x3001001F, 'Global Address Book') assert PpropFindProp(searchpath[1], PR_DISPLAY_NAME_W) == SPropValue( 0x3001001F, 'User Folder')
def test_ab_folder_single_contact(gab_contact_folder, gab_contacts, single_contact): hierarchy = gab_contacts.GetHierarchyTable(MAPI_UNICODE) rows = hierarchy.QueryRows(-1, 0) eid = PpropFindProp(rows[0], PR_ENTRYID) usercont = gab_contacts.OpenEntry(eid.Value, None, 0) contents = usercont.GetContentsTable(MAPI_UNICODE) rows = contents.QueryRows(-1, 0) assert len(rows) == 1 eid = PpropFindProp(rows[0], PR_ENTRYID) contact = usercont.OpenEntry(eid.Value, None, 0) assert contact
def test_ab_folder_multi_hierarchy(gab_contact_folder, gab_custom_folder, ab, abroot): gab_contacts = assert_get_contact_folder(ab, abroot) hierarchy = gab_contacts.GetHierarchyTable(MAPI_UNICODE) rows = hierarchy.QueryRows(-1, 0) assert len(rows) == 2 display_name = PpropFindProp(rows[0], PR_DISPLAY_NAME_W) assert display_name.Value == 'User Folder' display_name = PpropFindProp(rows[1], PR_DISPLAY_NAME_W) assert display_name.Value == 'Custom Folder'
def test_public_contacts(ab, abroot, gab_public_contact, public_contact): gab_contacts = assert_get_contact_folder(ab, abroot) hierarchy = gab_contacts.GetHierarchyTable(MAPI_UNICODE) rows = hierarchy.QueryRows(-1, 0) assert len(rows) == 1 displayname = PpropFindProp(rows[0], PR_DISPLAY_NAME_W) assert displayname.Value == 'Public Contacts' eid = PpropFindProp(rows[0], PR_ENTRYID) usercont = gab_contacts.OpenEntry(eid.Value, None, 0) contents = usercont.GetContentsTable(MAPI_UNICODE) rows = contents.QueryRows(-1, 0) assert len(rows) == 1
def assert_get_contact_folder(ab, abroot): hierarchy = abroot.GetHierarchyTable(MAPI_UNICODE) eid, store_eid = None, None for row in hierarchy.QueryRows(-1, 0): prop = PpropFindProp(row, PR_AB_PROVIDER_ID) if prop.Value == CONTACTS_GUID: store_eid = PpropFindProp(row, PR_AB_PROVIDER_ID) eid = PpropFindProp(row, PR_ENTRYID) break assert store_eid assert eid return ab.OpenEntry(eid.Value, None, 0)
def test_ab_depth(abroot, gab_contact_folder): hierarchy = abroot.GetHierarchyTable(MAPI_UNICODE | CONVENIENT_DEPTH) hierarchy.Restrict( SPropertyRestriction(RELOP_EQ, PR_AB_PROVIDER_ID, SPropValue(PR_AB_PROVIDER_ID, CONTACTS_GUID)), 0) rows = hierarchy.QueryRows(-1, 0) assert len(rows) == 2 assert PpropFindProp(rows[0], PR_DISPLAY_NAME_W).Value == 'Kopano Contacts Folders' assert PpropFindProp(rows[0], PR_DEPTH).Value == 0 assert PpropFindProp(rows[1], PR_DISPLAY_NAME_W).Value == 'User Folder' assert PpropFindProp(rows[1], PR_DEPTH).Value == 1
def get_gab_contacts_rows(gab_contacts): hierarchy = gab_contacts.GetHierarchyTable(MAPI_UNICODE) rows = hierarchy.QueryRows(-1, 0) eid = PpropFindProp(rows[0], PR_ENTRYID) usercont = gab_contacts.OpenEntry(eid.Value, None, 0) contents = usercont.GetContentsTable(MAPI_UNICODE) return contents.QueryRows(-1, 0)
def test_shared_contacts(ab, abroot, gab_shared_contacts): gab_contacts = assert_get_contact_folder(ab, abroot) hierarchy = gab_contacts.GetHierarchyTable(MAPI_UNICODE) rows = hierarchy.QueryRows(-1, 0) assert len(rows) == 1 displayname = PpropFindProp(rows[0], PR_DISPLAY_NAME_W) assert displayname.Value == 'Shared Contacts'
def test_html_charset_01(session, store, message, dopt): rfc = open(MAILS_PATH.format('html-charset-01.eml'), 'rb').read() inetmapi.IMToMAPI(session, store, None, message, rfc, dopt) attachtable = message.GetAttachmentTable(0) props = attachtable.QueryRows(-1, 0) prop = PpropFindProp(props[0], PR_ATTACH_NUM) attachment = message.OpenAttach(0, IID_IAttachment, 0) props = attachment.GetProps([PR_ATTACH_MIME_TAG_W, PR_ATTACH_DATA_BIN], 0) assert props[0].Value == "text/html" assert props[1].Value == b"body\xd0\xa7\n"
def test_ab_folder_incomplete_contact(gab_contact_folder, gab_contacts, incomplete_contact): hierarchy = gab_contacts.GetHierarchyTable(MAPI_UNICODE) rows = hierarchy.QueryRows(-1, 0) eid = PpropFindProp(rows[0], PR_ENTRYID) usercont = gab_contacts.OpenEntry(eid.Value, None, 0) contents = usercont.GetContentsTable(MAPI_UNICODE) rows = contents.QueryRows(-1, 0) # no contact here, since it was invalid! assert len(rows) == 0
def test_unknown_text_charset(session, store, message, dopt): rfc = open(MAILS_PATH.format('unknown-text-charset.eml'), 'rb').read() inetmapi.IMToMAPI(session, store, None, message, rfc, dopt) attachtable = message.GetAttachmentTable(0) props = attachtable.QueryRows(-1, 0) prop = PpropFindProp(props[0], PR_ATTACH_NUM) attachment = message.OpenAttach(0, IID_IAttachment, 0) props = attachment.GetProps([PR_ATTACH_MIME_TAG_W, PR_ATTACH_DATA_BIN], 0) assert props[0].Value == "text/plain" assert props[1].Value == b'\xe2\x98\xba'
def test_ab_folder_gab_distlist(gab_contact_folder, gab_contacts, gab_distlist): '''DistList with GAB contacts''' hierarchy = gab_contacts.GetHierarchyTable(MAPI_UNICODE) rows = hierarchy.QueryRows(-1, 0) eid = PpropFindProp(rows[0], PR_ENTRYID) usercont = gab_contacts.OpenEntry(eid.Value, None, 0) contents = usercont.GetContentsTable(MAPI_UNICODE) rows = contents.QueryRows(-1, 0) assert len(rows) == 1
def test_rfc2045_sec6_4(session, store, message, dopt): # On unknown Content-Transfer-Encodings, the MIME part needs to be # read raw and tagged application/octet-stream (RFC 2045 ยง6.4 pg 17). rfc = open(MAILS_PATH.format('unknown-transfer-enc.eml'), 'rb').read() inetmapi.IMToMAPI(session, store, None, message, rfc, dopt) attachtable = message.GetAttachmentTable(0) props = attachtable.QueryRows(-1, 0) prop = PpropFindProp(props[0], PR_ATTACH_NUM) attachment = message.OpenAttach(0, IID_IAttachment, 0) props = attachment.GetProps([PR_ATTACH_MIME_TAG_W, PR_ATTACH_DATA_BIN], 0) assert props[0].Value == "application/octet-stream" assert props[1].Value == b"=E2=98=BA"
def test_ab_root_hierarchy(abroot): hierarchy = abroot.GetHierarchyTable(MAPI_UNICODE) rows = hierarchy.QueryRows(-1, 0) assert len(rows) == 3 providers = 0 for row in rows: prop = PpropFindProp(row, PR_AB_PROVIDER_ID) assert prop if prop.Value == MUIDECSAB: providers |= 1 if prop.Value == CONTACTS_GUID: providers |= 2 assert providers == (1 | 2)
def test_redirect_rule(lmtpclient, inbox, outbox, gab_user, rules, sink, create_test_email): '''Redirect mail matching subject to KOPANO_TEST_USER''' subject = 'forward rule' sender = '*****@*****.**' receiver = os.getenv('KOPANO_TEST_EMAIL') create_forward_rule(rules, subject, gab_user, 0x3) # 3 = FWD_PRESERVE_SENDER | FWD_DO_NOT_MUNGE_MSG) msg = create_test_email(sender, receiver, subject, '') lmtpclient.sendmail(sender, receiver, msg.as_string()) sink.WaitForNotification(60) table = inbox.GetContentsTable(0) rowcount = table.GetRowCount(0) assert rowcount == 1 table = outbox.GetContentsTable(0) table.SetColumns([PR_ENTRYID], 0) rowcount = table.GetRowCount(0) assert rowcount == 1 rows = table.QueryRows(1, 0) assert rows item = outbox.OpenEntry(rows[0][0].Value, None, 0) reciptable = item.GetRecipientTable(0) recips = reciptable.QueryRows(-1, 0) assert PpropFindProp(recips[0], PR_RECIPIENT_TYPE).Value == MAPI_TO # Sender has no recipient type set assert not PpropFindProp(recips[1], PR_RECIPIENT_TYPE) assert PpropFindProp(recips[0], PR_EMAIL_ADDRESS).Value == PpropFindProp( recips[1], PR_EMAIL_ADDRESS).Value
def test_forward_external_rule(lmtpclient, inbox, outbox, rules, sink, reply_template, create_test_email): '''Forward mail matching subject to [email protected], should be disallowed with an reject in inbox''' subject = 'forward external rule' sender = '*****@*****.**' external = '*****@*****.**' receiver = os.getenv('KOPANO_TEST_EMAIL') external = [ SPropValue(PR_ADDRTYPE, b'SMTP'), SPropValue(PR_EMAIL_ADDRESS, external.encode()), SPropValue(PR_SMTP_ADDRESS, external.encode()), SPropValue(PR_DISPLAY_NAME, 'external contractor'.encode()), SPropValue(PR_OBJECT_TYPE, 6), SPropValue(PR_RECIPIENT_TYPE, MAPI_TO), SPropValue(PR_SEARCH_KEY, b'SMTP:' + external.encode()) ] create_forward_rule(rules, subject, [external]) msg = create_test_email(sender, receiver, subject, '') lmtpclient.sendmail(sender, receiver, msg.as_string()) sink.WaitForNotification(60) table = inbox.GetContentsTable(0) rowcount = table.GetRowCount(0) assert rowcount == 2 rows = table.QueryRows(2, 0) assert subject.encode() == PpropFindProp(rows[0], PR_SUBJECT).Value assert b'rule not forwarded (administratively blocked)' in PpropFindProp( rows[1], PR_SUBJECT).Value table = outbox.GetContentsTable(0) rowcount = table.GetRowCount(0) assert not rowcount
def test_get_searchpath(addressbook): searchpath = addressbook.GetSearchPath(MAPI_UNICODE) # should only contain Global Address Book assert len(searchpath) == 1 assert PpropFindProp(searchpath[0], PR_DISPLAY_NAME_W) == SPropValue( 0x3001001F, 'Global Address Book')
def test_ab_getsearchpath(ab): searchpath = ab.GetSearchPath(MAPI_UNICODE) assert len(searchpath) == 1 assert PpropFindProp(searchpath[0], PR_DISPLAY_NAME_W) == SPropValue( 0x3001001F, 'Global Address Book')