2 // Rss.cs: Adds RSS feed 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
;
37 namespace Beagle
.Daemon
.ThunderbirdQueryable
{
39 [ThunderbirdIndexableGenerator (TB
.AccountType
.Rss
, "RSS Support", true)]
40 public class RssIndexableGenerator
: ThunderbirdIndexableGenerator
{
41 private string feed_url
;
43 public RssIndexableGenerator (ThunderbirdIndexer indexer
, TB
.Account account
, string mork_file
)
44 : base (indexer
, account
, mork_file
)
48 public override bool HasNextIndexable ()
51 if (DbEnumerator
== null || !DbEnumerator
.MoveNext ()) {
53 indexer
.NotificationEvent
-= OnNotification
;
54 indexer
.ChildComplete ();
57 } while (IsUpToDate ((DbEnumerator
.Current
as TB
.RssFeed
).Uri
));
62 public override Indexable
GetNextIndexable ()
64 TB
.RssFeed feed
= DbEnumerator
.Current
as TB
.RssFeed
;
66 // If status is different, than something happend when loading this mail and we dont'
67 // want to change it's status.
68 if (feed
.GetObject ("FullIndex") == null)
69 feed
.SetObject ("FullIndex", (object) FullIndex
);
71 return RssFeedToIndexable (feed
);
74 public override void LoadDatabase ()
76 string folder_name
= null;
79 db
= new TB
.Database (account
, DbFile
);
82 Hashtable tbl
= db
.Db
.Compile ("1", "ns:msg:db:row:scope:dbfolderinfo:all");
83 feed_url
= tbl
["feedUrl"] as string;
84 folder_name
= tbl
["folderName"] as string;
85 } catch (Exception e
) {
86 Logger
.Log
.Warn (e
, "Failed to load {0}:", DbFile
);
91 Logger
.Log
.Debug ("Empty file {0}; skipping", DbFile
);
95 Logger
.Log
.Info ("Indexing \"{0}\" RSS feed containing {1} entries ({2})", folder_name
, db
.Count
, RelativePath
);
98 private Indexable
RssFeedToIndexable (TB
.RssFeed feed
)
101 StringReader content
= feed
.Content
;
103 indexable
= NewIndexable (feed
.Uri
, DateTime
.Parse (feed
.GetString ("date")).ToUniversalTime (), "FeedItem");
104 indexable
.MimeType
= "text/html";
106 indexable
.AddProperty (Property
.NewKeyword ("dc:identifier", feed
.GetString ("message-id")));
107 indexable
.AddProperty (Property
.NewKeyword ("dc:source", feed_url
));
108 indexable
.AddProperty (Property
.New ("dc:publisher", feed
.GetString ("sender")));
110 indexable
.AddProperty (Property
.New ("dc:title", feed
.GetString ("subject")));
112 indexable
.SetTextReader (content
);