~barry/mailman/events-and-web

« back to all changes in this revision

Viewing changes to src/mailman/interfaces/messages.py

  • Committer: klm
  • Date: 1998-01-07 21:21:35 UTC
  • Revision ID: vcs-imports@canonical.com-19980107212135-sv0y521ps0xye37r
Initial revision

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2012 by the Free Software Foundation, Inc.
2
 
#
3
 
# This file is part of GNU Mailman.
4
 
#
5
 
# GNU Mailman is free software: you can redistribute it and/or modify it under
6
 
# the terms of the GNU General Public License as published by the Free
7
 
# Software Foundation, either version 3 of the License, or (at your option)
8
 
# any later version.
9
 
#
10
 
# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11
 
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
 
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13
 
# more details.
14
 
#
15
 
# You should have received a copy of the GNU General Public License along with
16
 
# GNU Mailman.  If not, see <http://www.gnu.org/licenses/>.
17
 
 
18
 
"""The message storage service."""
19
 
 
20
 
from __future__ import absolute_import, unicode_literals
21
 
 
22
 
__metaclass__ = type
23
 
__all__ = [
24
 
    'IMessage',
25
 
    'IMessageStore',
26
 
    ]
27
 
 
28
 
 
29
 
from zope.interface import Interface, Attribute
30
 
 
31
 
 
32
 
 
33
 
class IMessageStore(Interface):
34
 
    """The interface of the global message storage service.
35
 
 
36
 
    All messages that are stored in the system live in the message storage
37
 
    service.  A message stored in this service must have a Message-ID header.
38
 
    The store writes an X-Message-ID-Hash header which contains the Base32
39
 
    encoded SHA1 hash of the message's Message-ID header.  Any existing
40
 
    X-Message-ID-Hash header is overwritten.
41
 
 
42
 
    Either the Message-ID or the X-Message-ID-Hash header can be used to
43
 
    uniquely identify this message in the storage service.  While it is
44
 
    possible to see duplicate Message-IDs, this is never correct and the
45
 
    service is allowed to drop any subsequent colliding messages, or overwrite
46
 
    earlier messages with later ones.
47
 
 
48
 
    The combination of the List-Archive header and either the Message-ID or
49
 
    X-Message-ID-Hash header can be used to retrieve the message from the
50
 
    internet facing interface for the message store.  This can be considered a
51
 
    globally unique URI to the message.
52
 
 
53
 
    For example, a message with the following headers:
54
 
 
55
 
    Message-ID: <87myycy5eh.fsf@uwakimon.sk.tsukuba.ac.jp>
56
 
    Date: Wed, 04 Jul 2007 16:49:58 +0900
57
 
    List-Archive: http://archive.example.com/
58
 
    X-Message-ID-Hash: RXTJ357KFOTJP3NFJA6KMO65X7VQOHJI
59
 
 
60
 
    the globally unique URI would be:
61
 
 
62
 
    http://archive.example.com/RXTJ357KFOTJP3NFJA6KMO65X7VQOHJI
63
 
    """
64
 
 
65
 
    def add(message):
66
 
        """Add the message to the store.
67
 
 
68
 
        :param message: An email.message.Message instance containing at least
69
 
            a unique Message-ID header.  The message will be given an
70
 
            X-Message-ID-Hash header, overriding any existing such header.
71
 
        :returns: The calculated X-Message-ID-Hash header.
72
 
        :raises ValueError: if the message is missing a Message-ID header.
73
 
            The storage service is also allowed to raise this exception if it
74
 
            find, but disallows collisions.
75
 
        """
76
 
 
77
 
    def get_message_by_id(message_id):
78
 
        """Return the message with a matching Message-ID.
79
 
 
80
 
        :param message_id: The Message-ID header contents to search for.
81
 
        :returns: The message, or None if no matching message was found.
82
 
        """
83
 
 
84
 
    def get_message_by_hash(message_id_hash):
85
 
        """Return the message with the matching X-Message-ID-Hash.
86
 
        
87
 
        :param message_id_hash: The X-Message-ID-Hash header contents to
88
 
            search for.
89
 
        :returns: The message, or None if no matching message was found.
90
 
        """
91
 
 
92
 
    def delete_message(message_id):
93
 
        """Remove the given message from the store.
94
 
 
95
 
        :param message: The Message-ID of the mesage to delete from the store.
96
 
        :raises LookupError: if there is no such message.
97
 
        """
98
 
 
99
 
    messages = Attribute(
100
 
        """An iterator over all messages in this message store.""")
101
 
 
102
 
 
103
 
 
104
 
class IMessage(Interface):
105
 
    """The representation of an email message."""
106
 
 
107
 
    message_id = Attribute("""The message's Message-ID header.""")
108
 
 
109
 
    message_id_hash = Attribute("""The unique SHA1 hash of the message.""")
110
 
 
111
 
    path = Attribute("""The filesystem path to the message object.""")