Forgot to bump FSQ version. Weekend syndrome.
[beagle.git] / search / Tiles / MailMessage.cs
bloba490db06c7f64226d30a468d1d771c104b3b3d03
1 using System;
2 using System.Diagnostics;
3 using Mono.Unix;
5 namespace Search.Tiles {
7 public class MailMessageActivator : TileActivator {
9 public MailMessageActivator () : base ()
11 AddSupportedFlavor (new HitFlavor (null, null, "message/rfc822"));
14 public override bool Validate (Beagle.Hit hit)
16 if (! base.Validate (hit))
17 return false;
19 // This handles a case when a file with the message/rfc822
20 // mimetype is indexed without gmime. Thus we fail to extract
21 // any info and this tile is useless.
22 if (hit ["beagle:HitType"] == "File") {
23 string subject = hit.GetFirstProperty ("dc:title");
25 if (subject != null && subject != "")
26 return true;
28 return false;
31 return true;
34 public override Tile BuildTile (Beagle.Hit hit, Beagle.Query query)
36 return new MailMessage (hit, query);
40 public class MailMessage : TileFlat {
42 public MailMessage (Beagle.Hit hit, Beagle.Query query) : base (hit, query)
44 Group = TileGroup.Conversations;
46 subject.LabelProp = Title = hit.GetFirstProperty ("dc:title");
47 from.LabelProp = "<b>" + GetAddress (hit) + "</b>";
48 try {
49 Timestamp = Utils.ParseTimestamp (hit.GetFirstProperty ("fixme:date"));
50 date.LabelProp = Utils.NiceShortDate (Timestamp);
51 } catch {}
53 AddAction (new TileAction (Catalog.GetString ("Send in Mail"), SendInMail));
56 protected override void LoadIcon (Gtk.Image image, int size)
58 if (Hit.GetFirstProperty ("fixme:isAnswered") != null)
59 image.Pixbuf = WidgetFu.LoadThemeIcon ("stock_mail-replied", size);
60 else if (Hit.GetFirstProperty ("fixme:isSeen") != null)
61 image.Pixbuf = WidgetFu.LoadThemeIcon ("stock_mail-open", size);
62 else
63 image.Pixbuf = WidgetFu.LoadThemeIcon ("stock_mail", size);
66 private static string GetAddress (Beagle.Hit hit)
68 bool sent = (hit.GetFirstProperty ("fixme:isSent") != null);
69 string address = sent ? hit.GetFirstProperty ("fixme:to") : hit.GetFirstProperty ("fixme:from");
71 if (address == null)
72 return "";
73 if (address.IndexOf (" <") != -1)
74 address = address.Substring (0, address.IndexOf (" <"));
76 return address;
79 protected override DetailsPane GetDetails ()
81 DetailsPane details = new DetailsPane ();
83 details.AddLabelPair (Catalog.GetString ("Subject:"),
84 SubjectLabel.Text,
85 0, 1);
86 details.AddLabelPair (Catalog.GetString ("From:"),
87 GetAddress (Hit),
88 1, 1);
89 details.AddLabelPair (Catalog.GetString ("Date Received:"),
90 DateLabel.Text,
91 2, 1);
93 details.AddSnippet (3, 1);
95 return details;
98 public override void Open ()
100 string uri_str;
102 if (Hit.GetFirstProperty ("fixme:client") != "evolution") {
103 OpenFromMime (Hit);
104 return;
107 Process p = new Process ();
108 p.StartInfo.UseShellExecute = false;
109 p.StartInfo.FileName = "evolution";
111 if (Hit.ParentUriAsString != null)
112 uri_str = Hit.ParentUriAsString;
113 else
114 uri_str = Hit.UriAsString;
116 p.StartInfo.Arguments = "'" + uri_str + "'";
118 try {
119 p.Start ();
120 } catch (System.ComponentModel.Win32Exception e) {
121 Console.WriteLine ("Unable to run {0}: {1}", p.StartInfo.FileName, e.Message);
125 public void SendInMail ()
127 if (Hit.GetFirstProperty ("fixme:client") != "evolution")
128 return;
130 Process p = new Process ();
131 p.StartInfo.UseShellExecute = false;
132 p.StartInfo.FileName = "evolution";
133 p.StartInfo.Arguments = String.Format ("\"{0};forward=attached\"", Hit.Uri);
135 try {
136 p.Start () ;
137 } catch (Exception e) {
138 Console.WriteLine ("Error launching Evolution composer: " + e);