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:
Roberto Rosario
2015-09-30 20:57:47 -04:00
parent 3d0c9485d0
commit 97d8529994
4 changed files with 37 additions and 4 deletions

View File

@@ -11,7 +11,8 @@ from .models import (
class IMAPEmailAdmin(admin.ModelAdmin):
list_display = (
'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):
list_display = (
'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'
)

View File

@@ -89,7 +89,7 @@ class EmailSetupBaseForm(forms.ModelForm):
'label', 'enabled', 'interval', 'document_type', 'uncompress',
'host', 'ssl', 'port', 'username', 'password',
'metadata_attachment_name', 'subject_metadata_type',
'from_metadata_type'
'from_metadata_type', 'store_body'
)
widgets = {
'password': forms.widgets.PasswordInput(render_value=True)

View 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,
),
]

View File

@@ -354,6 +354,11 @@ class EmailBaseModel(IntervalBaseModel):
), null=True, related_name='email_from',
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):
if self.subject_metadata_type:
@@ -453,7 +458,7 @@ class EmailBaseModel(IntervalBaseModel):
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())
with ContentFile(content=content, name='email_body.txt') as file_object:
source.handle_upload(