Пример #1
0
def test_rtfhebrew(message):
    rtf = b"{\\rtf1\\fbidis\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fswiss\\fcharset177 Arial;}{\\f1\\fswiss\\fcharset0 Verdana;}}\n{\\colortbl ;\\red0\\green0\\blue0;}\n{\\*\\generator Riched20 12.0.4518.1014;}\\viewkind4\\uc1\n\\pard\\ltrpar\\cf1\\f0\\rtlch\\fs32\\lang1037\\'f9\\'f4\\'e5\\'f8\\'f1\\'ee\\'e5 \\'e1\\'f2\\'e9\\'fa\\'e5\\'ef \\'e4\\'e0\\'f8\\'f5 \\'e5\\'ee\\'e1\\'e6\\'f7\\'e9\\'ed \\'e4\\'ee\\'f2\\'e5\\'e3\\'eb\\'f0\\'e9\\'ed \\'e1\\'e6\\'ee\\'ef \\'e0\\'ee\\'fa \\'e1\\'f0\\'e5\\'f9\\'e0\\'e9\\'ed \\'ee\\'e3\\'e9\\'f0\\'e9\\par\n\\f1\\ltrch\\lang1033\\par\n}"
    comp = message.OpenProperty(PR_RTF_COMPRESSED, IID_IStream, STGM_WRITE,
                                MAPI_MODIFY | MAPI_CREATE)
    uncomp = WrapCompressedRTFStream(comp, 0)
    uncomp.Write(rtf)
    uncomp.Commit(0)
    comp.Commit(0)
    comp.Seek(0, 0)
    body = message.GetProps([PR_BODY], 0)[0].Value
    assert body == u'שפורסמו בעיתון הארץ ומבזקים המעודכנים בזמן אמת בנושאים מדיני\r\n'.encode(
        'utf8')
Пример #2
0
def test_RTF_smarttags1(message):
    rtf = b"""
    {\\*\\xmlopen\\xmlns0{\\factoidname PersonName}}Name{\\*\\xmlclose}
    """
    comp = message.OpenProperty(PR_RTF_COMPRESSED, IID_IStream, STGM_WRITE,
                                MAPI_MODIFY | MAPI_CREATE)
    uncomp = WrapCompressedRTFStream(comp, 0)
    uncomp.Write(rtf)
    uncomp.Commit(0)
    comp.Commit(0)
    comp.Seek(0, 0)
    body = message.GetProps([PR_BODY], 0)[0].Value
    assert body == b'Name\r\n'
Пример #3
0
def test_RTF_smarttags2(message):
    # Example from http://support.microsoft.com/kb/922681
    rtf = b"""
    {\\*\\xmlopen\\xmlns2{\\factoidname date}
    {\\xmlattr\\xmlattrns0{\\xmlattrname Month}{\\xmlattrvalue 4}}
    {\\xmlattr\\xmlattrns0{\\xmlattrname Day}{\\xmlattrvalue 11}}
    {\\xmlattr\\xmlattrns0{\\xmlattrname Year}{\\xmlattrvalue 2006}}}4/11/2006}
    {\\*\\xmlclose}
    """
    comp = message.OpenProperty(PR_RTF_COMPRESSED, IID_IStream, STGM_WRITE,
                                MAPI_MODIFY | MAPI_CREATE)
    uncomp = WrapCompressedRTFStream(comp, 0)
    uncomp.Write(rtf)
    uncomp.Commit(0)
    comp.Commit(0)
    comp.Seek(0, 0)
    body = message.GetProps([PR_BODY], 0)[0].Value
    assert body == b'4/11/2006\r\n'
Пример #4
0
def test_RTF_generator_nosemicolon(message):
    rtf = b"""
    {\\rtf1\\ansi\\ansicpg1252\\deff0\\nouicompat\\deflang1033{\\fonttbl{\\f0\\fswiss\\fcharset0 Calibri;}}
    {\\*\\generator Riched20 15.0.4737}
    \\pard\\cf1\\f0\\fs22 1\\par 2\\par 2\\par 3\\par 4\\par 5\\par}
    """
    comp = message.OpenProperty(PR_RTF_COMPRESSED, IID_IStream, STGM_WRITE,
                                MAPI_MODIFY | MAPI_CREATE)
    uncomp = WrapCompressedRTFStream(comp, 0)
    uncomp.Write(rtf)
    uncomp.Commit(0)
    comp.Commit(0)
    comp.Seek(0, 0)
    body = message.GetProps([PR_BODY], 0)[0].Value
    assert b''.join(body.splitlines()).strip() == b'122345'
    html = message.GetProps([PR_HTML], 0)[0].Value
    assert b'Riched20' not in html
    assert b'1</p>' in html
    assert b'<p>2</p>' in html
    assert b'<p>3</p>' in html
    assert b'<p>4</p>' in html
    assert b'<p>5' in html
