Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for django 4.2 #247

Merged
merged 13 commits into from
Jun 12, 2023
6 changes: 6 additions & 0 deletions .eggs/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This directory contains eggs that were downloaded by setuptools to build, test, and run plug-ins.

This directory caches those eggs to prevent repeated downloads.

However, it is safe to delete this directory.

Spitfireap marked this conversation as resolved.
Show resolved Hide resolved
65 changes: 34 additions & 31 deletions .github/workflows/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:11
image: postgres:12
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
Expand All @@ -41,36 +41,39 @@ jobs:
strategy:
matrix:
database: ['postgres', 'mysql']
python-version: [3.7, 3.8, 3.9]
python-version: [3.8, 3.9, '3.10']
fail-fast: false

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
sudo apt-get update -y && sudo apt-get install -y librrd-dev rrdtool
sudo apt-get update -y \
&& sudo apt-get update -y && sudo apt-get install -y librrd-dev rrdtool
python -m pip install --upgrade pip
pip install -e git+https://github.com/modoboa/modoboa.git#egg=modoboa
pip install -r requirements.txt
pip install -r test-requirements.txt
cd ..
git clone https://github.com/modoboa/modoboa.git
cd modoboa
python setup.py develop
cd ../modoboa-webmail
python setup.py develop
- name: Install postgres requirements
if: ${{ matrix.database == 'postgres' }}
run: |
pip install psycopg2-binary>=2.7.4
pip install coverage
echo "DB=postgres" >> $GITHUB_ENV
- name: Install mysql requirements
if: ${{ matrix.database == 'mysql' }}
run: |
pip install 'mysqlclient<2.0.4'
echo "DB=mysql" >> $GITHUB_ENV
- name: Test with pytest
if: ${{ matrix.python-version != '3.9' || matrix.database != 'postgres' }}
if: ${{ matrix.python-version != '3.10' || matrix.database != 'postgres' }}
run: |
cd test_project
python3 manage.py test modoboa_webmail
Expand All @@ -83,10 +86,12 @@ jobs:
MYSQL_USER: root

- name: Test with pytest and coverage
if: ${{ matrix.python-version == '3.9' && matrix.database == 'postgres' }}
if: ${{ matrix.python-version == '3.10' && matrix.database == 'postgres' }}
run: |
cd test_project
coverage run --source ../modoboa_webmail manage.py test modoboa_webmail
coverage xml
coverage report
env:
# use localhost for the host here because we are running the job on the VM.
# If we were running the job on in a container this would be postgres
Expand All @@ -95,50 +100,48 @@ jobs:
MYSQL_PORT: ${{ job.services.mysql.ports[3306] }} # get randomly assigned published port
MYSQL_USER: root
- name: Upload coverage result
if: ${{ matrix.python-version == '3.9' }}
uses: actions/upload-artifact@v2
if: ${{ matrix.python-version == '3.10' && matrix.database == 'postgres' }}
uses: actions/upload-artifact@v3
with:
name: coverage-results
path: test_project/.coverage
path: test_project/coverage.xml

coverage:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: '3.9'
- name: Install dependencies
run: |
pip install codecov
- uses: actions/checkout@v3
- name: Download coverage results
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: coverage-results
- name: Report coverage
run: |
coverage report
codecov
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: ./coverage.xml

release:
if: github.event_name != 'pull_request'
needs: coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python 3.9
uses: actions/setup-python@v2
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: '3.9'
python-version: '3.10'
- name: Build packages
run: |
sudo apt-get install librrd-dev rrdtool libssl-dev gettext
python -m pip install --upgrade pip setuptools wheel
pip install -r requirements.txt
cd modoboa_webmail
cd ..
git clone https://github.com/modoboa/modoboa.git
cd modoboa
python setup.py develop
cd modoboa-webmail/modoboa_webmail
django-admin compilemessages
cd ..
python setup.py sdist bdist_wheel
Expand Down
2 changes: 1 addition & 1 deletion modoboa_webmail/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Webmail constants."""

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _


SORT_ORDERS = [
Expand Down
2 changes: 1 addition & 1 deletion modoboa_webmail/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""
import re

from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _

from modoboa.lib.exceptions import ModoboaException, InternalError

Expand Down
2 changes: 1 addition & 1 deletion modoboa_webmail/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from django.conf import settings
from django.core.mail import EmailMessage, EmailMultiAlternatives
from django.core.validators import validate_email
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from ckeditor_uploader.widgets import CKEditorUploadingWidget

Expand Down
2 changes: 1 addition & 1 deletion modoboa_webmail/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.urls import reverse
from django.dispatch import receiver
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _

from modoboa.core import signals as core_signals

Expand Down
6 changes: 3 additions & 3 deletions modoboa_webmail/lib/imapemail.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
from django.core.files.base import ContentFile
from django.core.files.storage import default_storage
from django.urls import reverse
from django.utils.encoding import smart_text
from django.utils.encoding import smart_str
from django.utils.html import conditional_escape
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _

from modoboa.core.extensions import exts_pool
from modoboa.lib import u2u_decode
Expand Down Expand Up @@ -211,7 +211,7 @@ def _find_attachments(self):
att["disposition"][1][pos + 1]
).strip("\r\t\n")
break
self.attachments[att["pnum"]] = smart_text(attname)
self.attachments[att["pnum"]] = smart_str(attname)

def _fetch_inlines(self):
"""Store inline images on filesystem to display them."""
Expand Down
2 changes: 1 addition & 1 deletion modoboa_webmail/lib/imapheader.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def parse_date(value, **kwargs):
ndate = datetime.datetime.fromtimestamp(email.utils.mktime_tz(tmp))
if ndate.tzinfo is not None:
tz = timezone.get_current_timezone()
ndate = tz.localize(datetime.datetime.fromtimestamp(ndate))
ndate = datetime.datetime.fromtimestamp(ndate).replace(tzinfo=tz)
current_language = get_request().user.language
if datetime.datetime.now() - ndate > datetime.timedelta(7):
fmt = "LONG"
Expand Down
2 changes: 1 addition & 1 deletion modoboa_webmail/lib/imaputils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import six

from django.utils.encoding import smart_bytes
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _

from modoboa.lib import imap_utf7 # noqa
from modoboa.lib.connections import ConnectionsManager
Expand Down
4 changes: 2 additions & 2 deletions modoboa_webmail/modo_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""Declare and register the webmail extension."""

