コード例 #1
0
ファイル: outlook.py プロジェクト: dfraser74/taskcoach
    def getCurrentSelection():
        obj = GetActiveObject('Outlook.Application')
        exp = obj.ActiveExplorer()
        sel = exp.Selection

        ret = []
        for n in xrange(1, sel.Count + 1):
            src = tempfile.NamedTemporaryFile(
                suffix='.eml')  # Will be deleted automagically
            src.close()
            sel.Item(n).SaveAs(src.name, 0)
            src = file(src.name, 'rb')

            # Okay. In the case of HTML mails, Outlook doesn't put
            # a blank line between the last header line and the
            # body. This assumes that the last header is
            # Subject:. Hope it's true.

            # States:
            # 0       still in headers
            # 1       subject: header seen, blank line not written
            # 2       all headers seen, blank line written
            # 2       in body

            name = persistence.get_temp_file(suffix='.eml')
            dst = file(name, 'wb')
            try:
                s = 0
                for line in src:
                    if s == 0:
                        dst.write(line)
                        if line.lower().startswith('subject:'):
                            dst.write('X-Outlook-ID: %s\r\n' %
                                      str(sel.Item(n).EntryID))
                            s = 1
                    elif s == 1:
                        dst.write('\r\n')
                        if line.strip() != '':
                            dst.write(line)
                        s = 2
                    else:
                        dst.write(line)
            finally:
                dst.close()
                if os.name == 'nt':
                    os.chmod(name, stat.S_IREAD)
            ret.append(name)

        return ret
コード例 #2
0
def openMailWithOutlook(filename):
    id_ = None
    for line in file(filename, 'r'):
        if line.startswith('X-Outlook-ID:'):
            id_ = line[13:].strip()
            break
        elif line.strip() == '':
            break

    if id_ is None:
        return False

    from win32com.client import GetActiveObject  # pylint: disable=F0401
    app = GetActiveObject('Outlook.Application')
    app.ActiveExplorer().Session.GetItemFromID(id_).Display()

    return True