Add boolean field to email source to control if the body of the email is to be stored or not.
This commit is contained in:
@@ -11,7 +11,8 @@ from .models import (
|
|||||||
class IMAPEmailAdmin(admin.ModelAdmin):
|
class IMAPEmailAdmin(admin.ModelAdmin):
|
||||||
list_display = (
|
list_display = (
|
||||||
'label', 'enabled', 'uncompress', 'host', 'ssl', 'port', 'interval',
|
'label', 'enabled', 'uncompress', 'host', 'ssl', 'port', 'interval',
|
||||||
'document_type', 'metadata_attachment_name'
|
'document_type', 'metadata_attachment_name', 'from_metadata_type',
|
||||||
|
'subject_metadata_type', 'store_body'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -19,7 +20,8 @@ class IMAPEmailAdmin(admin.ModelAdmin):
|
|||||||
class POP3EmailAdmin(admin.ModelAdmin):
|
class POP3EmailAdmin(admin.ModelAdmin):
|
||||||
list_display = (
|
list_display = (
|
||||||
'label', 'enabled', 'uncompress', 'host', 'ssl', 'port', 'interval',
|
'label', 'enabled', 'uncompress', 'host', 'ssl', 'port', 'interval',
|
||||||
'document_type', 'metadata_attachment_name'
|
'document_type', 'metadata_attachment_name', 'from_metadata_type',
|
||||||
|
'subject_metadata_type', 'store_body'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ class EmailSetupBaseForm(forms.ModelForm):
|
|||||||
'label', 'enabled', 'interval', 'document_type', 'uncompress',
|
'label', 'enabled', 'interval', 'document_type', 'uncompress',
|
||||||
'host', 'ssl', 'port', 'username', 'password',
|
'host', 'ssl', 'port', 'username', 'password',
|
||||||
'metadata_attachment_name', 'subject_metadata_type',
|
'metadata_attachment_name', 'subject_metadata_type',
|
||||||
'from_metadata_type'
|
'from_metadata_type', 'store_body'
|
||||||
)
|
)
|
||||||
widgets = {
|
widgets = {
|
||||||
'password': forms.widgets.PasswordInput(render_value=True)
|
'password': forms.widgets.PasswordInput(render_value=True)
|
||||||
|
|||||||
26
mayan/apps/sources/migrations/0010_auto_20151001_0055.py
Normal file
26
mayan/apps/sources/migrations/0010_auto_20151001_0055.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import models, migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('sources', '0009_auto_20150930_2341'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='emailbasemodel',
|
||||||
|
name='store_body',
|
||||||
|
field=models.BooleanField(default=True, help_text='Store the body of the email as a text document.', verbose_name='Store email body'),
|
||||||
|
preserve_default=True,
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='imapemail',
|
||||||
|
name='mailbox',
|
||||||
|
field=models.CharField(default='INBOX', help_text='IMAP Mailbox from which to check for messages.', max_length=64, verbose_name='Mailbox'),
|
||||||
|
preserve_default=True,
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -354,6 +354,11 @@ class EmailBaseModel(IntervalBaseModel):
|
|||||||
), null=True, related_name='email_from',
|
), null=True, related_name='email_from',
|
||||||
verbose_name=_('From metadata type')
|
verbose_name=_('From metadata type')
|
||||||
)
|
)
|
||||||
|
store_body = models.BooleanField(
|
||||||
|
default=True, help_text=_(
|
||||||
|
'Store the body of the email as a text document.'
|
||||||
|
), verbose_name=_('Store email body')
|
||||||
|
)
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
if self.subject_metadata_type:
|
if self.subject_metadata_type:
|
||||||
@@ -453,7 +458,7 @@ class EmailBaseModel(IntervalBaseModel):
|
|||||||
|
|
||||||
logger.debug('content_type: %s', content_type)
|
logger.debug('content_type: %s', content_type)
|
||||||
|
|
||||||
if content_type == 'text/plain':
|
if content_type == 'text/plain' and source.store_body:
|
||||||
content = part.get_payload(decode=True).decode(part.get_content_charset())
|
content = part.get_payload(decode=True).decode(part.get_content_charset())
|
||||||
with ContentFile(content=content, name='email_body.txt') as file_object:
|
with ContentFile(content=content, name='email_body.txt') as file_object:
|
||||||
source.handle_upload(
|
source.handle_upload(
|
||||||
|
|||||||
Reference in New Issue
Block a user