Exemplo n.º 1
0
def get_undeleted_msgnums(server: imaplib.IMAP4) -> List[int]:
    """
    Return a list of ids of non-deleted messages in the folder.
    """
    resp = []
    undeleted_info = check_response(server.search(None, "UNDELETED"))
    if undeleted_info:
        # If neither None nor empty, then
        # the first item should be a list of msg ids
        resp = [int(n) for n in undeleted_info[0].split()]
    return resp
Exemplo n.º 2
0
    def run(self, imap_obj: imaplib.IMAP4):
        """Executes IMAP SEARCH command according to the requested
         SearchQueryBuilder.

        :param imap_obj:
        """
        typ, data = imap_obj.search(self.__charset, str(self.__search_query))
        self.check_response(typ, data)
        if not data:
            return []
        for uid in data[0].split(b' '):
            if not uid:
                continue
            yield int(uid)
Exemplo n.º 3
0
def get_matching_msgnums(server: imaplib.IMAP4, query: str,
                         sent_before: Optional[str]) -> List[int]:
    """
    Return a list of ids of deleted messages in the folder.
    """
    resp = []
    if (sent_before is not None):
        query = query + " SENTBEFORE " + sent_before
        print("Getting matching messages sent before " + sent_before)
    deleted_info = check_response(server.search(None, query))
    if deleted_info:
        # If neither None nor empty, then
        # the first item should be a list of msg ids
        resp = [int(n) for n in deleted_info[0].split()]
    return resp
Exemplo n.º 4
0
def get_undeleted_msgnums(server: imaplib.IMAP4, sent_before) -> List[int]:
    """
    Return a list of ids of non-deleted messages in the folder.
    """
    resp = []
    query = "UNDELETED"
    if (sent_before != None):
        query = query + " SENTBEFORE " + sent_before
        print("Getting undeleted messages sent before " + sent_before)
    undeleted_info = check_response(server.search(None, query))
    if undeleted_info:
        # If neither None nor empty, then
        # the first item should be a list of msg ids
        resp = [int(n) for n in undeleted_info[0].split()]
    return resp
Exemplo n.º 5
0
def get_mail_from_imap(client: imaplib.IMAP4) -> List[ImapEmail]:
    _, data = client.search("", 'ALL')
    mails = [ImapEmail(client, num) for num in data[0].split()]
    return list(reversed(mails))
Exemplo n.º 6
0
def search_for_inbox_mails(imap: IMAP4, subject: str) -> Optional[List[bytes]]:
    ret = imap.search(None, 'SUBJECT "{subject}"'.format(subject=subject))
    if ret[0] != 'OK':
        return None
    return ret[1][0].split()
Exemplo n.º 7
0
def get_all_inbox_mails(imap: IMAP4) -> Optional[List[bytes]]:
    ret = imap.search(None, 'ALL')
    if ret[0] != 'OK':
        return None
    return ret[1][0].split()
Exemplo n.º 8
0
 def __search_mailbox(self, imap_connection: IMAP4) -> Tuple[str, list]:
     return imap_connection.search(None, self.__config.search,
                                   self.__config.data_to_look_for)