diff --git a/src/gmv/gmvault.py b/src/gmv/gmvault.py index c127698e..150208c4 100755 --- a/src/gmv/gmvault.py +++ b/src/gmv/gmvault.py @@ -45,15 +45,14 @@ def handle_restore_imap_error(the_exception, gm_id, db_gmail_ids_info, gmvaulter LOG.critical("Disconnecting and reconnecting to restart cleanly.") gmvaulter.src.reconnect() #reconnect else: - raise the_exception + raise elif isinstance(the_exception, IOError) and str(the_exception).find('[Errno 2] No such file or directory:') >=0: LOG.critical("Quarantine email with gm id %s from %s. GMAIL IMAP cannot restore it:"\ " err={%s}" % (gm_id, db_gmail_ids_info[gm_id], str(the_exception))) gmvaulter.gstorer.quarantine_email(gm_id) gmvaulter.error_report['emails_in_quarantine'].append(gm_id) LOG.critical("Disconnecting and reconnecting to restart cleanly.") - gmvaulter.src.reconnect() #reconnect - + gmvaulter.src.reconnect() #reconnects elif isinstance(the_exception, imaplib.IMAP4.error): LOG.error("Catched IMAP Error %s" % (str(the_exception))) LOG.exception(the_exception) @@ -64,9 +63,14 @@ def handle_restore_imap_error(the_exception, gm_id, db_gmail_ids_info, gmvaulter LOG.critical("Quarantine email with gm id %s from %s. GMAIL IMAP cannot restore it:"\ " err={%s}" % (gm_id, db_gmail_ids_info[gm_id], str(the_exception))) gmvaulter.gstorer.quarantine_email(gm_id) + gmvaulter.error_report['emails_in_quarantine'].append(gm_id) + elif str(the_exception) == "APPEND command error: BAD ['[TOOBIG] Message too large. https://support.google.com/mail/answer/6584#limit']": + LOG.critical("Quarantine email with gm id %s from %s. GMAIL IMAP cannot restore attachment too large:"\ + " err={%s}" % (gm_id, db_gmail_ids_info[gm_id], str(the_exception))) + gmvaulter.gstorer.quarantine_email(gm_id) gmvaulter.error_report['emails_in_quarantine'].append(gm_id) else: - raise the_exception + raise elif isinstance(the_exception, imap_utils.PushEmailError): LOG.error("Catch the following exception %s" % (str(the_exception))) LOG.exception(the_exception) @@ -77,11 +81,11 @@ def handle_restore_imap_error(the_exception, gm_id, db_gmail_ids_info, gmvaulter gmvaulter.gstorer.quarantine_email(gm_id) gmvaulter.error_report['emails_in_quarantine'].append(gm_id) else: - raise the_exception + raise else: LOG.error("Catch the following exception %s" % (str(the_exception))) LOG.exception(the_exception) - raise the_exception + raise def handle_sync_imap_error(the_exception, the_id, error_report, src): """ @@ -266,7 +270,8 @@ def __init__(self, db_root_dir, host, port, login, \ 'cannot_be_fetched' : [], 'emails_in_quarantine' : [], 'reconnections' : 0, - 'key_error' : []} + 'key_error' : [], + 'attachment_too_big' : 0 } #instantiate gstorer self.gstorer = gmvault_db.GmailStorer(self.db_root_dir, self.use_encryption) @@ -1142,6 +1147,7 @@ def restore_emails(self, pivot_dir = None, extra_labels = [], restart = False): labels_to_apply[ex_label] = imap_id except Exception, err: + LOG.critical("Error on gmid %s" % (gm_id)) handle_restore_imap_error(err, gm_id, db_gmail_ids_info, self) #create the non existing labels and update existing labels diff --git a/src/gmv/imap_utils.py b/src/gmv/imap_utils.py index f30be16c..7a03a294 100755 --- a/src/gmv/imap_utils.py +++ b/src/gmv/imap_utils.py @@ -121,7 +121,7 @@ def reconnect(the_self, rec_nb_tries, total_nb_tries, rec_error, rec_sleep_time LOG.exception(ignored) else: #cascade error - raise rec_error + raise def inner_retry(the_func): #pylint:disable=C0111,R0912 def wrapper(*args, **kwargs): #pylint:disable=C0111,R0912 @@ -179,6 +179,7 @@ def wrapper(*args, **kwargs): #pylint:disable=C0111,R0912 LOG.debug("IMAP (normal) error message = %s. traceback:%s" % (err, gmvault_utils.get_exception_traceback())) if nb_tries[0] < a_nb_tries: + LOG.critical(err) LOG.critical("Error when reaching Gmail server. Wait %s second(s) and retry up to 2 times." \ % (m_sleep_time[0])) else: @@ -800,6 +801,10 @@ def push_data(self, a_folder, a_body, a_flags, a_internal_time): try: #a_body = self._clean_email_body(a_body) res = self.server.append(a_folder, a_body, a_flags, a_internal_time) + except imaplib.IMAP4.error, erre: + if str(erre).find("APPEND command error: BAD ['[TOOBIG]") >= 0: + LOG.critical("APPEND error due to attachment too big: %s" % (len(a_body))) + raise except imaplib.IMAP4.abort, err: # handle issue when there are invalid characters (This is do to the presence of null characters) if str(err).find("APPEND => Invalid character in literal") >= 0: @@ -807,7 +812,7 @@ def push_data(self, a_folder, a_body, a_flags, a_internal_time): a_body = self._clean_email_body(a_body) self.reconnect() res = self.server.append(a_folder, a_body, a_flags, a_internal_time) - + LOG.debug("Appended data with flags %s and internal time %s. Operation time = %s.\nres = %s\n" \ % (a_flags, a_internal_time, the_timer.elapsed_ms(), res))