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

Updated Dockerfile to support ghostscript #5

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.github
bin
counters
devel
develop-eggs
docs
lib
optimized
output
scripts
.*
41 changes: 21 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
FROM python:3.7-buster

RUN apt-get update && apt-get install -y \
dumb-init \
locales \
vim \
xfonts-75dpi \
xfonts-base
FROM python:3.10-buster

WORKDIR /tmp

RUN wget -O wkhtmltox.deb "https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.stretch_amd64.deb" && \
dpkg -i wkhtmltox.deb && \
rm wkhtmltox.deb && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /var/tmp/*

ADD *.rst buildout.cfg entrypoint.sh requirements.txt setup.py sources.cfg versions.cfg /app/
ADD src /app/src
RUN apt-get update \
&& apt-get install -y \
dumb-init \
locales \
vim \
xfonts-75dpi \
xfonts-base \
&& wget -O wkhtmltox.deb "https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.stretch_amd64.deb" \
&& dpkg -i wkhtmltox.deb \
&& rm wkhtmltox.deb \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /var/tmp/*

WORKDIR /app

RUN ln -sf /usr/share/zoneinfo/Europe/Brussels /etc/localtime

COPY *.rst entrypoint.sh /app/
RUN chmod +x /app/entrypoint.sh

RUN pip install -r requirements.txt && \
buildout
COPY requirements.txt /app/requirements.txt
RUN ln -sf /usr/share/zoneinfo/Europe/Brussels /etc/localtime \
&& pip install -r requirements.txt

COPY buildout.cfg setup.py sources.cfg versions.cfg /app/
COPY src /app/src
RUN buildout

ENTRYPOINT ["/app/entrypoint.sh"]
8 changes: 8 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ To process emails, you can execute ::
See `config.ini` file for various parameters.


For usage with Docker, it's similar to `bin/process_mails` but you need to build the Docker image first ::

```bash
docker build -t imio.email.dms .
docker run --rm imio.email.dms config.ini
```


Release
-------

Expand Down
11 changes: 5 additions & 6 deletions src/imio/email/dms/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,17 +391,16 @@ def process_mails():
mail.__setitem__("X-Forwarded-For", "0.0.0.0") # to be considered as main mail
parser = Parser(mail, dev_mode, "")
headers = parser.headers
o_attachments = parser.attachments
# [k: v for k, v in at.items() if k != 'content'} for at in o_attachments]
attachments = modify_attachments(mail_id, o_attachments)
main_file_path = get_preview_pdf_path(config, mail_id)
logger.info("pdf file {}".format(main_file_path))
try:
parser.generate_pdf(main_file_path)
except Exception:
main_file_path = main_file_path.replace(".pdf", ".eml")
save_as_eml(main_file_path, parser.message)
# structure(parser.message)
o_attachments = parser.attachments()
# [k: v for k, v in at.items() if k != 'content'} for at in o_attachments]
attachments = modify_attachments(mail_id, o_attachments)
send_to_ws(config, headers, main_file_path, attachments, mail_id)
lock.close()
sys.exit()
Expand Down Expand Up @@ -459,14 +458,14 @@ def process_mails():
pass
continue
# logger.info('Accepting {}: {}'.format(headers['Agent'][0][1], headers['Subject']))
o_attachments = parser.attachments
attachments = modify_attachments(mail_id, o_attachments)
try:
parser.generate_pdf(main_file_path)
except Exception:
# if 'XDG_SESSION_TYPE=wayland' not in str(pdf_exc):
main_file_path = main_file_path.replace(".pdf", ".eml")
save_as_eml(main_file_path, parser.message)
o_attachments = parser.attachments()
attachments = modify_attachments(mail_id, o_attachments)
send_to_ws(config, headers, main_file_path, attachments, mail_id)
if not dev_mode:
handler.mark_mail_as_imported(mail_id)
Expand Down
10 changes: 10 additions & 0 deletions src/imio/email/dms/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from imio.email.dms.main import compress_pdf

import os
import unittest


class TestUtils(unittest.TestCase):
def test_compress_pdf(self):
pdf_file_path = "files/pdf-example-bookmarks-1-2.pdf"
import ipdb; ipdb.set_trace()