Пример #1
0
def test_zcp_13036_0d(session, store, message):
    rfc = open(MAILS_PATH.format('zcp-13036-0db504a2.eml'), 'rb').read()
    dopt = inetmapi.delivery_options()
    inetmapi.IMToMAPI(session, store, None, message, rfc, dopt)
    props = message.GetProps([PR_INTERNET_CPID, PR_BODY_W], 0)
    assert GetCharsetByCP(props[0].Value) == "utf-8"
    assert "zgłoszeń" in props[1].Value
Пример #2
0
def test_mime_charset_03(session, store, message, dopt):
    rfc = open(MAILS_PATH.format('mime_charset_03.eml'), 'rb').read()
    dopt.ascii_upgrade = None
    inetmapi.IMToMAPI(session, store, None, message, rfc, dopt)
    props = message.GetProps([PR_INTERNET_CPID], 0)
    charset = GetCharsetByCP(props[0].Value)
    assert charset == "us-ascii"
Пример #3
0
def test_html_charset_02(session, store, message, dopt):
    rfc = open(MAILS_PATH.format('html-charset-02.eml'), 'rb').read()
    dopt.charset_strict_rfc = False
    inetmapi.IMToMAPI(session, store, None, message, rfc, dopt)
    props = message.GetProps([PR_INTERNET_CPID], 0)
    charset = GetCharsetByCP(props[0].Value)
    assert charset == "iso-8859-1"
Пример #4
0
def test_big5(session, store, message, dopt):
    rfc = open(MAILS_PATH.format('big5.eml'), 'rb').read()
    dopt.ascii_upgrade = "big5"
    inetmapi.IMToMAPI(session, store, None, message, rfc, dopt)
    props = message.GetProps([PR_SUBJECT_W], 0)

    assert props[0].Value == "?i???h?u?W?q??"
Пример #5
0
def test_zcp_13036_69(session, store, message):
    rfc = open(MAILS_PATH.format('zcp-13036-6906a338.eml'), 'rb').read()
    dopt = inetmapi.delivery_options()
    inetmapi.IMToMAPI(session, store, None, message, rfc, dopt)
    props = message.GetProps([PR_INTERNET_CPID, PR_BODY_W], 0)
    assert GetCharsetByCP(props[0].Value) == "iso-8859-1"
    assert "Jänner" in props[1].Value
Пример #6
0
def test_kc_138_2(session, store, message, dopt):
    rfc = open(MAILS_PATH.format('kc-138-2.eml'), 'rb').read()
    inetmapi.IMToMAPI(session, store, None, message, rfc, dopt)
    props = message.GetProps([PR_BODY_W], 0)

    # Ensure iCal object description does not override earlier bodies
    assert "part1" in props[0].Value or "part2" in props[0].Value
Пример #7
0
def test_mime_charset_01(session, store, message, dopt, eml):
    rfc = open(MAILS_PATH.format(eml), 'rb').read()
    inetmapi.IMToMAPI(session, store, None, message, rfc, dopt)
    props = message.GetProps([PR_INTERNET_CPID, PR_BODY_W], 0)
    charset = GetCharsetByCP(props[0].Value)
    assert charset == "utf-8"
    assert props[1].Value == "tæst"
Пример #8
0
def test_zcp_13439_nl(session, store, message, dopt):
    rfc = open(MAILS_PATH.format('zcp-13439-nl.eml'), 'rb').read()
    inetmapi.IMToMAPI(session, store, None, message, rfc, dopt)
    props = message.GetProps([PR_INTERNET_CPID, PR_BODY_W, PR_SUBJECT_W], 0)

    assert GetCharsetByCP(props[0].Value) == "utf-8"
    assert "für" in props[1].Value
    assert "Ää Öö Üü ß – Umlautetest, UMLAUTETEST 2" == props[2].Value
Пример #9
0
def test_zcp_13175(session, store, message, dopt):
    rfc = open(MAILS_PATH.format('zcp-13175.eml'), 'rb').read()
    inetmapi.IMToMAPI(session, store, None, message, rfc, dopt)
    props = message.GetProps([PR_INTERNET_CPID, PR_BODY_W], 0)

    assert GetCharsetByCP(props[0].Value) == "utf-8"
    print(props[1].Value)
    assert "extrem überhöht" in props[1].Value
