Пример #1
0
 def maildir_msg(self) -> MaildirMessage:
     flag_str = self.maildir_flags.to_maildir(self.permanent_flags)
     msg_bytes = bytes(self.get_body(binary=True))
     maildir_msg = MaildirMessage(msg_bytes)
     maildir_msg.set_flags(flag_str)
     maildir_msg.set_subdir('new' if self.recent else 'cur')
     if self.internal_date is not None:
         maildir_msg.set_date(self.internal_date.timestamp())
     return maildir_msg
Пример #2
0
 def to_maildir(cls, prepared_msg: PreparedMessage, recent: bool,
                maildir_flags: MaildirFlags) -> MaildirMessage:
     flag_str = maildir_flags.to_maildir(prepared_msg.flag_set)
     when = prepared_msg.when or datetime.now()
     literal: bytes = prepared_msg.ref
     maildir_msg = MaildirMessage(literal)
     maildir_msg.set_flags(flag_str)
     maildir_msg.set_subdir('new' if recent else 'cur')
     maildir_msg.set_date(when.timestamp())
     return maildir_msg
Пример #3
0
 def populateMailbox(self, username):
     # Here will the mail directory of the user be stored
     pathShort = "/var/vmail/" + self.domain + "/" + username
     pathLong = pathShort + "/Maildir"
     # Create those directories
     os.mkdir(pathShort)
     mailbox = Maildir(pathLong)
     # And now populate that directory
     numOfMails = random.randint(1, 6666)
     percentageRead = random.randint(0, 100)
     for i in xrange(1, numOfMails):
         message = MaildirMessage(message=str(i))
         message.set_subdir("cur")
         readSeed = random.randint(0, 100)
         if percentageRead <= readSeed:
             message.set_flags("S")
         mailbox.add(message)
     self.chmodMailbox(pathShort)
     
     
def store_mail(tf, mail, maildir, metadata):
    """Store the given mail inside the maildir with its metadata"""
    # Retrieve the message
    msg = MaildirMessage(tf.extractfile(mail['name']))
    msg.set_flags(get_msgflags(metadata[mail['name']]))
    folder = path.dirname(mail['name'])
    # Find the mailbox in which to store the mail
    md = None
    if re.match('Inbox(\![0-9]+)?$', folder):
        md = Maildir(maildir)
    elif re.match('Inbox/', folder):
        # Nested folders under Inbox, put them under a folder named
        # 'INBOX'.
        folder = folder.replace('/', '.').replace('Inbox', 'INBOX')
        md = Maildir(path.join(maildir, '.' + folder), factory=None)
    elif re.match('Sent(\ Items.*)?', folder):
        md = Maildir(path.join(maildir, '.' + 'Sent'), factory=None)
    else:
        md = Maildir(path.join(maildir, '.' + folder), factory=None)
    # Store the mail
    md.add(msg)
Пример #5
0
 def __getitem__(self, key):
     path, info = self.toc[key]
     msg = MaildirMessage(open(path).read())
     msg.set_flags(parse_info(info))
     msg.msgkey = key
     return msg