Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

Merge remote-tracking branch 'paperless/dev' into feature-consume-eml

phail08988e11f81c
diff --cc Pipfile
index 0fe616568,0660ef30f..df511483b
--- a/Pipfile
+++ b/Pipfile
@@@ -49,8 -54,12 +54,13 @@@ concurrent-log-handler = "*
"importlib-resources" = {version = "*", markers = "python_version < '3.9'"}
zipp = {version = "*", markers = "python_version < '3.9'"}
pyzbar = "*"
+ mysqlclient = "*"
+ celery = {extras = ["redis"], version = "*"}
+ django-celery-results = "*"
+ setproctitle = "*"
+ nltk = "*"
pdf2image = "*"
+bleach = "*"
[dev-packages]
coveralls = "*"
diff --cc docker/compose/docker-compose.postgres-tika.yml
index 216138d7a,c4333ad35..1158e7d67
--- a/docker/compose/docker-compose.postgres-tika.yml
+++ b/docker/compose/docker-compose.postgres-tika.yml
@@@ -77,15 -77,11 +77,15 @@@ services
PAPERLESS_TIKA_ENDPOINT: http://tika:9998
gotenberg:
- image: docker.io/gotenberg/gotenberg:7.4
+ image: docker.io/gotenberg/gotenberg:7.6
restart: unless-stopped
+
+ # The gotenberg chromium route is used to convert .eml files. We do not
+ # want to allow external content like tracking pixels or even javascript.
command:
- "gotenberg"
- - "--chromium-disable-routes=true"
+ - "--chromium-disable-javascript=true"
+ - "--chromium-allow-list=file:///tmp/.*"
tika:
image: ghcr.io/paperless-ngx/tika:latest
diff --cc docker/compose/docker-compose.sqlite-tika.yml
index eea7dd5f3,a7b9a4ebe..a331c1ad1
--- a/docker/compose/docker-compose.sqlite-tika.yml
+++ b/docker/compose/docker-compose.sqlite-tika.yml
@@@ -65,15 -65,11 +65,15 @@@ services
PAPERLESS_TIKA_ENDPOINT: http://tika:9998
gotenberg:
- image: docker.io/gotenberg/gotenberg:7.4
+ image: docker.io/gotenberg/gotenberg:7.6
restart: unless-stopped
+
+ # The gotenberg chromium route is used to convert .eml files. We do not
+ # want to allow external content like tracking pixels or even javascript.
command:
- "gotenberg"
- - "--chromium-disable-routes=true"
+ - "--chromium-disable-javascript=true"
+ - "--chromium-allow-list=file:///tmp/.*"
tika:
image: ghcr.io/paperless-ngx/tika:latest
diff --cc docs/configuration.rst
index fb7ba8505,402a41761..5824f69f9
--- a/docs/configuration.rst
+++ b/docs/configuration.rst
@@@ -512,15 -538,11 +538,15 @@@ requires are as follows
# ...
gotenberg:
- image: gotenberg/gotenberg:7.4
+ image: gotenberg/gotenberg:7.6
restart: unless-stopped
+
+ # The gotenberg chromium route is used to convert .eml files. We do not
+ # want to allow external content like tracking pixels or even javascript.
command:
- - "gotenberg"
- - "--chromium-disable-routes=true"
+ - "gotenberg"
+ - "--chromium-disable-javascript=true"
+ - "--chromium-allow-list=file:///tmp/.*"
tika:
image: ghcr.io/paperless-ngx/tika:latest
diff --cc docs/troubleshooting.rst
index a092ce6be,2d10bb15f..644a38552
--- a/docs/troubleshooting.rst
+++ b/docs/troubleshooting.rst
@@@ -125,16 -125,12 +125,16 @@@ If using docker-compose, this is achiev
.. code:: yaml
gotenberg:
- image: gotenberg/gotenberg:7.4
+ image: gotenberg/gotenberg:7.6
restart: unless-stopped
+
+ # The gotenberg chromium route is used to convert .eml files. We do not
+ # want to allow external content like tracking pixels or even javascript.
command:
- - "gotenberg"
- - "--chromium-disable-routes=true"
- - "--api-timeout=60"
+ - "gotenberg"
+ - "--chromium-disable-javascript=true"
+ - "--chromium-allow-list=file:///tmp/.*"
+ - "--api-timeout=60"
Permission denied errors in the consumption directory
#####################################################
diff --cc scripts/start_services.sh
index e3f90258f,97ef0cba7..efba11883
--- a/scripts/start_services.sh
+++ b/scripts/start_services.sh
@@@ -2,5 -2,5 +2,5 @@@
docker run -p 5432:5432 -e POSTGRES_PASSWORD=password -v paperless_pgdata:/var/lib/postgresql/data -d postgres:13
docker run -d -p 6379:6379 redis:latest
- docker run -p 3000:3000 -d gotenberg/gotenberg:7.4 gotenberg --chromium-disable-javascript=true --chromium-allow-list=file:///tmp/.*
-docker run -p 3000:3000 -d gotenberg/gotenberg:7.6
++docker run -p 3000:3000 -d gotenberg/gotenberg:7.6 gotenberg --chromium-disable-javascript=true --chromium-allow-list=file:///tmp/.*
docker run -p 9998:9998 -d ghcr.io/paperless-ngx/tika:latest
diff --cc src/paperless_mail/mail.py
index fb2080d7b,67631ac5e..e3bb887d6
--- a/src/paperless_mail/mail.py
+++ b/src/paperless_mail/mail.py
@@@ -344,132 -367,75 +370,130 @@@ class MailAccountHandler(LoggingMixin)
processed_attachments = 0
- for att in message.attachments:
+ if (
+ rule.consumption_scope == MailRule.ConsumptionScope.EML_ONLY
+ or rule.consumption_scope == MailRule.ConsumptionScope.EVERYTHING
+ ):
+ os.makedirs(settings.SCRATCH_DIR, exist_ok=True)
+ _, temp_filename = tempfile.mkstemp(
+ prefix="paperless-mail-",
+ dir=settings.SCRATCH_DIR,
+ suffix=".eml",
+ )
+ with open(temp_filename, "wb") as f:
+ # Move "From"-header to beginning of file
+ # TODO: This ugly workaround is needed because the parser is
+ # chosen only by the mime_type detected via magic
+ # (see documents/consumer.py "mime_type = magic.from_file")
+ # Unfortunately magic sometimes fails to detect the mime
+ # type of .eml files correctly as message/rfc822 and instead
+ # detects text/plain.
+ # This also effects direct file consumption of .eml files
+ # which are not treated with this workaround.
+ from_element = None
+ for i, header in enumerate(message.obj._headers):
+ if header[0] == "From":
+ from_element = i
+ if from_element:
+ new_headers = [message.obj._headers.pop(from_element)]
+ new_headers += message.obj._headers
+ message.obj._headers = new_headers
+
+ f.write(message.obj.as_bytes())
- if (
- not att.content_disposition == "attachment"
- and rule.attachment_type
- == MailRule.AttachmentProcessing.ATTACHMENTS_ONLY
- ):
- self.log(
- "debug",
- f"Rule {rule}: "
- f"Skipping attachment {att.filename} "
- f"with content disposition {att.content_disposition}",
- )
- continue
-
- if rule.filter_attachment_filename:
- # Force the filename and pattern to the lowercase
- # as this is system dependent otherwise
- if not fnmatch(
- att.filename.lower(),
- rule.filter_attachment_filename.lower(),
+ self.log(
+ "info",
+ f"Rule {rule}: "
+ f"Consuming eml from mail "
+ f"{message.subject} from {message.from_}",
+ )
+
- async_task(
- "documents.tasks.consume_file",
++ consume_file.delay(
+ path=temp_filename,
+ override_filename=pathvalidate.sanitize_filename(
+ message.subject + ".eml",
+ ),
+ override_title=message.subject,
+ override_correspondent_id=correspondent.id if correspondent else None,
+ override_document_type_id=doc_type.id if doc_type else None,
+ override_tag_ids=tag_ids,
+ task_name=message.subject[:100],
+ )
+ processed_attachments += 1
+
+ if (
+ rule.consumption_scope == MailRule.ConsumptionScope.ATTACHMENTS_ONLY
+ or rule.consumption_scope == MailRule.ConsumptionScope.EVERYTHING
+ ):
+ for att in message.attachments:
+
+ if (
+ not att.content_disposition == "attachment"
+ and rule.attachment_type
+ == MailRule.AttachmentProcessing.ATTACHMENTS_ONLY
):
+ self.log(
+ "debug",
+ f"Rule {rule}: "
+ f"Skipping attachment {att.filename} "
+ f"with content disposition {att.content_disposition}",
+ )
continue
- title = self.get_title(message, att, rule)
+ if rule.filter_attachment_filename:
+ # Force the filename and pattern to the lowercase
+ # as this is system dependent otherwise
+ if not fnmatch(
+ att.filename.lower(),
+ rule.filter_attachment_filename.lower(),
+ ):
+ continue
- # don't trust the content type of the attachment. Could be
- # generic application/octet-stream.
- mime_type = magic.from_buffer(att.payload, mime=True)
+ title = self.get_title(message, att, rule)
- if is_mime_type_supported(mime_type):
+ # don't trust the content type of the attachment. Could be
+ # generic application/octet-stream.
+ mime_type = magic.from_buffer(att.payload, mime=True)
- os.makedirs(settings.SCRATCH_DIR, exist_ok=True)
- _, temp_filename = tempfile.mkstemp(
- prefix="paperless-mail-",
- dir=settings.SCRATCH_DIR,
- )
- with open(temp_filename, "wb") as f:
- f.write(att.payload)
+ if is_mime_type_supported(mime_type):
- self.log(
- "info",
- f"Rule {rule}: "
- f"Consuming attachment {att.filename} from mail "
- f"{message.subject} from {message.from_}",
- )
+ os.makedirs(settings.SCRATCH_DIR, exist_ok=True)
+ _, temp_filename = tempfile.mkstemp(
+ prefix="paperless-mail-",
+ dir=settings.SCRATCH_DIR,
+ )
+ with open(temp_filename, "wb") as f:
+ f.write(att.payload)
- consume_file.delay(
- path=temp_filename,
- override_filename=pathvalidate.sanitize_filename(
- att.filename,
- ),
- override_title=title,
- override_correspondent_id=correspondent.id
- if correspondent
- else None,
- override_document_type_id=doc_type.id if doc_type else None,
- override_tag_ids=tag_ids,
- task_name=att.filename[:100],
- )
+ self.log(
+ "info",
+ f"Rule {rule}: "
+ f"Consuming attachment {att.filename} from mail "
+ f"{message.subject} from {message.from_}",
+ )
- async_task(
- "documents.tasks.consume_file",
- processed_attachments += 1
- else:
- self.log(
- "debug",
- f"Rule {rule}: "
- f"Skipping attachment {att.filename} "
- f"since guessed mime type {mime_type} is not supported "
- f"by paperless",
- )
++ consume_file.delay(
+ path=temp_filename,
+ override_filename=pathvalidate.sanitize_filename(
+ att.filename,
+ ),
+ override_title=title,
+ override_correspondent_id=correspondent.id
+ if correspondent
+ else None,
+ override_document_type_id=doc_type.id if doc_type else None,
+ override_tag_ids=tag_ids,
+ task_name=att.filename[:100],
+ )
+
+ processed_attachments += 1
+ else:
+ self.log(
+ "debug",
+ f"Rule {rule}: "
+ f"Skipping attachment {att.filename} "
+ f"since guessed mime type {mime_type} is not supported "
+ f"by paperless",
+ )
return processed_attachments