Пример #10
0
def test_zcp_13449_meca(session, store, message, dopt):
    rfc = open(MAILS_PATH.format('zcp-13449-meca.eml'), 'rb').read()
    dopt.charset_strict_rfc = False
    inetmapi.IMToMAPI(session, store, None, message, rfc, dopt)
    props = message.GetProps([PR_INTERNET_CPID, PR_BODY_W], 0)

    assert GetCharsetByCP(props[0].Value) == "windows-1252"
    assert "Mécanique" in props[1].Value
Пример #11
0
def test_zcp_13337(session, store, message, dopt):
    rfc = open(MAILS_PATH.format('zcp-13337.eml'), 'rb').read()
    inetmapi.IMToMAPI(session, store, None, message, rfc, dopt)
    props = message.GetProps([PR_INTERNET_CPID, PR_BODY_W], 0)

    assert GetCharsetByCP(props[0].Value) == "utf-8"
    # non breaking space
    assert "\xa0" in props[1].Value
Пример #12
0
def test_iconvonly(session, store, message, dopt, eml):
    # iconvonly01 has a charset for which no Win32 CPID exists (at
    # least in our codepage.cpp), and so gets reconverted by inetmapi
    # to UTF-8 so Windows has something to display.
    rfc = open(MAILS_PATH.format(eml), 'rb').read()
    inetmapi.IMToMAPI(session, store, None, message, rfc, dopt)
    props = message.GetProps([PR_INTERNET_CPID], 0)
    charset = GetCharsetByCP(props[0].Value)
    assert charset == "utf-8"
Пример #13
0
def test_gb2312_18030(session, store, message, dopt):
    rfc = open(MAILS_PATH.format('gb2312_18030.eml'), 'rb').read()
    inetmapi.IMToMAPI(session, store, None, message, rfc, dopt)

    props = message.GetProps([PR_SENDER_NAME_W, PR_DISPLAY_TO_W, PR_SUBJECT_W],
                             0)
    assert props[0].Value == "梁祐晟"
    assert props[1].Value == "'林慶美'"
    assert props[2].Value == '讀取: ??排??生?a'
Пример #14
0
def test_zcp_12930(session, store, message, dopt):
    rfc = open(MAILS_PATH.format('zcp-12930.eml'), 'rb').read()
    dopt.ascii_upgrade = None
    inetmapi.IMToMAPI(session, store, None, message, rfc, dopt)
    props = message.GetProps([PR_INTERNET_CPID, PR_BODY_W], 0)

    charset = GetCharsetByCP(props[0].Value)
    assert charset == "us-ascii"

    assert "simply dummy t ext" in props[1].Value
Пример #15
0
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"
Пример #16
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'
Пример #17
0
def test_zcp_11713(session, store, message, dopt):
    rfc = open(MAILS_PATH.format('zcp-11713.eml'), 'rb').read()
    dopt.charset_strict_rfc = False
    inetmapi.IMToMAPI(session, store, None, message, rfc, dopt)
    props = message.GetProps([PR_INTERNET_CPID, PR_BODY_W], 0)

    # ISO-2022-JP (50220, 50222) is a valid outcome of any decoder.
    # SHIFT_JIS (932) is a possible outcome of ZCP's IMToMAPI, but not
    # strictly RFC-conformant.
    charset = GetCharsetByCP(props[0].Value)
    assert charset == "shift-jis"
    assert "メッセージ" in props[1].Value
Пример #18
0
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"
Пример #19
0
def test_zcp_13449_na(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('zcp-13449-na.eml'), 'rb').read()
    dopt.ascii_upgrade = None
    inetmapi.IMToMAPI(session, store, None, message, rfc, dopt)
    props = message.GetProps([PR_INTERNET_CPID, PR_BODY_W, PR_SUBJECT_W], 0)

    assert GetCharsetByCP(props[0].Value) == "us-ascii"
    # All non-ASCII is stripped, and the '!' is the leftover.
    assert "!" in props[1].Value
    # May need rework depending on how unreadable characters
    # are transformed (decoder dependent).
    assert "N??t ASCII??????" == props[2].Value