Пример #5
0
 def rtf(self, x):
     stream = self._arch_item.OpenProperty(PR_RTF_COMPRESSED, IID_IStream, STGM_WRITE | STGM_TRANSACTED, MAPI_MODIFY | MAPI_CREATE)
     uncompressed = WrapCompressedRTFStream(stream, MAPI_MODIFY)
     uncompressed.Write(x)
     uncompressed.Commit(0)
     stream.Commit(0)
Пример #6
0
def test_rtfcyrilliceuro(message):
    rtf = b"""
    {\\rtf1\\ansi\\ansicpg1251\\fromhtml1 \\deff0{\\fonttbl
    {\\f0\\fswiss Arial;}
    {\\f1\\fmodern Courier New;}
    {\\f2\\fnil\\fcharset2 Symbol;}
    {\\f3\\fmodern\\fcharset0 Courier New;}
    {\\f4\\fswiss\\fcharset204 Arial;}}
    {\\colortbl\\red0\\green0\\blue0;\\red0\\green0\\blue255;}
    \\uc1\\pard\\plain\\deftab360 \\f0\\fs24
    {\\*\\htmltag19 <html>}
    {\\*\\htmltag2 \\par }
    {\\*\\htmltag2 \\par }
    {\\*\\htmltag34 <head>}
    {\\*\\htmltag1 \\par }
    {\\*\\htmltag1 \\par }
    {\\*\\htmltag161 <meta name=Generator content="Microsoft Word 11 (filtered)">}
    {\\*\\htmltag1 \\par }
    {\\*\\htmltag241 <style>}
    {\\*\\htmltag241 \\par <!--\\par  /* Font Definitions */\\par  @font-face\\par \\tab \\{font-family:SimSun;\\par \\tab panose-1:2 1 6 0 3 1 1 1 1 1;\\}\\par @font-face\\par \\tab \\{font-family:"\\\\@SimSun";\\par \\tab panose-1:2 1 6 0 3 1 1 1 1 1;\\}\\par  /* Style Definitions */\\par  p.MsoNormal, li.MsoNormal, div.MsoNormal\\par \\tab \\{margin:0in;\\par \\tab margin-bottom:.0001pt;\\par \\tab font-size:12.0pt;\\par \\tab font-family:"Times New Roman";\\}\\par a:link, span.MsoHyperlink\\par \\tab \\{color:blue;\\par \\tab text-decoration:underline;\\}\\par a:visited, span.MsoHyperlinkFollowed\\par \\tab \\{color:purple;\\par \\tab text-decoration:underline;\\}\\par span.EmailStyle17\\par \\tab \\{font-family:Arial;\\par \\tab color:windowtext;\\}\\par @page Section1\\par \\tab \\{size:8.5in 11.0in;\\par \\tab margin:1.0in 1.25in 1.0in 1.25in;\\}\\par div.Section1\\par \\tab \\{page:Section1;\\}\\par -->\\par }
    {\\*\\htmltag249 </style>}
    {\\*\\htmltag1 \\par }
    {\\*\\htmltag1 \\par }
    {\\*\\htmltag41 </head>}
    {\\*\\htmltag2 \\par }
    {\\*\\htmltag2 \\par }
    {\\*\\htmltag50 <body lang=EN-US link=blue vlink=purple>}
    {\\*\\htmltag0 \\par }
    {\\*\\htmltag0 \\par }
    {\\*\\htmltag96 <div class=Section1>}\\htmlrtf {\\htmlrtf0
    {\\*\\htmltag0 \\par }
    {\\*\\htmltag0 \\par }
    {\\*\\htmltag64 <p class=MsoNormal>}\\htmlrtf {\\htmlrtf0
    {\\*\\htmltag148 <font size=2 face=Arial>}\\htmlrtf {\\fs20 \\f4 \\htmlrtf0
    {\\*\\htmltag84 <span style='font-size:10.0pt;\\par font-family:Arial'>}\\htmlrtf {\\htmlrtf0 Test \\'88
    {\\*\\htmltag92 </span>}\\htmlrtf }\\htmlrtf0
    {\\*\\htmltag156 </font>}\\htmlrtf }\\htmlrtf0 \\htmlrtf\\par}\\htmlrtf0
    \\htmlrtf \\par
    \\htmlrtf0
    {\\*\\htmltag72 </p>}
    {\\*\\htmltag0 \\par }
    {\\*\\htmltag0 \\par }
    {\\*\\htmltag104 </div>}\\htmlrtf }\\htmlrtf0
    {\\*\\htmltag0 \\par }
    {\\*\\htmltag0 \\par }
    {\\*\\htmltag58 </body>}
    {\\*\\htmltag2 \\par }
    {\\*\\htmltag2 \\par }
    {\\*\\htmltag27 </html>}
    {\\*\\htmltag3 \\par }}
    """

    comp = message.OpenProperty(PR_RTF_COMPRESSED, IID_IStream, STGM_WRITE,
                                MAPI_MODIFY | MAPI_CREATE)
    uncomp = WrapCompressedRTFStream(comp, 0)
    uncomp.Write(rtf)
    uncomp.Commit(0)
    comp.Commit(0)
    comp.Seek(0, 0)
    body = message.GetProps([PR_BODY], 0)[0].Value
    assert body == 'Test €\r\n'.encode('utf8')
