Exemple #1
0
 def _getIdsList(ids):
     idslist = None
     if isinstance(ids,list):
         if len(ids) > 0 and ids[0]!='' and ids[0]!=None:
             li = len(ids)-1
             if int(ids[0])+li == int(ids[li]):
                 idslist = Io.str(ids[0]+b':'+ids[li]) if isinstance(ids[0],bytes) else str(ids[0])+':'+str(ids[li])
             else :
                 idslist = Io.str(b','.join(ids)) if isinstance(ids[0],bytes) else ','.join(ids)
     elif isinstance(ids, int) and ids > 0:
         idslist = Io.str(ids)
     return idslist
Exemple #2
0
 def _ids(self, box='INBOX', search='ALL', charset=None, byUid=False):
     """"""
     status, resp = self.cnx.select(box)
     if status == self.KO :
         self.createBox(box)
         self.cnx.select(box)
     status, resp = self.cnx.search(charset, '(%s)' % search)
     return resplit(' ',Io.str(resp[self.K_HEAD]))
Exemple #3
0
 def headerField(self, mid, field, byUid=False):
     """"""
     value = ''
     field = field.upper()
     query = '(UID BODY[HEADER' + ('])' if field=='*' or field=='ALL' else '.FIELDS (%s)])' % field)
     status, resp = self.fetch(mid, query, byUid)
     if status==self.OK and resp[0]!=None:
         value = Io.str(resp[0][1][len(field)+2:-4])
     return value
Exemple #4
0
 def listBox(self, box='INBOX', pattern='*'):
     """"""
     status, resp = self.cnx.list(box,pattern)
     l = []
     for r in resp :
         if  r is not None :
             name = Io.str(r).split(' "/" ')
             l.append((name[0][1:-1].split(' '),name[1][1:-1]))
     return l
Exemple #5
0
 def initBoxNames(self):
     """"""
     status, resp = self.cnx.xlist()
     if status == self.OK :
         bdef, bname, c = None, None, None
         for c in resp :
             bdef, bname = c[1:-1].split(b') "/" "')
             if bdef == Io.bytes(self.NO_SELECT+' '+self.CHILDREN) :
                 self.BOXS['/'] = Io.str(bname)
             elif bdef == Io.bytes(self.NO_CHILDREN+' '+self.INBOX) :
                 self.BOXS[self.INBOX] = self.INBOX[1:].upper()
             elif bdef == Io.bytes(self.NO_CHILDREN+' '+self.DRAFTS) :
                 self.BOXS[self.DRAFTS] = Io.str(bname)
             elif bdef == Io.bytes(self.NO_CHILDREN+' '+self.TRASH) :
                 self.BOXS[self.TRASH] = Io.str(bname)
             elif bdef == Io.bytes(self.NO_CHILDREN+' '+self.SENT) :
                 self.BOXS[self.SENT] = Io.str(bname)
     else :
         self.BOXS = { '/' : '/', self.INBOX : self.INBOX[1:].upper(), self.DRAFTS : self.DRAFTS[1:], self.TRASH : self.TRASH[1:], self.SENT : self.SENT[1:] }
Exemple #6
0
 def buildIndex(self, fromPath):
     """Build mail for ImpraIndex
     :Returns: 'email.message.Message'
     """
     msg = MIMEText(Io.str(b2a_base64(Io.get_data(fromPath, True))), 'plain', 'utf-8')
     msg['From']    = self.getHashName('system')+'@'+self.DOMAIN_NAME
     msg['To']      = self.getHashName('all')+'@'+self.DOMAIN_NAME
     msg['Date']    = formatdate(localtime=True)
     msg['Subject'] = Header(self.getHashName('index'),'utf-8')      
     return msg
Exemple #7
0
 def status(self, box='INBOX'):
     """"""
     status, resp = self.cnx.status(box, '(MESSAGES RECENT UIDNEXT UIDVALIDITY UNSEEN)')
     if status == self.OK :
         data = research(self.REG_SATUS, Io.str(resp[self.K_HEAD]))
         l    = resplit(' ',data.group(2))
         dic  = {'BOX' : box}
         for i in range(len(l)):
             if i%2 == 0 : dic[l[i]] = int(l[i+1])
     else : dic = {}
     return dic