diff --git a/extensions/webmail/lib.py b/extensions/webmail/lib.py index 8e366d911..6d1555730 100644 --- a/extensions/webmail/lib.py +++ b/extensions/webmail/lib.py @@ -225,6 +225,7 @@ class IMAPconnector(object): (status, data) = self.m.sort("(%s)" % criterion, "UTF-8", "(NOT DELETED)", *self.criterions) self.messages = data[0].split() + self.getquota(folder) return len(self.messages) def unseen_messages(self, folder): @@ -302,6 +303,17 @@ class IMAPconnector(object): self.m.select(self._encodefolder(folder)) self.m.expunge() + def getquota(self, folder): + status, data = self.m.getquotaroot(self._encodefolder(folder)) + if status == "OK": + quotadef = data[1][0] + m = re.match("[^\s]+ \(STORAGE (\d+) (\d+)\)", quotadef) + if not m: + print "Problem while parsing quota def" + return + self.quota_limit = int(m.group(2)) + self.quota_actual = int(m.group(1)) + def fetch(self, start=None, stop=None, folder=None, all=False): if not start and not stop: return [] @@ -404,6 +416,13 @@ class ImapListing(EmailListing): unicode(or_criterion(criterions, '%s "%s"' % (key, pattern))) self.mbc.criterions = [unicode("(%s)" % criterions)] + def getquota(self): + try: + return int(float(self.mbc.quota_actual) \ + / float(self.mbc.quota_limit) * 100) + except AttributeError: + return -1 + class ImapEmail(Email): def __init__(self, msg, addrfull=False, *args, **kwargs): Email.__init__(self, msg, *args, **kwargs) diff --git a/extensions/webmail/static/css/webmail.css b/extensions/webmail/static/css/webmail.css index 45e7ca0c3..d42bf35dd 100644 --- a/extensions/webmail/static/css/webmail.css +++ b/extensions/webmail/static/css/webmail.css @@ -173,3 +173,30 @@ textarea:hover { #mailheader { padding-bottom: 5px; } + +/* Progress bar */ +#quotabox { + float: left; + margin: 5px; + width: 250px; + padding: 0; +} + +#box { + border: 1px solid #ccc; + width: 200px; + height: 15px; +} + +#perc { + background: green; + height: 15px; +} + +#quotatext { + font-family:tahoma, arial, sans-serif; + font-size:11px; + color:#000; + + padding: 3px 0 0 10px; +} \ No newline at end of file diff --git a/extensions/webmail/templates/index.html b/extensions/webmail/templates/index.html index cea42b009..9783109ed 100644 --- a/extensions/webmail/templates/index.html +++ b/extensions/webmail/templates/index.html @@ -4,11 +4,23 @@ {% endblock %} {% block js %} + quota_pb = new ProgressBar({ + container: $("quotabox"), + startPercentage: 0, + boxID: "box", + percentageID: "perc", + displayText: true, + displayID: "quotatext" + }); + wm_updatelisting = function(resp) { updatelisting(resp); if ($defined(resp.folders)) { $("folders").set("html", resp.folders); } + if ($defined(resp.quota) && resp.quota != "-1") { + quota_pb.set(resp.quota); + } $$("a[name=loadfolder]").addEvent("click", foldercallback); $$("a[name=compose]").addEvent("click", loadCompose); $$("a[name=empty]").addEvent("click", empty); diff --git a/extensions/webmail/views.py b/extensions/webmail/views.py index f905a4588..5aba3a4cd 100644 --- a/extensions/webmail/views.py +++ b/extensions/webmail/views.py @@ -62,6 +62,8 @@ def folder(request, name, updatenav=True): dico["listing"] = "