Add methods and messages to retrieve specific information from beagle-info. Clients...
[beagle.git] / search / Tiles / MailMessage.cs
blobe9167b978271dd8996fd7edce6cdede60b6e5a42
1 using System;
2 using System.Diagnostics;
3 using Mono.Unix;
4 using Beagle.Util;
6 namespace Search.Tiles {
8 public class MailMessageActivator : TileActivator {
10 public MailMessageActivator () : base ()
12 AddSupportedFlavor (new HitFlavor (null, null, "message/rfc822"));
15 public override bool Validate (Beagle.Hit hit)
17 if (! base.Validate (hit))
18 return false;
20 // This handles a case when a file with the message/rfc822
21 // mimetype is indexed without gmime. Thus we fail to extract
22 // any info and this tile is useless.
23 if (hit ["beagle:HitType"] == "File") {
24 string subject = hit.GetFirstProperty ("dc:title");
26 if (subject != null && subject != "")
27 return true;
29 return false;
32 return true;
35 public override Tile BuildTile (Beagle.Hit hit, Beagle.Query query)
37 return new MailMessage (hit, query);
41 public class MailMessage : TileFlat {
43 public MailMessage (Beagle.Hit hit, Beagle.Query query) : base (hit, query)
45 Group = TileGroup.Conversations;
47 Subject.LabelProp = Title = hit.GetFirstProperty ("dc:title");
48 From.LabelProp = "<b>" + GetAddress (hit) + "</b>";
49 try {
50 Timestamp = Utils.ParseTimestamp (hit.GetFirstProperty ("fixme:date"));
51 Date.LabelProp = Utils.NiceShortDate (Timestamp);
52 } catch {}
54 if (Hit.GetFirstProperty ("fixme:client") == "evolution")
55 AddAction (new TileAction (Catalog.GetString ("Send in Mail"), SendInMail));
58 protected override void LoadIcon (Gtk.Image image, int size)
60 if (Hit.GetFirstProperty ("fixme:isAnswered") != null)
61 image.Pixbuf = WidgetFu.LoadThemeIcon ("stock_mail-replied", size);
62 else if (Hit.GetFirstProperty ("fixme:isSeen") != null)
63 image.Pixbuf = WidgetFu.LoadThemeIcon ("stock_mail-open", size);
64 else
65 image.Pixbuf = WidgetFu.LoadThemeIcon ("stock_mail", size);
68 private static string GetAddress (Beagle.Hit hit)
70 bool sent = (hit.GetFirstProperty ("fixme:isSent") != null);
71 string address = sent ? hit.GetFirstProperty ("fixme:to") : hit.GetFirstProperty ("fixme:from");
73 if (address == null)
74 return "";
75 if (address.IndexOf (" <") != -1)
76 address = address.Substring (0, address.IndexOf (" <"));
78 return address;
81 protected override DetailsPane GetDetails ()
83 DetailsPane details = new DetailsPane ();
85 bool sent = (Hit.GetFirstProperty ("fixme:isSent") != null);
87 details.AddLabelPair (Catalog.GetString ("Subject:"), SubjectLabel.Text);
89 string label = sent ? Catalog.GetString ("To:") : Catalog.GetString ("From:");
90 details.AddLabelPair (label, GetAddress (Hit));
92 label = sent ? Catalog.GetString ("Date Sent:") : Catalog.GetString ("Date Received:");
93 details.AddLabelPair (label, Utils.NiceLongDate (Timestamp));
95 details.AddSnippet ();
97 return details;
100 public override void Open ()
102 if (Hit.GetFirstProperty ("fixme:client") != "evolution") {
103 OpenFromMime (Hit);
104 return;
107 SafeProcess p = new SafeProcess ();
108 p.Arguments = new string [2];
109 p.Arguments [0] = "evolution";
111 if (Hit.ParentUriAsString != null)
112 p.Arguments [1] = Hit.ParentUriAsString;
113 else
114 p.Arguments [1] = Hit.UriAsString;
116 try {
117 p.Start ();
118 } catch (SafeProcessException e) {
119 Console.WriteLine ("Unable to run {0}: {1}", p.Arguments [0], e.Message);
123 public void SendInMail ()
125 SafeProcess p = new SafeProcess ();
126 p.Arguments = new string [] { "evolution", String.Format ("{0};forward=attached", Hit.Uri) };
128 try {
129 p.Start () ;
130 } catch (Exception e) {
131 Console.WriteLine ("Error launching Evolution composer: " + e.Message);