~ubuntu-branches/ubuntu/dapper/lurker/dapper

« back to all changes in this revision

Viewing changes to prune/message.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Meurer
  • Date: 2004-09-26 16:27:51 UTC
  • Revision ID: james.westby@ubuntu.com-20040926162751-z1ohcjltv7ojtg6z
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  $Id: message.cpp,v 1.8 2004/08/19 14:52:29 terpstra Exp $
 
2
 *  
 
3
 *  message.cpp - Cleanup after a message/ command
 
4
 *  
 
5
 *  Copyright (C) 2002 - Wesley W. Terpstra
 
6
 *  
 
7
 *  License: GPL
 
8
 *  
 
9
 *  Authors: 'Wesley W. Terpstra' <wesley@terpstra.ca>
 
10
 *  
 
11
 *    This program is free software; you can redistribute it and/or modify
 
12
 *    it under the terms of the GNU General Public License as published by
 
13
 *    the Free Software Foundation; version 2.
 
14
 *    
 
15
 *    This program is distributed in the hope that it will be useful,
 
16
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 *    GNU General Public License for more details.
 
19
 *    
 
20
 *    You should have received a copy of the GNU General Public License
 
21
 *    along with this program; if not, write to the Free Software
 
22
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
23
 */
 
24
 
 
25
#define _XOPEN_SOURCE 500
 
26
#define _FILE_OFFSET_BITS 64
 
27
 
 
28
#include "PTable.h"
 
29
#include <Keys.h>
 
30
 
 
31
#include <iostream>
 
32
 
 
33
using namespace std;
 
34
 
 
35
bool PTable::test_message(KSI ks)
 
36
{
 
37
        const string::size_type skip = sizeof("message"); // null is /
 
38
        return MessageId::is_full(ks->first.c_str() + skip);
 
39
}
 
40
 
 
41
void PTable::calc_message(KSI ks)
 
42
{
 
43
        /* Messages themselves never change
 
44
         *
 
45
         * ... but messages include:
 
46
         *   list info (from config file)
 
47
         *   thread info
 
48
         *   next/prev for each mbox info
 
49
         *
 
50
         * Policy:
 
51
         *   kill if obsolete due to above
 
52
         *   kill if older than a fixed time
 
53
         *   kill if no recent accesses
 
54
         */
 
55
        
 
56
        if (!test_message(ks))
 
57
        {
 
58
                if (verbose)
 
59
                        cout << ks->first << ": not a lurker file." << endl;
 
60
                return;
 
61
        }
 
62
        
 
63
        MessageId id(ks->first.c_str() + 8);
 
64
        if (ks->second.mtime <= cfg.modified)
 
65
        {       // die - it's older than the config file
 
66
                ks->second.kill = true;
 
67
                if (verbose)
 
68
                        cout << ks->first << ": older than config file." << endl;
 
69
                return;
 
70
        }
 
71
        
 
72
        if (now - ks->second.mtime >= modifiedLimit)
 
73
        {
 
74
                ks->second.kill = true;
 
75
                if (verbose)
 
76
                        cout << ks->first << ": expired due to maximum age." << endl;
 
77
                return;
 
78
        }
 
79
        
 
80
        if (now - ks->second.atime >= accessedLimit)
 
81
        {
 
82
                ks->second.kill = true;
 
83
                if (verbose)
 
84
                        cout << ks->first << ": expired due to no access." << endl;
 
85
                return;
 
86
        }
 
87
        
 
88
        Summary& sum = summaries[id];
 
89
        string tid(subject_hash(sum.subject.c_str()));
 
90
        if (threads.find(tid) != threads.end())
 
91
        {       // die - the thread changed
 
92
                ks->second.kill = true;
 
93
                if (verbose)
 
94
                        cout << ks->first << ": thread modified." << endl;
 
95
                return;
 
96
        }
 
97
        
 
98
        set<string>::const_iterator list;
 
99
        for (list = sum.lists.begin(); list != sum.lists.end(); ++list)
 
100
        {
 
101
                const MessageIds& ids = lists[*list];
 
102
                MessageIds::const_iterator self = ids.find(id);
 
103
                if (self == ids.end())
 
104
                {
 
105
                        // if it can't find us, then we are not in the range
 
106
                        // off messages whose mindex is affected by import
 
107
                        continue;
 
108
                }
 
109
                
 
110
                MessageIds::const_iterator next = self; ++next;
 
111
                MessageIds::const_iterator prev = self; --prev;
 
112
                
 
113
                Summaries::const_iterator ns, ps;
 
114
                
 
115
                if (prev != ids.end() && 
 
116
                   (ps = summaries.find(*prev)) != summaries.end() &&
 
117
                   ps->second.changed)
 
118
                {
 
119
                        ks->second.kill = true;
 
120
                        if (verbose)
 
121
                                cout << ks->first << ": previous message changed in '" << *list << "'." << endl;
 
122
                        return;
 
123
                }
 
124
                
 
125
                if (next != ids.end() && 
 
126
                   (ns = summaries.find(*next)) != summaries.end() &&
 
127
                   ns->second.changed)
 
128
                {
 
129
                        ks->second.kill = true;
 
130
                        if (verbose)
 
131
                                cout << ks->first << ": next message changed in '" << *list << "'." << endl;
 
132
                        return;
 
133
                }
 
134
        }
 
135
        
 
136
        if (verbose)
 
137
                cout << ks->first << ": not expired" << endl;
 
138
}