Exemple #1
0
 def valFmt(val, unit):
     if not unit:
         return val
     ul = unit.lower()
     if ul == "8kb":
         return floatToSize(int(val) * 8192)
     val = "%s %s" % (val, unit)
     if ul in ['kb', 'mb', 'gb']:
         return floatToSize(sizeToFloat(val[:-1] + "iB"))
     elif ul in ['ms', 's', 'h', 'min']:
         return floatToTime(timeToFloat(val))
     else:
         return val
Exemple #2
0
 def valFmt(val, unit):
   if not unit:
     return val
   ul=unit.lower()
   if ul == "8kb":
     return floatToSize(int(val)*8192)
   val="%s %s" % (val, unit)
   if ul in ['kb', 'mb', 'gb']:
     return floatToSize(sizeToFloat(val[:-1] + "iB"))
   elif ul in ['ms', 's', 'h', 'min']:
     return floatToTime(timeToFloat(val))
   else:
     return val
Exemple #3
0
 def AddSizeProperty(self, txt, value, imageid=-1):
     if not isinstance(value, float):
         value = sizeToFloat(value)
     self.AddProperty(txt, floatToSize(value), imageid)
Exemple #4
0
        def Save(self):
            c = self.GetConnection()
            mailboxName = encodeUtf7(self.MailboxName)
            if self.node:
                if self.MailboxName == self.node.name:
                    ok = True
                    mailboxPath = self.node.mailboxPath
                else:
                    if isinstance(self.node.parentNode, Mailbox):
                        mailboxPath = "%s%s%s" % (
                            self.node.parentNode.mailboxPath,
                            self.parentNode.separator, mailboxName)
                    else:
                        mailboxPath = mailboxName
                    ok = c.RenameMailbox(self.node.mailboxPath, mailboxPath)
                    if ok:
                        self.refreshNode = self.node.parentNode
            else:
                if isinstance(self.parentNode, Mailbox):
                    mailboxPath = "%s%s%s" % (self.parentNode.mailboxPath,
                                              self.parentNode.separator,
                                              mailboxName)
                else:
                    mailboxPath = mailboxName
                ok = c.CreateMailbox(mailboxPath)

            if ok and self.HasChanged('Comment'):
                ok = c.SetAnnotation(mailboxPath, "/comment", self.Comment)
            if ok and self.HasChanged('Squat'):
                if self.Squat: squat = 'true'
                else: squat = 'false'
                ok = c.SetAnnotation(mailboxPath, squatAnnotation, squat)

            if ok and self.HasChanged('StorageQuota'):
                if self.StorageQuota != "":
                    ok = c.SetQuota(
                        mailboxPath,
                        {'STORAGE': sizeToFloat(self.StorageQuota)})
                else:
                    ok = c.SetQuota(mailboxPath, None)

            lbAcl = self['ACL']
            if ok and lbAcl.unchangedValue != self.Acl or self.AclRecursive:
                subMbList = [mailboxPath]
                setAclList = []

                if self.AclRecursive:
                    mbList = c.List(mailboxPath, "*")
                    for line in mbList:
                        name, _, _ = self.node.splitMbInfo(line)
                        if name != mailboxPath:
                            subMbList.append(name)

                for row in range(lbAcl.GetItemCount()):
                    user = lbAcl.GetItemText(row, 0)
                    acl = lbAcl.GetItemText(row, 1)
                    if user in self.oldAcl:
                        if acl != self.oldAcl[user]:
                            # Change ACL
                            setAclList.append((user, acl))
                        del self.oldAcl[user]
                    else:
                        # add ACL
                        setAclList.append((user, acl))

                for mb in subMbList:
                    self.SetStatus(xlt("Setting ACL on %s") % mb)
                    if setAclList:
                        ok = c.SetAcl(mb, setAclList)
                    else:
                        ok = True
                    if ok and self.oldAcl:
                        ok = c.DelAcl(mb, self.oldAcl.keys())

                    if not ok:
                        self.SetStatus("Save error: %s" %
                                       self.GetServer().GetLastError())
                        return False

            if not self.node:
                self.parentNode.Refresh()
            return ok
Exemple #5
0
    def Save(self):
      c=self.GetConnection()
      mailboxName=encodeUtf7(self.MailboxName)
      if self.node:
        if self.MailboxName == self.node.name:
          ok=True
          mailboxPath=self.node.mailboxPath
        else:
          if isinstance(self.node.parentNode, Mailbox):
            mailboxPath="%s%s%s" % (self.node.parentNode.mailboxPath, self.parentNode.separator, mailboxName)
          else:
            mailboxPath=mailboxName
          ok=c.RenameMailbox(self.node.mailboxPath, mailboxPath)  
          if ok:
            self.refreshNode = self.node.parentNode
      else:
        if isinstance(self.parentNode, Mailbox):
          mailboxPath="%s%s%s" % (self.parentNode.mailboxPath, self.parentNode.separator, mailboxName)
        else:
          mailboxPath=mailboxName
        ok=c.CreateMailbox(mailboxPath)
      
      if ok and self.HasChanged('Comment'):
        ok = c.SetAnnotation(mailboxPath, "/comment", self.Comment)
        
      if ok and self.HasChanged('StorageQuota'):
        if self.StorageQuota != "":
          ok=c.SetQuota(mailboxPath, { 'STORAGE': sizeToFloat(self.StorageQuota) } )
        else:
          ok=c.SetQuota(mailboxPath, None)
    
      lbAcl=self['ACL']
      if ok and lbAcl.unchangedValue != self.Acl or self.AclRecursive:
        subMbList=[mailboxPath]
        setAclList=[]

        if self.AclRecursive:
          mbList=c.List(mailboxPath, "*")
          for line in mbList:
            name, _,_ = self.node.splitMbInfo(line)
            if name != mailboxPath:
              subMbList.append(name)

        for row in range(lbAcl.GetItemCount()):
          user=lbAcl.GetItemText(row, 0)
          acl=lbAcl.GetItemText(row, 1)
          if user in self.oldAcl:
            if acl != self.oldAcl[user]:
              # Change ACL
              setAclList.append( (user, acl))
            del self.oldAcl[user]
          else:
            # add ACL
            setAclList.append( (user, acl))
        
        for mb in subMbList:
          self.SetStatus(xlt("Setting ACL on %s") % mb)
          ok=c.SetAcl(mb, setAclList)
          if ok:
            ok=c.DelAcl(mb, self.oldAcl)
    
          if not ok:
            self.SetStatus("Save error: %s" % self.GetServer().GetLastError())
            return False
        
      if not self.node:
        self.parentNode.Refresh()
      return ok
Exemple #6
0
 def AddSizeProperty(self, txt, value, imageid=-1):
   if not isinstance(value, float):
     value=sizeToFloat(value)
   self.AddProperty(txt, floatToSize(value), imageid)