Example #1
0
 def test_get_date_header(self):
     # a date header
     msg_txt = 'Date: Thu, 01 Jan 1970 01:00:00 +0100'
     msg = email.message_from_string(msg_txt)
     self.assertEquals(0.0, utils.get_date_header(msg, 'Date'))
     # a date header with timezone name
     msg_txt = 'Date: Sat, 14 Feb 2009 00:31:30 +0100 (CET)'
     msg = email.message_from_string(msg_txt)
     self.assertEquals(1234567890.0, utils.get_date_header(msg, 'Date'))
     # an unparsable date header
     msg_txt = 'Date: at any time ...'
     msg = email.message_from_string(msg_txt)
     self.assertEqual(0.0, utils.get_date_header(msg, 'Date'))
Example #2
0
def receipt_date(obj):
    """Return the receipt date of the mail for the receipt_date indexer.
    We currently approximate this date by using the document date.
    """
    # TODO: Parse received-values of header mail
    document_date = utils.get_date_header(obj.msg, 'Date')
    return datetime.fromtimestamp(document_date).date()
Example #3
0
def receipt_date(obj):
    """Return the receipt date of the mail for the receipt_date indexer.
    We currently approximate this date by using the document date.
    """
    # TODO: Parse received-values of header mail
    document_date = utils.get_date_header(obj.msg, 'Date')
    return datetime.fromtimestamp(document_date).date()
Example #4
0
    def initialize_required_metadata(self, mail):
        mail_metadata = IDocumentMetadata(mail)

        date_time = datetime.fromtimestamp(
            utils.get_date_header(mail.msg, 'Date'))
        mail_metadata.document_date = date_time.date()

        # Receipt date should be None for migrated mails
        mail_metadata.receipt_date = None
        mail_metadata.document_author = get_author_by_email(mail)
Example #5
0
def initialize_metadata(mail, event):
    if not ogmetadata.IDocumentMetadata.providedBy(mail):
        return

    if IObjectCopiedEvent.providedBy(event):
        return

    mail_metadata = ogmetadata.IDocumentMetadata(mail)
    date_time = datetime.fromtimestamp(utils.get_date_header(mail.msg, 'Date'))

    mail_metadata.document_date = date_time.date()
    mail_metadata.receipt_date = date.today()
    mail_metadata.document_author = get_author_by_email(mail)
Example #6
0
def initialize_metadata(mail, event):
    if not ogmetadata.IDocumentMetadata.providedBy(mail):
        return

    if IObjectCopiedEvent.providedBy(event):
        return

    mail_metadata = ogmetadata.IDocumentMetadata(mail)
    date_time = datetime.fromtimestamp(utils.get_date_header(mail.msg, 'Date'))

    mail_metadata.document_date = date_time.date()
    mail_metadata.receipt_date = date.today()
    mail_metadata.document_author = get_author_by_email(mail)
Example #7
0
    def get_header(self, name, isdate=False):
        """Returns a header value from the mail message.
        If it is a date, it returns a DateTime.
        This method caches the retrieved values.
        """

        if getattr(self, '_header_cache', None) is None:
            self._reset_header_cache()

        if name not in self._header_cache:
            if isdate:
                ts = utils.get_date_header(self.msg, name)
                if ts is not None:
                    self._header_cache[name] = DateTime(ts)
                else:
                    self._header_cache[name] = ""
            else:
                self._header_cache[name] = utils.get_header(self.msg, name)

        return self._header_cache[name]
Example #8
0
def document_date(obj):
    """Return the sent (not receipt) date of the mail for the
    document_date indexer.
    """
    document_date = utils.get_date_header(obj.msg, 'Date')
    return datetime.fromtimestamp(document_date).date()
Example #9
0
def get_header_date(mail):
    return datetime.fromtimestamp(utils.get_date_header(mail.msg, 'Date'))
Example #10
0
 def get_date_header(self, name):
     return DateTime(utils.get_date_header(self.msg(), name))
Example #11
0
def document_date(obj):
    """Return the sent (not receipt) date of the mail for the
    document_date indexer.
    """
    document_date = utils.get_date_header(obj.msg, 'Date')
    return datetime.fromtimestamp(document_date).date()