Возможность изменять флаги письма
This commit is contained in:
		
							parent
							
								
									f36515f233
								
							
						
					
					
						commit
						de41f90943
					
				@ -1,11 +1,34 @@
 | 
				
			|||||||
from mailbox import Maildir
 | 
					from mailbox import Maildir
 | 
				
			||||||
 | 
					import os
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ExtendedMaildir(Maildir):
 | 
					class ExtendedMaildir(Maildir):
 | 
				
			||||||
    def set_flags(self, key):
 | 
					    def set_flags(self, key, flags):
 | 
				
			||||||
        pass
 | 
					        sflags = sorted(flags)
 | 
				
			||||||
 | 
					        if sflags == self.get_flags(key): return True
 | 
				
			||||||
 | 
					        subpath = self._lookup(key)
 | 
				
			||||||
 | 
					        info = '2,' + ''.join(sflags)
 | 
				
			||||||
 | 
					        oldpath = os.path.join(self._path, subpath)
 | 
				
			||||||
 | 
					        newsubdir = os.path.split(subpath)[0]
 | 
				
			||||||
 | 
					        newname = key + self.colon + info
 | 
				
			||||||
 | 
					        if 'S' not in sflags and newsubdir == 'new':
 | 
				
			||||||
 | 
					            newsubdir = 'cur'
 | 
				
			||||||
 | 
					        newpath = os.path.join(self._path, newsubdir, newname)
 | 
				
			||||||
 | 
					        if hasattr(os, 'link'):
 | 
				
			||||||
 | 
					            os.link(oldpath, newpath)
 | 
				
			||||||
 | 
					            os.remove(oldpath)
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            os.rename(oldpath, newpath)
 | 
				
			||||||
 | 
					        self._toc[key] = os.path.join(newsubdir, newname)
 | 
				
			||||||
    def get_flags(self, key):
 | 
					    def get_flags(self, key):
 | 
				
			||||||
        pass
 | 
					        subpath = self._lookup(key)
 | 
				
			||||||
    def add_flag(self):
 | 
					        _, name = os.path.split(subpath)
 | 
				
			||||||
        pass
 | 
					        info = name.split(self.colon)[-1]
 | 
				
			||||||
    def remove_flag(self):
 | 
					        if info.startswith('2,'):
 | 
				
			||||||
        pass
 | 
					            return info[2:]
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            return ''
 | 
				
			||||||
 | 
					    def add_flag(self, flag):
 | 
				
			||||||
 | 
					        self.set_flags(''.join(set(self.get_flags()) | set(flag)))
 | 
				
			||||||
 | 
					    def remove_flag(self, flag):
 | 
				
			||||||
 | 
					        if self.get_flags():
 | 
				
			||||||
 | 
					            self.set_flags(''.join(set(self.get_flags()) - set(flag)))
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user