コード例 #1
0
ファイル: message.py プロジェクト: yasusii/shaling
def mime_del(msg, part):
    validate_message_structure(msg)
    # Get the old object to be removed.
    mpart = get_message_part(msg, part)
    # Get the list of the children of the parent object.
    children = msg.get_payload()
    if mpart not in children:
        raise MessageStructureError("Cannot remove that part.")
    i = children.index(mpart)
    if i == 0:
        raise MessageStructureError("Cannot remove the first text part.")
    # Remove it.
    children.remove(mpart)
    return msg
コード例 #2
0
ファイル: message.py プロジェクト: yasusii/shaling
def mime_del(msg, part):
    validate_message_structure(msg)
    # Get the old object to be removed.
    mpart = get_message_part(msg, part)
    # Get the list of the children of the parent object.
    children = msg.get_payload()
    if mpart not in children:
        raise MessageStructureError('Cannot remove that part.')
    i = children.index(mpart)
    if i == 0:
        raise MessageStructureError('Cannot remove the first text part.')
    # Remove it.
    children.remove(mpart)
    return msg
コード例 #3
0
ファイル: message.py プロジェクト: yasusii/shaling
def mime_alter(msg, part, obj):
    validate_message_structure(msg)
    # Get the old object to be replaced.
    mpart = get_message_part(msg, part)
    # Get the list of the children of the parent object.
    children = msg.get_payload()
    if mpart not in children:
        raise MessageStructureError("Cannot change that part.")
    i = children.index(mpart)
    if i == 0:
        raise MessageStructureError("Cannot change the first text part.")
    # Replace it with a new one.
    children[i] = obj
    return msg
コード例 #4
0
ファイル: message.py プロジェクト: yasusii/shaling
def mime_alter(msg, part, obj):
    validate_message_structure(msg)
    # Get the old object to be replaced.
    mpart = get_message_part(msg, part)
    # Get the list of the children of the parent object.
    children = msg.get_payload()
    if mpart not in children:
        raise MessageStructureError('Cannot change that part.')
    i = children.index(mpart)
    if i == 0:
        raise MessageStructureError('Cannot change the first text part.')
    # Replace it with a new one.
    children[i] = obj
    return msg
コード例 #5
0
ファイル: message.py プロジェクト: yasusii/shaling
def get_editable_string(msg, labels):
    mpart = msg
    if msg.is_multipart():
        mpart = get_message_part(msg, 1)
        if mpart.get_content_maintype() != "text":
            raise MessageStructureError("The first part is not text??.")

    # Construct text.
    text = u""
    for h in config.EDITABLE_HEADERS:
        for v in unicode_getall(msg, h):
            text += u"%s: %s\n" % (h, rmsp(v))
    if labels:
        text += u"Label: %s\n" % get_label_names(labels)
    text += u"\n" + get_body_text(mpart, msg.get_content_charset())
    return text
コード例 #6
0
ファイル: message.py プロジェクト: yasusii/shaling
def get_editable_string(msg, labels):
    mpart = msg
    if msg.is_multipart():
        mpart = get_message_part(msg, 1)
        if mpart.get_content_maintype() != 'text':
            raise MessageStructureError('The first part is not text??.')

    # Construct text.
    text = u''
    for h in config.EDITABLE_HEADERS:
        for v in unicode_getall(msg, h):
            text += u'%s: %s\n' % (h, rmsp(v))
    if labels:
        text += u'Label: %s\n' % get_label_names(labels)
    text += u'\n' + get_body_text(mpart, msg.get_content_charset())
    return text
コード例 #7
0
ファイル: message.py プロジェクト: yasusii/shaling
def show_mime_part(term, msg, part, headerlevel=0, charset=None):
    mpart = get_message_part(msg, part)

    # Binary - might get InterfaceError.
    if mpart.get_content_type() != "text/plain":
        content = mpart.get_payload(decode=True)
        term.show_binary(content, mpart.get_content_type())
        return

    # Headers are normally not displayed.
    if 2 <= headerlevel:
        for (h, v) in mpart.items():
            term.display(term.normal("%s: %s\n" % (h, rmsp(v))))
        term.display("\n")

    charset = msg.get_content_charset(charset or config.MESSAGE_CHARSET)
    term.display(term.normal(get_body_text(mpart, charset)))
    return
