2 using System
.Diagnostics
;
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
))
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
!= "")
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>";
49 Timestamp
= Utils
.ParseTimestamp (hit
.GetFirstProperty ("fixme:date"));
50 date
.LabelProp
= Utils
.NiceShortDate (Timestamp
);
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
);
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");
73 if (address
.IndexOf (" <") != -1)
74 address
= address
.Substring (0, address
.IndexOf (" <"));
79 protected override DetailsPane
GetDetails ()
81 DetailsPane details
= new DetailsPane ();
83 details
.AddLabelPair (Catalog
.GetString ("Subject:"),
86 details
.AddLabelPair (Catalog
.GetString ("From:"),
89 details
.AddLabelPair (Catalog
.GetString ("Date Received:"),
93 details
.AddSnippet (3, 1);
98 public override void Open ()
102 if (Hit
.GetFirstProperty ("fixme:client") != "evolution") {
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
;
114 uri_str
= Hit
.UriAsString
;
116 p
.StartInfo
.Arguments
= "'" + uri_str
+ "'";
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")
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
);
137 } catch (Exception e
) {
138 Console
.WriteLine ("Error launching Evolution composer: " + e
);