Tokenize 001234 as 1234. Include a testing function in NoiseFilter to figure out...
[beagle.git] / beagled / ThunderbirdQueryable / Nntp.cs
blob9c964a19bff6b1ac69059e19da8fd741d664a2ac
1 //
2 // Nntp.cs: Adds NNTP indexing support to the Thunderbird backend
3 //
4 // Copyright (C) 2006 Pierre Östlund
5 //
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
27 using System;
28 using System.IO;
29 using System.Collections;
30 using System.Reflection;
31 using System.Text.RegularExpressions;
33 using Beagle.Util;
34 using Beagle.Daemon;
35 using TB = Beagle.Util.Thunderbird;
37 using GMime;
39 namespace Beagle.Daemon.ThunderbirdQueryable {
41 [ThunderbirdIndexableGenerator (TB.AccountType.Nntp, "NNTP Support", false)]
42 public class NntpIndexableGenerator : ThunderbirdIndexableGenerator {
44 public NntpIndexableGenerator (ThunderbirdIndexer indexer, TB.Account account, string file)
45 : base (indexer, account, file)
49 public override bool HasNextIndexable ()
51 do {
52 if (DbEnumerator == null || !DbEnumerator.MoveNext ()) {
53 Done = true;
54 indexer.NotificationEvent -= OnNotification;
55 indexer.ChildComplete ();
56 return false;
58 } while (IsUpToDate ((DbEnumerator.Current as TB.NntpMessage).Uri));
60 return true;
63 public override Indexable GetNextIndexable ()
65 TB.NntpMessage message = DbEnumerator.Current as TB.NntpMessage;
67 // If status is different, than something happend when loading this mail and we dont'
68 // want to change it's status.
69 if (message.GetObject ("FullIndex") == null)
70 message.SetObject ("FullIndex", (object) FullIndex);
72 return NntpMessageToIndexable (message);
75 public override void LoadDatabase ()
77 try {
78 db = new TB.Database (account, DbFile);
79 db.Load ();
80 } catch (Exception e) {
81 Logger.Log.Warn (e, "Failed to load {0}:", DbFile);
82 return;
85 if (db.Count <= 0) {
86 Logger.Log.Debug ("Empty file {0}; skipping", DbFile);
87 return;
90 FullIndex = (Thunderbird.IsFullyIndexable (DbFile) ? true : false);
91 Logger.Log.Info ("Indexing {0} NNTP messages", db.Count);
94 // FIXME: This need some more info
95 private Indexable NntpMessageToIndexable (TB.NntpMessage message)
97 Indexable indexable;
99 indexable = new Indexable (message.Uri);
100 indexable.HitType = "MailMessage";
101 indexable.MimeType = "message/rfc822";
102 indexable.Timestamp = DateTime.Parse (message.GetString ("date")).ToUniversalTime ();
104 indexable.AddProperty (Property.NewKeyword ("fixme:client", "thunderbird"));
105 indexable.AddProperty (Property.NewUnsearched ("fixme:fullyIndexed", message.GetBool ("FullIndex")));
106 indexable.AddProperty (Property.NewDate ("fixme:indexDateTime", DateTime.UtcNow));
108 string subject = GMime.Utils.HeaderDecodePhrase (message.GetString ("subject"));
109 indexable.AddProperty (Property.New ("dc:title", subject));
111 return indexable;