Ejemplo n.º 1
0
 def getCurrentSelection():
     selection = GetActiveObject('Outlook.Application').ActiveExplorer().Selection
     filenames = []
     for n in xrange(1, selection.Count + 1):
         filename = persistence.get_temp_file(suffix='.eml')
         saveItem(selection.Item(n), filename)
         filenames.append(filename)
     return filenames
Ejemplo n.º 2
0
 def getCurrentSelection():
     selection = GetActiveObject(
         'Outlook.Application').ActiveExplorer().Selection
     filenames = []
     for n in xrange(1, selection.Count + 1):
         filename = persistence.get_temp_file(suffix='.eml')
         saveItem(selection.Item(n), filename)
         filenames.append(filename)
     return filenames
Ejemplo n.º 3
0
def getMail(id_):
    if id_.startswith("mailbox-message://"):
        reader = ThunderbirdMailboxReader(id_)
    elif id_.startswith("imap-message://"):
        reader = ThunderbirdImapReader(id_)
    else:
        raise TypeError("Not supported: %s" % id_)

    filename = persistence.get_temp_file(suffix=".eml")
    reader.saveToFile(file(filename, "wb"))
    return filename
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
def getMail(id_):
    if id_.startswith('mailbox-message://'):
        reader = ThunderbirdMailboxReader(id_)
    elif id_.startswith('imap-message://'):
        reader = ThunderbirdImapReader(id_)
    else:
        raise TypeError('Not supported: %s' % id_)

    filename = persistence.get_temp_file(suffix='.eml')
    reader.saveToFile(file(filename, 'wb'))

    if os.name == 'nt':
        os.chmod(filename, stat.S_IREAD)

    return filename
Ejemplo n.º 6
0
    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
 def _getMail(self):
     match = _RX_MAILBOX.match(self.url)
     if match is None:
         raise ThunderbirdError(_('Unrecognized URL scheme: "%s"') % self.url)
     path = unquote(match.group(1))
     # Note that the number= part of the URL is not the message key, but
     # rather an offset in the mbox file.
     offset = int(match.group(2))
     # So we skip the first offset bytes before reading the contents:
     with file(path, 'rb') as mbox:
         mbox.seek(offset)
         contents = mbox.read(4 * 1024 * 1024)  # Assume message size <= 4MB
     # Then we get a filename for a temporary file...
     filename = persistence.get_temp_file()
     # And save the remaining contents of the original mbox file: 
     with file(filename, 'wb') as tmpmbox:
         tmpmbox.write(contents)
     # Now we can open the temporary mbox file...
     mb = mailbox.mbox(filename)
     # And the message we look for should be the first one:
     return mb.get_string(0)
Ejemplo n.º 8
0
 def _getMail(self):
     match = _RX_MAILBOX.match(self.url)
     if match is None:
         raise ThunderbirdError(
             _('Unrecognized URL scheme: "%s"') % self.url)
     path = unquote(match.group(1))
     # Note that the number= part of the URL is not the message key, but
     # rather an offset in the mbox file.
     offset = int(match.group(2))
     # So we skip the first offset bytes before reading the contents:
     with file(path, 'rb') as mbox:
         mbox.seek(offset)
         contents = mbox.read(4 * 1024 * 1024)  # Assume message size <= 4MB
     # Then we get a filename for a temporary file...
     filename = persistence.get_temp_file()
     # And save the remaining contents of the original mbox file:
     with file(filename, 'wb') as tmpmbox:
         tmpmbox.write(contents)
     # Now we can open the temporary mbox file...
     mb = mailbox.mbox(filename)
     # And the message we look for should be the first one:
     return mb.get_string(0)