コード例 #8
0
ファイル: message.py プロジェクト: yasusii/shaling
def show_mime_part(term, msg, part, headerlevel=0, charset=None):
    mpart = get_message_part(msg, part)

    # Binary - might get InterfaceError.
    if mpart.get_content_type() != 'text/plain':
        content = mpart.get_payload(decode=True)
        term.show_binary(content, mpart.get_content_type())
        return

    # Headers are normally not displayed.
    if 2 <= headerlevel:
        for (h, v) in mpart.items():
            term.display(term.normal('%s: %s\n' % (h, rmsp(v))))
        term.display('\n')

    charset = msg.get_content_charset(charset or config.MESSAGE_CHARSET)
    term.display(term.normal(get_body_text(mpart, charset)))
    return
コード例 #9
0
 def cmd_get(self, args):
     'usage: get [-f|-F field] [-o filename] msg:part'
     try:
         (opts, args) = getopt(args, 'f:F:c:o:')
     except GetoptError:
         raise Kernel.ShowUsage()
     #
     fields = []
     outputfile = None
     for (k, v) in opts:
         if k == '-f': fields.extend((h, True) for h in v.split(','))
         elif k == '-F': fields.extend((h, False) for h in v.split(','))
         elif k == '-o': outputfile = v
     #
     (docs, args) = self.get_messages(args or ['.'])
     if args:
         self.terminal.warning('Arguments ignored: %r' % args)
     if fields:
         for (_, doc, part) in docs:
             message.show_headers(self.terminal, doc, fields)
         return
     if len(docs) != 1:
         raise Kernel.SyntaxError('Can save only one file at a time.')
     (_, doc, part) = docs[0]
     confirm = False
     if part == None:
         # Save the entire message.
         data = doc.corpus.get_message(doc.loc)
     else:
         # Save the mime part.
         try:
             mpart = get_message_part(doc.get_msg(0), part)
         except MessagePartNotFoundError:
             raise Kernel.ValueError('Message part not found.')
         if not outputfile:
             outputfile = escape_unsafe_chars(mpart.get_filename() or '')
             confirm = True
         data = mpart.get_payload(decode=True)
     if not outputfile:
         raise Kernel.ValueError('Speficy the filename to save.')
     self.terminal.save_file(data, outputfile, confirm)
     return
コード例 #10
0
ファイル: kernel.py プロジェクト: yasusii/shaling
 def cmd_get(self, args):
   'usage: get [-f|-F field] [-o filename] msg:part'
   try:
     (opts, args) = getopt(args, 'f:F:c:o:')
   except GetoptError:
     raise Kernel.ShowUsage()
   #
   fields = []
   outputfile = None
   for (k,v) in opts:
     if k == '-f': fields.extend( (h,True) for h in v.split(',') )
     elif k == '-F': fields.extend( (h,False) for h in v.split(',') )
     elif k == '-o': outputfile = v
   #
   (docs, args) = self.get_messages(args or ['.'])
   if args:
     self.terminal.warning('Arguments ignored: %r' % args)
   if fields:
     for (_,doc,part) in docs:
       message.show_headers(self.terminal, doc, fields)
     return
   if len(docs) != 1:
     raise Kernel.SyntaxError('Can save only one file at a time.')
   (_,doc,part) = docs[0]
   confirm = False
   if part == None:
     # Save the entire message.
     data = doc.corpus.get_message(doc.loc)
   else:
     # Save the mime part.
     try:
       mpart = get_message_part(doc.get_msg(0), part)
     except MessagePartNotFoundError:
       raise Kernel.ValueError('Message part not found.')
     if not outputfile:
       outputfile = escape_unsafe_chars(mpart.get_filename() or '')
       confirm = True
     data = mpart.get_payload(decode=True)
   if not outputfile:
     raise Kernel.ValueError('Speficy the filename to save.')
   self.terminal.save_file(data, outputfile, confirm)
   return