2 using System
.Diagnostics
;
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
))
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
!= "")
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>";
50 Timestamp
= Utils
.ParseTimestamp (hit
.GetFirstProperty ("fixme:date"));
51 Date
.LabelProp
= Utils
.NiceShortDate (Timestamp
);
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
);
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");
75 if (address
.IndexOf (" <") != -1)
76 address
= address
.Substring (0, address
.IndexOf (" <"));
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 ();
100 public override void Open ()
102 if (Hit
.GetFirstProperty ("fixme:client") != "evolution") {
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
;
114 p
.Arguments
[1] = Hit
.UriAsString
;
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) };
130 } catch (Exception e) {
131 Console.WriteLine ("Error launching Evolution composer
: " + e.Message);