Пример #1
0
    def find_and_select_chats_folder(self):
        """
           depending on your account the all mail folder can be named 
           [GMAIL]/Chats or [GoogleMail]/Chats.
           Find and set the right one
        """
        #use xlist because of localized dir names
        folders = self.server.xlist_folders()

        for (_, _, the_dir) in folders:
            #non localised GMAIL_CHATS
            if GIMAPFetcher.GENERIC_GMAIL_CHATS in the_dir:
                LOG.debug("Chat folder = %s\n" % (the_dir))
                #select it in read only mode
                self.server.select_folder(the_dir, True)
                self._in_chat_dir = True
                return the_dir

        #Error did not find Chats dir
        if gmvault_utils.get_conf_defaults().getboolean(
                "General", "errors_if_chat_not_visible", False):
            raise Exception(
                "Cannot find global 'Chats' folder ! Check whether 'Show in IMAP for 'Chats' is enabled in Gmail (Go to Settings->Labels->All Mail)"
            )
        else:
            if not self.printed_chat_error_msg:
                LOG.critical(
                    "Cannot find 'Chats' folder on Gmail Server. If you wish to backup your chats, look at the documentation to see how to configure your Gmail account.\n"
                )
                self.printed_chat_error_msg = True
        return None
Пример #2
0
 def _restore(cls, args, credential):
     """
        Execute All restore operations
     """
     LOG.critical("Connect to Gmail server.\n")
     # Create a gmvault releaving read_only_access
     restorer = gmvault.GMVaulter(args['db-dir'], args['host'], args['port'], \
                                    args['email'], credential, read_only_access = False)
     
     #full sync is the first one
     if args.get('type', '') == 'full':
         
         #call restore
         labels = [args['label']] if args['label'] else []
         restorer.restore(extra_labels = labels, restart = args['restart'], emails_only = args['emails_only'], chats_only = args['chats_only'])
         
     elif args.get('type', '') == 'quick':
         
         #take the last two to 3 months depending on the current date
         
         # today - 2 months
         today = datetime.date.today()
         begin = today - datetime.timedelta(gmvault_utils.get_conf_defaults().getint("Restore", "quick_days", 8))
         
         starting_dir = gmvault_utils.get_ym_from_datetime(begin)
         
         #call restore
         labels = [args['label']] if args['label'] else []
         restorer.restore(pivot_dir = starting_dir, extra_labels = labels, restart = args['restart'], emails_only = args['emails_only'], chats_only = args['chats_only'])
     
     else:
         raise ValueError("Unknown synchronisation mode %s. Please use full (default), quick.")
     
     #print error report
     LOG.critical(restorer.get_error_report()) 
Пример #3
0
    def find_and_select_chats_folder(self):
        """
           depending on your account the all mail folder can be named 
           [GMAIL]/Chats or [GoogleMail]/Chats.
           Find and set the right one
        """
        #use xlist because of localized dir names
        folders = self.server.xlist_folders()
        
        for (_, _, the_dir) in folders:
            #non localised GMAIL_CHATS
            if GIMAPFetcher.GENERIC_GMAIL_CHATS in the_dir:
                LOG.debug("Chat folder = %s\n" % (the_dir))
                #select it in read only mode
                self.server.select_folder(the_dir, True)
                self._in_chat_dir = True
                return the_dir

        #Error did not find Chats dir 
        if gmvault_utils.get_conf_defaults().getboolean("General","errors_if_chat_not_visible", False):
            raise Exception("Cannot find global 'Chats' folder ! Check whether 'Show in IMAP for 'Chats' is enabled in Gmail (Go to Settings->Labels->All Mail)") 
        else:
            if not self.printed_chat_error_msg: 
                LOG.critical("Cannot find 'Chats' folder on Gmail Server. If you wish to backup your chats, look at the documentation to see how to configure your Gmail account.\n")
                self.printed_chat_error_msg= True
        return None
Пример #4
0
 def _sync(cls, args, credential):
     """
        Execute All synchronisation operations
     """
     LOG.critical("Connect to Gmail server.\n")
     
     # handle credential in all levels
     syncer = gmvault.GMVaulter(args['db-dir'], args['host'], args['port'], \
                                    args['email'], credential, read_only_access = True, use_encryption = args['encrypt'])
     
     
     
     #full sync is the first one
     if args.get('type', '') == 'full':
     
         #choose full sync. Ignore the request
         syncer.sync({ 'type': 'imap', 'req': 'ALL' } , compress_on_disk = args['compression'], \
                     db_cleaning = args['db-cleaning'], ownership_checking = args['ownership_control'], restart = args['restart'], \
                     emails_only = args['emails_only'], chats_only = args['chats_only'])
         
     elif args.get('type', '') == 'quick':
         
         #sync only the last x days (taken in defaults) in order to be quick (cleaning is import here because recent days might move again
         
         # today - 2 months
         today = datetime.date.today()
         begin = today - datetime.timedelta(gmvault_utils.get_conf_defaults().getint("Sync", "quick_days", 8))
         
         LOG.critical("Quick sync mode. Check for new emails since %s." % (begin.strftime('%d-%b-%Y')))
         
         # today + 1 day
         end   = today + datetime.timedelta(1)
         
         syncer.sync( { 'type': 'imap', 'req': syncer.get_imap_request_btw_2_dates(begin, end) }, \
                        compress_on_disk = args['compression'], \
                        db_cleaning = args['db-cleaning'], \
                        ownership_checking = args['ownership_control'], restart = args['restart'], \
                        emails_only = args['emails_only'], chats_only = args['chats_only'])
         
     elif args.get('type', '') == 'custom':
         
         # pass an imap request. Assume that the user know what to do here
         LOG.critical("Perform custom synchronisation with %s request: %s.\n" % (args['request']['type'], args['request']['req']))
         
         #LOG.critical("Deactivate chats syncing and database cleaning when performing a custom synchronisation.\n" )
         #deactivate everything
         #args['emails_only'] = True
         #args['chats_only']  = False
         #args['db-cleaning'] = False
         
         syncer.sync(args['request'], compress_on_disk = args['compression'], db_cleaning = args['db-cleaning'], \
                     ownership_checking = args['ownership_control'], restart = args['restart'], \
                     emails_only = args['emails_only'], chats_only = args['chats_only'])
     else:
         raise ValueError("Unknown synchronisation mode %s. Please use full (default), quick or custom.")
     
     
     #print error report
     LOG.critical(syncer.get_error_report())
Пример #5
0
def bootstrap_run():
    """ temporary bootstrap """
    
    #force argv[0] to gmvault
    sys.argv[0] = "gmvault"
    
    init_logging()
    
    LOG.critical("")
    
    gmvlt = GMVaultLauncher()
    
    args = gmvlt.parse_args()
    
    #activate debug if enabled
    if args['debug']:
        LOG.critical("Activate debugging information.")
        activate_debug_mode()
    
    # force instanciation of conf to load the defaults
    gmvault_utils.get_conf_defaults() 
    
    gmvlt.run(args)
Пример #6
0
def setup_default_conf():
    """
       set the environment GMVAULT_CONF_FILE which is necessary for Conf object
    """
    gmvault_utils.get_conf_defaults() # force instanciation of conf to load the defaults