Пример #20
0
 def addMessage(self, rfc):
     msg = self.dest.CreateMessage(None, 0)
     try:
         inetmapi.IMToMAPI(self.session, self.store, self.abook, msg,
                           str(rfc), self.dopt)
     except:
         self.errors += 1
         return
     try:
         # mark as read when rfc['status'] contains R (mbox only)
         if 'R' in rfc['status']:
             msg.SetProps([SPropValue(PR_MESSAGE_FLAGS, MSGFLAG_READ)])
     except:
         pass
     msg.SaveChanges(0)
Пример #21
0
    def __init__(self,
                 parent=None,
                 eml=None,
                 ics=None,
                 vcf=None,
                 load=None,
                 loads=None,
                 attachments=True,
                 create=False,
                 mapiobj=None,
                 entryid=None,
                 content_flag=None,
                 save=True):
        self.emlfile = None
        self._architem = None
        self._folder = None
        self.mapiobj = mapiobj
        self._entryid = entryid
        self._content_flag = content_flag or 0

        if isinstance(parent, _folder.Folder):
            self._folder = parent
            self.store = parent.store
            self.server = parent.server
        elif isinstance(parent, _store.Store):
            self.store = store
            self.server = store.server

        if create:
            self.mapiobj = self.folder.mapiobj.CreateMessage(
                None, MAPI_ASSOCIATED if self.folder.content_flag
                & MAPI_ASSOCIATED else 0)
            self.store = self.folder.store
            self.server = server = self.store.server  # XXX

            if _is_file(eml):
                eml = eml.read()
            if _is_file(ics):
                ics = ics.read()
            if _is_file(vcf):
                vcf = vcf.read()

            self.emlfile = eml

            if eml is not None:
                # options for CreateMessage: 0 / MAPI_ASSOCIATED
                dopt = inetmapi.delivery_options()
                inetmapi.IMToMAPI(server.mapisession,
                                  self.folder.store.mapiobj, None,
                                  self.mapiobj, self.emlfile, dopt)
                pass
            elif ics is not None:
                icm = icalmapi.CreateICalToMapi(self.mapiobj, server.ab, False)
                icm.ParseICal(ics, 'utf-8', '', None, 0)
                icm.GetItem(0, 0, self.mapiobj)
            elif vcf is not None:
                vcm = icalmapi.create_vcftomapi(self.mapiobj)
                vcm.parse_vcf(vcf)
                vcm.get_item(self.mapiobj)
            elif load is not None:
                self.load(load, attachments=attachments)
            elif loads is not None:
                self.loads(loads, attachments=attachments)
            else:
                try:
                    container_class = HrGetOneProp(self.folder.mapiobj,
                                                   PR_CONTAINER_CLASS).Value
                except MAPIErrorNotFound:
                    self.mapiobj.SetProps(
                        [SPropValue(PR_MESSAGE_CLASS_W, u'IPM.Note')])
                else:
                    if container_class == 'IPF.Contact':  # XXX just skip first 4 chars?
                        self.mapiobj.SetProps([
                            SPropValue(PR_MESSAGE_CLASS_W, u'IPM.Contact')
                        ])  # XXX set default props
                    elif container_class == 'IPF.Appointment':
                        self.mapiobj.SetProps([
                            SPropValue(PR_MESSAGE_CLASS_W, u'IPM.Appointment')
                        ])  # XXX set default props
            if save:
                self.mapiobj.SaveChanges(KEEP_OPEN_READWRITE)
Пример #22
0
def test_zcp_13473(session, store, message, dopt):
    rfc = open(MAILS_PATH.format('zcp-13473.eml'), 'rb').read()
    inetmapi.IMToMAPI(session, store, None, message, rfc, dopt)
    props = message.GetProps([PR_INTERNET_CPID], 0)

    assert GetCharsetByCP(props[0].Value) == "utf-8"