Пример #7
0
    def PreSending(self, session, addrbook, store, folder, message):

        if not os.path.isdir(self.disclaimerdir):
            self.logger.logWarn(
                "!--- Disclaimer directory '%s' doesn't exist." %
                self.disclaimerdir)
            return MP_CONTINUE,

        company = None

        props = store.GetProps([PR_USER_ENTRYID], 0)
        if props[0].ulPropTag == PR_USER_ENTRYID:
            currentuser = session.OpenEntry(props[0].Value, None, 0)

            userprops = currentuser.GetProps([PR_EC_COMPANY_NAME_W], 0)
            if userprops[0].ulPropTag == PR_EC_COMPANY_NAME_W and len(
                    userprops[0].Value) > 0:
                company = userprops[0].Value.encode("utf-8")
                self.logger.logDebug("*--- Company name is '%s'" % (company))

        bodytag = self.bestBody(message)

        self.logger.logDebug("*--- The message bestbody 0x%08X" % bodytag)
        if bodytag == PR_BODY_W:

            disclaimer = u"\r\n" + codecs.decode(
                self.getDisclaimer('txt', company), 'utf-8')

            bodystream = message.OpenProperty(PR_BODY_W, IID_IStream, 0,
                                              MAPI_MODIFY)
            bodystream.Seek(0, STREAM_SEEK_END)
            bodystream.Write(disclaimer.encode('utf-32-le'))
            bodystream.Commit(0)

        elif bodytag == PR_HTML:
            charset = "us-ascii"
            props = message.GetProps([PR_INTERNET_CPID], 0)
            if props[0].ulPropTag == PR_INTERNET_CPID:
                charset = self.getCharSetByCP(props[0].Value)

            disclaimer = u"<br>" + codecs.decode(
                self.getDisclaimer('html', company), 'utf-8')

            stream = message.OpenProperty(PR_HTML, IID_IStream, 0, MAPI_MODIFY)
            stream.Seek(0, STREAM_SEEK_END)
            stream.Write(disclaimer.encode(charset))
            stream.Commit(0)

        elif bodytag == PR_RTF_COMPRESSED:
            self.logger.logWarn("!--- RTF disclaimer is not supported")
            # RTF not supported because this cause body issues.
            return MP_CONTINUE,

            rtf = self.getDisclaimer('rtf', company)

            stream = message.OpenProperty(PR_RTF_COMPRESSED, IID_IStream, 0,
                                          MAPI_MODIFY)
            uncompressed = WrapCompressedRTFStream(stream, MAPI_MODIFY)

            # Find end tag
            uncompressed.Seek(-5, STREAM_SEEK_END)
            data = uncompressed.Read(5)
            for i in range(4, 0, -1):
                if data[i] == '}':
                    uncompressed.Seek(i - 5, STREAM_SEEK_END)
                    break

            uncompressed.Write(rtf)
            uncompressed.Commit(0)
            stream.Commit(0)
        else:
            self.logger.logWarn("!--- No Body exists")

        return MP_CONTINUE,