Esempio n. 1
0
 def _on_search(imap_response):
     data = extract_data(imap_response)
     ids = string.split(data[0])
     ids_to_fetch = page_from_list(ids, limit, offset)
     return _cmd_cb(self.messages_by_id, _on_messages_by_id,
                    bool(callback), ids_to_fetch, only_uids=only_uids,
                    full=full, teaser=teasers, gm_ids=gm_ids)
Esempio n. 2
0
 def _on_fetch(imap_response):
     data = extract_data(imap_response)
     if only_uids:
         uids = [string.split(elm, " ")[4][:-1] for elm in data]
         return _cmd(callback, uids)
     else:
         messages = parse_fetch_request(data, self, teasers, full, gm_ids)
         return _cmd(callback, messages)
Esempio n. 3
0
 def _on_search_complete(imap_response):
     data = extract_data(imap_response)
     if len(data) == 0 or not data[0]:
         return _cmd(callback, None)
     else:
         uid = data[0]
         return _cmd_cb(self.fetch, _on_fetch, bool(callback),
                        uid, full=full, **kwargs)
Esempio n. 4
0
 def _on_mailbox_creation(imap_response):
     error = check_for_response_error(imap_response)
     if error:
         return _cmd(callback, error)
     else:
         response_type = extract_type(imap_response)
         if response_type == "NO":
             return _cmd(callback, False)
         else:
             data = extract_data(imap_response)
             self.boxes = None
             was_success = data[0] == "Success"
             return _cmd(callback, was_success)
Esempio n. 5
0
        def _on_search_for_message_complete(imap_response):
            data = extract_data(imap_response)

            # Its possible here that we've tried to select the message
            # we want to delete from the trash bin before google has
            # registered it there for us.  If our search attempt returned
            # a uid, then we're good to go and can continue.
            try:
                deleted_uid = data[0].split()[-1]
                cbp = dict(deleted_uid=deleted_uid)
                return _cmd_cb(self.conn, _on_received_connection_4,
                               bool(callback), callback_args=cbp)

            # If not though, we should wait a couple of seconds and try
            # again.  We'll do this a maximum of 5 times.  If we still
            # haven't had any luck at this point, we give up and return
            # False, indiciating we weren't able to delete the message
            # fully.
            except IndexError:
                self.num_tries += 1

                # If this is the 5th time we're trying to delete this
                # message, we're going to call it a loss and stop trying.
                # We do some minimal clean up and then just bail out
                # Otherwise, schedule another attempt in 2 seconds and
                # hope that gmail has updated its indexes by then
                if self.num_tries == 5:
                    del self.num_tries
                    if __debug__:
                        _log.error(u"Giving up trying to delete message {subject} - {id}".format(subject=self.subject, id=self.message_id))
                        _log.error("got response: {response}".format(response=str(imap_response)))
                    return _cmd(callback, False)
                else:
                    if __debug__:
                        _log.error("Try {num} to delete deleting message {subject} - {id} failed.  Waiting".format(num=self.num_tries, subject=self.subject, id=self.message_id))
                        _log.error("got response: {response}".format(response=str(imap_response)))
                    return _cmd_in(_on_trash_selected, 2, bool(callback), force_success=True)
Esempio n. 6
0
 def _on_mailboxes(imap_response):
     data = extract_data(imap_response)
     self.boxes = []
     for box in data:
         self.boxes.append(mailbox.Mailbox(self, box))
     return _cmd(callback, self.boxes)
Esempio n. 7
0
 def _on_safe_save_append(imap_response, message_copy):
     data = extract_data(imap_response)
     msg_uid = data[0].split()[2][:-1]
     cbp = dict(message_uid=msg_uid, message_id=message_copy['Message-Id'])
     return _cmd_cb(self.conn, _post_safe_save_connection, bool(callback),
                    callback_args=cbp)
Esempio n. 8
0
 def _on_append(imap_response):
     data = extract_data(imap_response)
     self.uid = data[0].split()[2][:-1]
     return _cmd_cb(self.conn, _on_post_append_connection, bool(callback))
Esempio n. 9
0
 def _on_fetch(imap_response):
     data = extract_data(imap_response)
     messages = parse_fetch_request(data, self, teasers, full, gm_ids)
     return _cmd(callback, messages[0] if len(messages) > 0 else None)
Esempio n. 10
0
 def _on_mailbox_deletion(imap_response):
     data = extract_data(imap_response)
     was_success = data[0] == "Success"
     return _cmd(callback, was_success)
Esempio n. 11
0
 def _on_select_complete(imap_response):
     data = extract_data(imap_response)
     self.account.last_viewed_mailbox = self
     msg_count = int(Mailbox.COUNT_PATTERN.sub("", str(data)))
     return _cmd(callback, msg_count)