Пример #23
0
def test_zcp_11699_p(session, store, message, eml, dopt):
    rfc = open(MAILS_PATH.format(eml), 'rb').read()
    inetmapi.IMToMAPI(session, store, None, message, rfc, dopt)
    props = message.GetProps([PR_SUBJECT_W, PR_BODY_W], 0)
    assert props[0].Value == "☺ dum"
    assert props[1].Value == "☺ dummy ☻"
Пример #24
0
def test_encword_split(session, store, message, dopt):
    rfc = open(MAILS_PATH.format('encoded-word-split.eml'), 'rb').read()
    inetmapi.IMToMAPI(session, store, None, message, rfc, dopt)
    props = message.GetProps([PR_SUBJECT_W], 0)
    assert props[0].Value == "☺ vų. ?뮘"
Пример #25
0
    def __init__(self, folder=None, eml=None, ics=None, vcf=None, load=None,
                 loads=None, attachments=True, create=False, mapiobj=None,
                 entryid=None, content_flag=None, cache={}, save=True):
        self._eml = None
        self._architem = None
        self._folder = None
        self.mapiobj = mapiobj
        self._entryid = entryid
        self._content_flag = content_flag or 0
        self._cache = cache

        if folder:
            self._folder = folder
            self.store = folder.store
            self.server = folder.server

        if create:
            self.mapiobj = self.folder.mapiobj.CreateMessage(None, MAPI_ASSOCIATED if self.folder.content_flag & MAPI_ASSOCIATED else 0)
            self.store = self.folder.store
            self.server = server = self.store.server # XXX

            if _is_file(eml):
                eml = eml.read()
            if _is_file(ics):
                ics = ics.read()
            if _is_file(vcf):
                vcf = vcf.read()

            self._eml = eml

            if eml is not None:
                # options for CreateMessage: 0 / MAPI_ASSOCIATED
                dopt = inetmapi.delivery_options()
                inetmapi.IMToMAPI(server.mapisession, self.folder.store.mapiobj, None, self.mapiobj, self._eml, dopt)
                pass
            elif ics is not None:
                icm = icalmapi.CreateICalToMapi(self.mapiobj, server.ab, False)
                icm.ParseICal(ics, 'utf-8', 'UTC', self.user.mapiobj, 0)
                icm.GetItem(0, 0, self.mapiobj)
            elif vcf is not None:
                vcm = icalmapi.create_vcftomapi(self.mapiobj)
                vcm.parse_vcf(vcf)
                vcm.get_item(self.mapiobj)
            elif load is not None:
                self.load(load, attachments=attachments)
            elif loads is not None:
                self.loads(loads, attachments=attachments)
            else:
                try:
                    container_class = HrGetOneProp(self.folder.mapiobj, PR_CONTAINER_CLASS_W).Value
                except MAPIErrorNotFound:
                    self.mapiobj.SetProps([SPropValue(PR_MESSAGE_CLASS_W, u'IPM.Note')])
                else:
                    if container_class == 'IPF.Contact': # TODO just skip first 4 chars?
                        self.mapiobj.SetProps([SPropValue(PR_MESSAGE_CLASS_W, u'IPM.Contact')]) # TODO set all default props
                    elif container_class == 'IPF.Appointment':
                        self.mapiobj.SetProps([SPropValue(PR_MESSAGE_CLASS_W, u'IPM.Appointment')]) # TODO set all default props!!
                        self.from_ = self.store.user
                        self[PidLidAppointmentStateFlags] = 1
                        self[PidLidResponseStatus] = 1 # TODO move appt creation to appointment.py
                        self[PidLidFInvited] = False
            if save:
                _utils._save(self.mapiobj)
Пример #26
0
def test_zcp_11581(session, store, message, dopt):
    rfc = open(MAILS_PATH.format('zcp-11581.eml'), 'rb').read()
    inetmapi.IMToMAPI(session, store, None, message, rfc, dopt)
    props = message.GetProps([PR_BODY_W], 0)
    assert "RFC-compliant" in props[0].Value