2 // Nntp.cs: Adds NNTP indexing support to the Thunderbird backend
4 // Copyright (C) 2006 Pierre Östlund
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
29 using System
.Collections
;
30 using System
.Reflection
;
31 using System
.Text
.RegularExpressions
;
35 using TB
= Beagle
.Util
.Thunderbird
;
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 ()
52 if (DbEnumerator
== null || !DbEnumerator
.MoveNext ()) {
54 indexer
.NotificationEvent
-= OnNotification
;
55 indexer
.ChildComplete ();
58 } while (IsUpToDate ((DbEnumerator
.Current
as TB
.NntpMessage
).Uri
));
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 ()
78 db
= new TB
.Database (account
, DbFile
);
80 } catch (Exception e
) {
81 Logger
.Log
.Warn (e
, "Failed to load {0}:", DbFile
);
86 Logger
.Log
.Debug ("Empty file {0}; skipping", DbFile
);
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
)
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
));