summaryrefslogtreecommitdiffstats
path: root/hyperkitty/lib/archiver.py
blob: d0af7a278c779ac6b913d8357356e0d0196800b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# -*- coding: utf-8 -*-
"""
Class implementation of Mailman's IArchiver interface
"""


from mailman.interfaces.archiver import IArchiver
from django.core.urlresolvers import reverse
from hyperkitty.lib import ThreadSafeStorePool


class Archiver(object):

    implements(IArchiver)

    name = "hyperkitty"

    def __init__(self):
        self.store = None

    def list_url(self, mlist):
        """Return the url to the top of the list's archive.

        :param mlist: The IMailingList object.
        :returns: The url string.
        """
        return reverse('archives', mlist_fqdn=mlist)

    def permalink(self, mlist, msg):
        """Return the url to the message in the archive.

        This url points directly to the message in the archive.  This method
        only calculates the url, it does not actually archive the message.

        :param mlist: The IMailingList object.
        :param msg: The message object.
        :returns: The url string or None if the message's archive url cannot
            be calculated.
        """
        return reverse('message_index', mlist_fqdn=mlist, hashid=msg.message_id_hash)

    def archive_message(self, mlist, msg):
        """Send the message to the archiver.

        :param mlist: The IMailingList object.
        :param msg: The message object.
        :returns: The url string or None if the message's archive url cannot
            be calculated.
        """
        if self.store is None:
            self.store = ThreadSafeStorePool().get()
        msg.message_id_hash = self.store.add_to_list(mlist.list_name, msg)
        # Update karma