def imapify(string): """ Return a version of the given string which can be used as a mailbox name by an IMAP server. """ result = imap_utf7.encode(string).decode() result = result.replace(".", "-") result = result.replace('"', "'") result = result.replace("/", "|") return result
def check_msgid(self, msgid, folder): folder_utf7 = imap_utf7.encode(folder) res, msgs = self.server.select(folder_utf7) if res == 'NO': log(ERROR, "Folderfehler %s, %s, %s" % (folder, res, msgs)) raise NameError("Folderfehler %s, %s, %s" % (folder, res, msgs)) res, msgs = self.server.search(None, "(HEADER Message-ID \"<%s>\")" % msgid) if res == 'OK' and len(msgs) > 0 and len(msgs[0]) > 0: return True else: return False
def store_feedentry(self, entry, sender = '*****@*****.**', folder='INBOX'): # check folder folder_utf7 = imap_utf7.encode(folder) if not self.folder_cache.has_key(folder): res, folders = self.server.list(folder_utf7) if folders[0] is None: self.server.create(folder_utf7) self.folder_cache[folder] = True # calc msg-id msgid = entry.msgid() if not self.check_msgid(msgid, folder): self.server.append(folder_utf7, None, entry.updated, self.entry_as_mail(entry, sender))
def _encode_folder_name(self, name): if self.folder_encode: name = imap_utf7.encode(name) # imaplib assumes that if a command argument (in this case a # folder name) has double quotes around it, then it doesn't # need quoting. This "feature" prevents creation of folders # with names that start and end with double quotes. # # To work around this IMAPClient performs the quoting # itself. This adds start and end double quotes which also # serves to fool IMAP4._checkquote into not attempting further # quoting. A hack but it works. return _quote_arg(name)