from django.urls import reverse_lazy
from django.utils.translation import ugettext_lazy
from django.utils.translation import gettext_lazy

from modoboa.core.extensions import ModoExtension, exts_pool
from modoboa.parameters import tools as param_tools
Expand All @@ -15,7 +15,7 @@ class Webmail(ModoExtension):
name = "modoboa_webmail"
label = "Webmail"
version = __version__
description = ugettext_lazy("Simple IMAP webmail")
description = gettext_lazy("Simple IMAP webmail")
needs_media = True
url = "webmail"
topredirection_url = reverse_lazy("modoboa_webmail:index")
Expand Down
2 changes: 1 addition & 1 deletion modoboa_webmail/templatetags/webmail_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.utils.encoding import smart_str
from django.utils.html import escape
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _

from ..lib import imapheader, separate_mailbox
from .. import constants
Expand Down
4 changes: 2 additions & 2 deletions modoboa_webmail/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from email.utils import getaddresses

from django.utils.encoding import force_text
from django.utils.encoding import force_str
from django.core.validators import validate_email


Expand All @@ -11,7 +11,7 @@ class EmailListValidator(object):
"""Validate a list of email."""

def __call__(self, value):
value = force_text(value)
value = force_str(value)
addresses = getaddresses([value])
[validate_email(email) for name, email in addresses if email]

Expand Down
16 changes: 10 additions & 6 deletions modoboa_webmail/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from django.http import HttpResponse
from django.shortcuts import render
from django.template.loader import render_to_string
from django.utils.translation import ugettext as _, ungettext
from django.utils.translation import gettext as _, ngettext
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.gzip import gzip_page

Expand Down Expand Up @@ -39,6 +39,10 @@
from .templatetags import webmail_tags


def is_ajax(request):
return request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest'


@login_required
@needs_mailbox()
@gzip_page
Expand Down Expand Up @@ -93,7 +97,7 @@ def delete(request):
mbc.move(",".join(selection), mbox,
request.user.parameters.get_value("trash_folder"))
count = len(selection)
message = ungettext("%(count)d message deleted",
message = ngettext("%(count)d message deleted",
"%(count)d messages deleted",
count) % {"count": count}
return render_to_json_response(message)
Expand Down Expand Up @@ -136,7 +140,7 @@ def mark_as_junk(request):
"""Mark a message as SPAM."""
count = _move_selection_to_folder(
request, request.user.parameters.get_value("junk_folder"))
message = ungettext("%(count)d message marked",
message = ngettext("%(count)d message marked",
"%(count)d messages marked",
count) % {"count": count}
return render_to_json_response(message)
Expand All @@ -147,7 +151,7 @@ def mark_as_junk(request):
def mark_as_not_junk(request):
"""Mark a message as not SPAM."""
count = _move_selection_to_folder(request, "INBOX")
message = ungettext("%(count)d message marked",
message = ngettext("%(count)d message marked",
"%(count)d messages marked",
count) % {"count": count}
return render_to_json_response(message)
Expand Down Expand Up @@ -651,12 +655,12 @@ def index(request):
raise UnknownAction
response = globals()[action](request)
else:
if request.is_ajax():
if is_ajax(request):
raise BadRequest(_("Invalid request"))
response = {"selection": "webmail"}

curmbox = WebmailNavigationParameters(request).get("mbox", "INBOX")
if not request.is_ajax():
if not is_ajax(request):
request.session["lastaction"] = None
imapc = get_imapconnector(request)
imapc.getquota(curmbox)
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
modoboa>=2.0.4
chardet
lxml
2 changes: 1 addition & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
factory-boy<3.3.0
testfixtures==7.1.0
psycopg2>=2.5.4
psycopg[binary]>=3.1.8
mysqlclient<2.1.2
Loading