Пример #1
0
 def imap_store(self, tag, argparser, uid_command=False):
     msgset = argparser.parse()
     item = argparser.parse()
     value = argparser.parse()
     mailmanager = self._account.get_mailmanager()
     silent = False
     item = item.lower()
     if item in ('flags.silent', '+flags.silent', '-flags.silent'):
         silent = True
         item = item[:item.index('.')]
     if item not in ('flags', '+flags', '-flags'):
         return 'NO STORE failed, can\'t store that data'
     flags = [utils.flag_to_letter(i) for i in value]
     for seq, uid in self._expand_msgset(msgset, uid_command):
         if item == 'flags':
             mailmanager.set_flags(self._mailbox, flags, uid=uid)
         elif item == '+flags':
             mailmanager.add_flags(self._mailbox, flags, uid=uid)
         elif item == '-flags':
             mailmanager.remove_flags(self._mailbox, flags, uid=uid)
         if not silent:
             flags_str = [utils.letter_to_flag(i) for i in
                          mailmanager.get_flags(self._mailbox, uid)]
             if not uid_command:
                 self._sock.sendline('* %i FETCH FLAGS (%s)'
                                     % (seq, flags_str))
             else:
                 self._sock.sendline('* %i FETCH (FLAGS (%s) UID %s)' %
                           (seq, flags_str, uid))
     return 'OK STORE completed'
Пример #2
0
 def run(self, seq, uid):
     message = LazyMessage(self._mailmanager, self._folder, seq)
     self._sock.sendall('* %i FETCH (' % (seq))
     for item in self._items:
         if item == 'UID':
             # UID is sent unconditionally as last item
             pass
         elif item == 'FLAGS':
             flags = self._mailmanager.get_flags(self._folder, seq=seq)
             flags = [utils.letter_to_flag(i) for i in flags]
             flags = ' '.join(flags)
             self._sock.sendall('FLAGS (%s) ' % (flags))
         elif item == 'RFC822.SIZE':
             size = len(message.as_string())
             self._sock.sendall('RFC822.SIZE %i ' % (size))
         elif ((isinstance(item, tuple) and item[1][0] in ('BODY.PEEK',
                                                           'BODY'))
               or item in ('RFC822.HEADER', 'BODY.PEEK', 'PEEK')):
             peeking = False
             if isinstance(item, str):
                 if item in ('BODY.PEEK', 'RFC822.HEADER'):
                     peeking = True
                 matched = item
                 item = (item, None)
             else:
                 matched, item = item
                 if item[0] == 'BODY.PEEK':
                     peeking = True
             matched = matched.replace('BODY.PEEK', 'BODY', 1)
             # TODO: if peeking is false, set Seen flag
             # TODO: support offset
             # TODO: support parts
             if item[1] is None:
                 size = len(message.as_string())
                 self._sock.sendall('%s[] {%i}\r\n' % (matched, size))
                 self._sock.sendall(message.as_string())
             else:
                 what = item[1][0]
                 part = item[1][1]
                 message = self._mailmanager.get_message(
                     self._folder, seq=seq)
                 fields = item[2][1]
                 buf = []
                 for field in fields:
                     if field in message:
                         buf.append('%s: %s' % (field, message[field]))
                 buf = '\r\n'.join(buf) + '\r\n'
                 self._sock.sendall('%s {%i}\r\n%s' %
                                    (matched, len(buf), buf))
     self._sock.sendall('UID %i' % (uid))
     self._sock.sendall(')\r\n')