mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-12-01 12:03:55 +01:00
Merged in jpcaruana/modoboa/menage (pull request #2)
1st run througth the webmail module
This commit is contained in:
@@ -2,7 +2,6 @@
|
|||||||
from django.utils.translation import ugettext as _, ugettext_lazy
|
from django.utils.translation import ugettext as _, ugettext_lazy
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from modoboa.lib import events, parameters
|
from modoboa.lib import events, parameters
|
||||||
from modoboa.lib.webutils import static_url
|
|
||||||
from modoboa.extensions import ModoExtension, exts_pool
|
from modoboa.extensions import ModoExtension, exts_pool
|
||||||
|
|
||||||
class Webmail(ModoExtension):
|
class Webmail(ModoExtension):
|
||||||
@@ -99,7 +98,8 @@ def userlogout(request):
|
|||||||
try:
|
try:
|
||||||
m = IMAPconnector(user=request.user.username,
|
m = IMAPconnector(user=request.user.username,
|
||||||
password=request.session["password"])
|
password=request.session["password"])
|
||||||
except Exception, e:
|
except Exception:
|
||||||
|
# TODO silent exception are bad : we should at least log it
|
||||||
return
|
return
|
||||||
|
|
||||||
# The following statement may fail under Python 2.6...
|
# The following statement may fail under Python 2.6...
|
||||||
|
|||||||
@@ -61,8 +61,7 @@ def parse_bodystructure(buf, depth=0, prefix=""):
|
|||||||
if nb_bodystruct == 0:
|
if nb_bodystruct == 0:
|
||||||
ret.append(subret)
|
ret.append(subret)
|
||||||
elif nb_bodystruct == 1:
|
elif nb_bodystruct == 1:
|
||||||
newret = [ret.pop(-1)]
|
newret = [ret.pop(-1), subret]
|
||||||
newret.append(subret)
|
|
||||||
ret.append(newret)
|
ret.append(newret)
|
||||||
else:
|
else:
|
||||||
ret[-1].append(subret)
|
ret[-1].append(subret)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
# coding: utf-8
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ import time
|
|||||||
from functools import wraps
|
from functools import wraps
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
from modoboa.lib import parameters
|
from modoboa.lib import parameters
|
||||||
from modoboa.lib.connections import *
|
from modoboa.lib.connections import ConnectionsManager
|
||||||
from modoboa.lib.webutils import static_url
|
from modoboa.lib.webutils import static_url
|
||||||
from exceptions import ImapError, WebmailError
|
from exceptions import ImapError, WebmailError
|
||||||
from fetch_parser import *
|
from fetch_parser import parse_fetch_response
|
||||||
|
|
||||||
#imaplib.Debug = 4
|
#imaplib.Debug = 4
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ class BodyStructure(object):
|
|||||||
* Any other MIME type is considered as an attachment (for now)
|
* Any other MIME type is considered as an attachment (for now)
|
||||||
|
|
||||||
:param definition: a part definition (list)
|
:param definition: a part definition (list)
|
||||||
:param prefix: the part's number
|
:param pnum: the part's number
|
||||||
:param multisubtype: the multipart subtype
|
:param multisubtype: the multipart subtype
|
||||||
"""
|
"""
|
||||||
pnum = "1" if pnum is None else pnum
|
pnum = "1" if pnum is None else pnum
|
||||||
@@ -353,24 +353,24 @@ class IMAPconnector(object):
|
|||||||
sdescr["class"] = "subfolders"
|
sdescr["class"] = "subfolders"
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _listmboxes_simple(self, topmailbox='INBOX', mailboxes=[], **kwargs):
|
def _listmboxes_simple(self, topmailbox='INBOX', mailboxes=None, **kwargs):
|
||||||
#data = self._cmd("LIST", "", "*")
|
#data = self._cmd("LIST", "", "*")
|
||||||
|
if not mailboxes: mailboxes = []
|
||||||
(status, data) = self.m.list()
|
(status, data) = self.m.list()
|
||||||
result = []
|
|
||||||
newmboxes = []
|
newmboxes = []
|
||||||
for mb in data:
|
for mb in data:
|
||||||
flags, delimiter, name = self.list_response_pattern.match(mb).groups()
|
flags, delimiter, name = self.list_response_pattern.match(mb).groups()
|
||||||
name = name.strip('"').decode("imap4-utf-7")
|
name = name.strip('"').decode("imap4-utf-7")
|
||||||
pos = -1
|
mdm_found = False
|
||||||
for idx, mdm in enumerate(mailboxes):
|
for idx, mdm in enumerate(mailboxes):
|
||||||
if mdm["name"] == name:
|
if mdm["name"] == name:
|
||||||
pos = idx
|
mdm_found = True
|
||||||
|
descr = mailboxes[idx]
|
||||||
break
|
break
|
||||||
if pos == -1:
|
if not mdm_found:
|
||||||
descr = dict(name=name)
|
descr = dict(name=name)
|
||||||
newmboxes += [descr]
|
newmboxes += [descr]
|
||||||
else:
|
|
||||||
descr = mailboxes[idx]
|
|
||||||
if re.search("\%s" % delimiter, name):
|
if re.search("\%s" % delimiter, name):
|
||||||
parts = name.split(".")
|
parts = name.split(".")
|
||||||
if not descr.has_key("path"):
|
if not descr.has_key("path"):
|
||||||
@@ -385,7 +385,8 @@ class IMAPconnector(object):
|
|||||||
mailboxes += sorted(newmboxes, key=itemgetter("name"))
|
mailboxes += sorted(newmboxes, key=itemgetter("name"))
|
||||||
|
|
||||||
@capability('LIST-EXTENDED', '_listmboxes_simple')
|
@capability('LIST-EXTENDED', '_listmboxes_simple')
|
||||||
def _listmboxes(self, topmailbox='', mailboxes=[], until_mailbox=None):
|
def _listmboxes(self, topmailbox='', mailboxes=None, until_mailbox=None):
|
||||||
|
if not mailboxes: mailboxes = []
|
||||||
pattern = ("%s.%%" % topmailbox.encode("imap4-utf-7")) if len(topmailbox) else "%"
|
pattern = ("%s.%%" % topmailbox.encode("imap4-utf-7")) if len(topmailbox) else "%"
|
||||||
resp = self._cmd("LIST", "", pattern, "RETURN", "(CHILDREN)")
|
resp = self._cmd("LIST", "", pattern, "RETURN", "(CHILDREN)")
|
||||||
newmboxes = []
|
newmboxes = []
|
||||||
@@ -394,16 +395,15 @@ class IMAPconnector(object):
|
|||||||
self.listextended_response_pattern.match(mb).groups()
|
self.listextended_response_pattern.match(mb).groups()
|
||||||
flags = flags.split(' ')
|
flags = flags.split(' ')
|
||||||
name = name.decode("imap4-utf-7")
|
name = name.decode("imap4-utf-7")
|
||||||
pos = -1
|
mdm_found = False
|
||||||
for idx, mdm in enumerate(mailboxes):
|
for idx, mdm in enumerate(mailboxes):
|
||||||
if mdm["name"] == name:
|
if mdm["name"] == name:
|
||||||
pos = idx
|
mdm_found = True
|
||||||
|
descr = mailboxes[idx]
|
||||||
break
|
break
|
||||||
if pos == -1:
|
if not mdm_found:
|
||||||
descr = dict(name=name)
|
descr = dict(name=name)
|
||||||
newmboxes += [descr]
|
newmboxes += [descr]
|
||||||
else:
|
|
||||||
descr = mailboxes[idx]
|
|
||||||
|
|
||||||
if r'\Marked' in flags or not r'\UnMarked' in flags:
|
if r'\Marked' in flags or not r'\UnMarked' in flags:
|
||||||
descr["send_status"] = True
|
descr["send_status"] = True
|
||||||
@@ -628,7 +628,7 @@ class IMAPconnector(object):
|
|||||||
:param mbox: the mailbox containing the message
|
:param mbox: the mailbox containing the message
|
||||||
:param mailid: the message's unique id
|
:param mailid: the message's unique id
|
||||||
:param readonly:
|
:param readonly:
|
||||||
:param extraheaders:
|
:param headers:
|
||||||
"""
|
"""
|
||||||
self.select_mailbox(mbox, readonly)
|
self.select_mailbox(mbox, readonly)
|
||||||
if headers is None:
|
if headers is None:
|
||||||
|
|||||||
@@ -1,24 +1,23 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
import sys, os
|
|
||||||
import re
|
|
||||||
import time
|
import time
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import email
|
import email
|
||||||
import lxml
|
import lxml
|
||||||
import chardet
|
import chardet
|
||||||
from django.core.files.uploadhandler import FileUploadHandler, StopUpload, SkipFile
|
|
||||||
from django.http import HttpResponse
|
from django.core.files.uploadhandler import FileUploadHandler, SkipFile
|
||||||
from django.utils.translation import ugettext as _, ugettext_lazy
|
from django.utils.translation import ugettext as _, ugettext_lazy
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from modoboa.lib import u2u_decode, tables, imap_utf7, parameters
|
|
||||||
from modoboa.lib.webutils import static_url, size2integer
|
|
||||||
from modoboa.lib.connections import ConnectionsManager
|
|
||||||
from modoboa.lib.email_listing import MBconnector, EmailListing
|
|
||||||
from modoboa.lib.emailutils import *
|
|
||||||
|
|
||||||
from imaputils import *
|
import os
|
||||||
from exceptions import *
|
import re
|
||||||
|
from modoboa.lib import u2u_decode, tables, parameters
|
||||||
|
from modoboa.lib.webutils import size2integer
|
||||||
|
from modoboa.lib.email_listing import EmailListing
|
||||||
|
from modoboa.extensions.webmail.exceptions import WebmailError
|
||||||
|
from modoboa.extensions.webmail.imaputils import IMAPconnector, get_imapconnector, BodyStructure
|
||||||
|
from modoboa.lib.emailutils import EmailAddress, Email
|
||||||
|
|
||||||
|
|
||||||
class WMtable(tables.Table):
|
class WMtable(tables.Table):
|
||||||
tableid = "emails"
|
tableid = "emails"
|
||||||
@@ -603,7 +602,7 @@ def send_mail(request, posturl=None):
|
|||||||
"""
|
"""
|
||||||
from email.mime.multipart import MIMEMultipart
|
from email.mime.multipart import MIMEMultipart
|
||||||
from forms import ComposeMailForm
|
from forms import ComposeMailForm
|
||||||
from modoboa.lib.webutils import getctx, ajax_simple_response, _render_to_string
|
from modoboa.lib.webutils import _render_to_string
|
||||||
from modoboa.auth.lib import get_password
|
from modoboa.auth.lib import get_password
|
||||||
|
|
||||||
form = ComposeMailForm(request.POST)
|
form = ComposeMailForm(request.POST)
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
from modoboa.lib.webutils import ajax_response, _render_error
|
from modoboa.lib.webutils import ajax_response, _render_error
|
||||||
from modoboa.extensions.webmail.exceptions import *
|
from modoboa.extensions.webmail.exceptions import WebmailError, ImapError
|
||||||
|
|
||||||
class WebmailErrorMiddleware(object):
|
class WebmailErrorMiddleware(object):
|
||||||
def process_exception(self, request, exception):
|
def process_exception(self, request, exception):
|
||||||
|
|||||||
@@ -5,10 +5,8 @@ from django.utils.translation import ugettext as _
|
|||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from modoboa.extensions import webmail
|
from modoboa.extensions import webmail
|
||||||
from modoboa.extensions.webmail.lib import IMAPheader
|
|
||||||
from modoboa.extensions.webmail.imaputils import separate_mailbox
|
from modoboa.extensions.webmail.imaputils import separate_mailbox
|
||||||
from modoboa.lib import parameters
|
from modoboa.lib import parameters
|
||||||
from modoboa.lib.webutils import static_url
|
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from django.conf.urls.defaults import *
|
# coding: utf-8
|
||||||
|
from django.conf.urls.defaults import patterns
|
||||||
|
|
||||||
urlpatterns = patterns(
|
urlpatterns = patterns(
|
||||||
'modoboa.extensions.webmail.views',
|
'modoboa.extensions.webmail.views',
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
from django.http import HttpResponse, Http404
|
from django.conf import settings
|
||||||
|
import os
|
||||||
|
from django.http import HttpResponse
|
||||||
from django.template import Template, Context
|
from django.template import Template, Context
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from modoboa.lib import parameters
|
from modoboa.lib import parameters
|
||||||
from modoboa.lib.webutils import _render, _render_error, \
|
from modoboa.lib.webutils import _render, _render_to_string, ajax_response, ajax_simple_response
|
||||||
getctx, _render_to_string, ajax_response, ajax_simple_response
|
|
||||||
from modoboa.lib.email_listing import parse_search_parameters
|
|
||||||
from modoboa.lib.decorators import needs_mailbox
|
from modoboa.lib.decorators import needs_mailbox
|
||||||
from modoboa.auth.lib import *
|
from exceptions import WebmailError
|
||||||
from lib import *
|
from forms import FolderForm, AttachmentForm, ComposeMailForm
|
||||||
from forms import *
|
from imaputils import get_imapconnector, IMAPconnector, separate_mailbox
|
||||||
|
from lib import decode_payload, AttachmentUploadHandler, save_attachment, ImapListing, EmailSignature, clean_attachments, set_compose_session, send_mail, ImapEmail
|
||||||
from templatetags import webextras
|
from templatetags import webextras
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@@ -23,7 +24,6 @@ def getattachment(request):
|
|||||||
redemandé pour accéder aux headers de cette pièce jointe.
|
redemandé pour accéder aux headers de cette pièce jointe.
|
||||||
|
|
||||||
:param request: a ``Request`` object
|
:param request: a ``Request`` object
|
||||||
:param folder
|
|
||||||
"""
|
"""
|
||||||
mbox = request.GET.get("mbox", None)
|
mbox = request.GET.get("mbox", None)
|
||||||
mailid = request.GET.get("mailid", None)
|
mailid = request.GET.get("mailid", None)
|
||||||
@@ -123,9 +123,9 @@ def newfolder(request, tplname="webmail/folder.html"):
|
|||||||
"action_label": _("Create"),
|
"action_label": _("Create"),
|
||||||
"action_classes": "submit",
|
"action_classes": "submit",
|
||||||
"withunseen": False,
|
"withunseen": False,
|
||||||
"selectonly" : True}
|
"selectonly": True,
|
||||||
|
"mboxes": mbc.getmboxes(request.user)}
|
||||||
|
|
||||||
ctx["mboxes"] = mbc.getmboxes(request.user)
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
form = FolderForm(request.POST)
|
form = FolderForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
@@ -225,7 +225,7 @@ def attachments(request, tplname="webmail/attachments.html"):
|
|||||||
return _render(request, "webmail/upload_done.html", {
|
return _render(request, "webmail/upload_done.html", {
|
||||||
"status" : "ok", "fname" : request.FILES["attachment"],
|
"status" : "ok", "fname" : request.FILES["attachment"],
|
||||||
"tmpname" : os.path.basename(tmpname)
|
"tmpname" : os.path.basename(tmpname)
|
||||||
});
|
})
|
||||||
except WebmailError, inst:
|
except WebmailError, inst:
|
||||||
error = _("Failed to save attachment: ") + str(inst)
|
error = _("Failed to save attachment: ") + str(inst)
|
||||||
|
|
||||||
@@ -234,7 +234,7 @@ def attachments(request, tplname="webmail/attachments.html"):
|
|||||||
% parameters.get_admin("MAX_ATTACHMENT_SIZE"))
|
% parameters.get_admin("MAX_ATTACHMENT_SIZE"))
|
||||||
return _render(request, "webmail/upload_done.html", {
|
return _render(request, "webmail/upload_done.html", {
|
||||||
"status" : "ko", "error" : error
|
"status" : "ko", "error" : error
|
||||||
});
|
})
|
||||||
ctx = {
|
ctx = {
|
||||||
"title" : _("Attachments"),
|
"title" : _("Attachments"),
|
||||||
"formid" : "uploadfile",
|
"formid" : "uploadfile",
|
||||||
@@ -274,7 +274,7 @@ def render_mboxes_list(request, imapc):
|
|||||||
"""Return the HTML representation of a mailboxes list
|
"""Return the HTML representation of a mailboxes list
|
||||||
|
|
||||||
:param request: a ``Request`` object
|
:param request: a ``Request`` object
|
||||||
:param imap: an ``IMAPconnector` object
|
:param imapc: an ``IMAPconnector` object
|
||||||
:return: a string
|
:return: a string
|
||||||
"""
|
"""
|
||||||
curmbox = request.session.get("mbox", "INBOX")
|
curmbox = request.session.get("mbox", "INBOX")
|
||||||
|
|||||||
Reference in New Issue
Block a user