def rename_folder(self, oldname: str = None, newname: str = None, parent_folder: str = None) -> bool: """Rename email folder :param oldname: current folder name :param newname: new name for the folder :param parent_folder: name for the parent folder, by default INBOX :return: True if operation was successful, False if not """ if oldname is None or newname is None: raise KeyError( "'oldname' and 'newname' are required for rename folder") if parent_folder is None or parent_folder is self.account.inbox: parent = self.account.inbox else: parent = self.account.inbox / parent_folder self.logger.info( "Rename folder '%s' to '%s'", oldname, newname, ) items = self._get_all_items_in_folder(oldname, parent_folder) old_folder = Folder(parent=parent, name=oldname) old_folder.name = newname old_folder.save() items.move(to_folder=parent / newname) self.delete_folder(oldname, parent_folder)
def set_isolate_folder(self,folder='isolate',task_id=''): """ param folder: str, folder name return: None """ isolate_folder = None try: try: isolate_folder = self.admin_account.inbox / folder #i_folder = self.admin_account.inbox.glob(folder) #print('i_folder=',i_folder,i_folder._folders) if self.logger!=None: self.logger.info('isolated folder exist:{}'.format(isolate_folder)) except Exception as e: f = Folder(parent=self.admin_account.inbox, name=folder) print 'isolate_folder=',f f.save() f.name = folder f.save() isolate_folder = f print 'isolate_folder=',f if self.logger!=None: self.logger.info('create isolated folder: inbox/{0}'.format(folder)) if task_id: #create isolated folder based on task if not exist try: task_fold = f / task_id isolate_folder = task_fold if self.logger!=None: self.logger.info('folder-task_id={0} already existed'.format(task_id)) except Exception as e: t = Folder(parent=isolate_folder, name=task_id) t.save() t.name = task_id t.save() isolate_folder = t if self.logger!=None: self.logger.info('Create folder-task_id={0}.'.format(task_id)) else: pass except Exception as e: if self.logger!=None: self.logger.info(e) self.logger.info('this_isolated_folder={0}.'.format(isolate_folder)) self.isolate_folder = isolate_folder return
鈹溾攢鈹� exchangelib issues 鈹斺攢鈹� Mom ''' # Folders have some useful counters: a.inbox.total_count a.inbox.child_folder_count a.inbox.unread_count # Update the counters a.inbox.refresh() # Folders can be created, updated and deleted: f = Folder(parent=a.inbox, name='My New Folder') f.save() f.name = 'My New Subfolder' f.save() f.delete() # Delete all items in a folder f.empty() # Also delete all subfolders in the folder f.empty(delete_sub_folders=True) # Recursively delete all items in a folder, and all subfolders and their content. This is # like `empty(delete_sub_folders=True)` but attempts to protect distinguished folders from # being deleted. Use with caution! f.wipe() ###Dates, datetimes and timezones from datetime import datetime, timedelta