2 using System
.Diagnostics
;
7 namespace Search
.Tiles
{
9 public class MailMessageActivator
: TileActivator
{
11 public MailMessageActivator () : base ()
13 AddSupportedFlavor (new HitFlavor (null, null, "message/rfc822"));
15 // This one allows us to handle HTML child indexables
16 // that contain the actual body of the message as real
17 // mail tiles. We don't have to worry about them also
18 // appearing as mail attachments because they aren't
19 // considered attachments during indexing.
20 AddSupportedFlavor (new HitFlavor (null, "MailMessage", "text/html"));
23 public override bool Validate (Beagle
.Hit hit
)
25 if (! base.Validate (hit
))
28 if (hit
["beagle:HitType"] == "File") {
29 // This handles a case when a file with the
30 // message/rfc822 mimetype is indexed without
31 // gmime. Thus we fail to extract any info and
32 // this tile is useless.
33 string subject
= hit
.GetFirstProperty ("dc:title");
35 if (subject
!= null && subject
!= "")
44 public override Tile
BuildTile (Beagle
.Hit hit
, Beagle
.Query query
)
46 return new MailMessage (hit
, query
);
50 public class MailMessage
: TileFlat
{
52 public MailMessage (Beagle
.Hit hit
, Beagle
.Query query
) : base (hit
, query
)
54 Group
= TileGroup
.Conversations
;
56 string title
= Utils
.GetFirstPropertyOfParent (hit
, "dc:title");
57 if (title
== null || title
== String
.Empty
)
58 title
= Catalog
.GetString ("(untitled)");
59 Subject
.LabelProp
= Title
= title
;
61 From
.LabelProp
= "<b>" + GetAddress (hit
) + "</b>";
63 Timestamp
= Utils
.ParseTimestamp (Utils
.GetFirstPropertyOfParent (hit
, "fixme:date"));
64 Date
.LabelProp
= Utils
.NiceShortDate (Timestamp
);
67 if (Utils
.GetFirstPropertyOfParent (Hit
, "fixme:client") == "evolution")
68 AddAction (new TileAction (Catalog
.GetString ("Send in Mail"), SendInMail
));
71 protected override void LoadIcon (Gtk
.Image image
, int size
)
73 if (Utils
.GetFirstPropertyOfParent (Hit
, "fixme:isAnswered") != null)
74 image
.Pixbuf
= WidgetFu
.LoadThemeIcon ("stock_mail-replied", size
);
75 else if (Utils
.GetFirstPropertyOfParent (Hit
, "fixme:isSeen") != null)
76 image
.Pixbuf
= WidgetFu
.LoadThemeIcon ("stock_mail-open", size
);
78 image
.Pixbuf
= WidgetFu
.LoadThemeIcon ("stock_mail", size
);
81 private static string GetAddress (Beagle
.Hit hit
)
83 bool sent
= (Utils
.GetFirstPropertyOfParent (hit
, "fixme:isSent") != null);
84 string address
= sent
? Utils
.GetFirstPropertyOfParent (hit
, "fixme:to") : Utils
.GetFirstPropertyOfParent (hit
, "fixme:from");
88 if (address
.IndexOf (" <") != -1)
89 address
= address
.Substring (0, address
.IndexOf (" <"));
94 protected override DetailsPane
GetDetails ()
96 DetailsPane details
= new DetailsPane ();
98 bool sent
= (Utils
.GetFirstPropertyOfParent (Hit
, "fixme:isSent") != null);
100 details
.AddLabelPair (Catalog
.GetString ("Subject:"), SubjectLabel
.Text
);
102 string label
= sent
? Catalog
.GetString ("To:") : Catalog
.GetString ("From:");
103 details
.AddLabelPair (label
, GetAddress (Hit
));
105 label
= sent
? Catalog
.GetString ("Date Sent:") : Catalog
.GetString ("Date Received:");
106 details
.AddLabelPair (label
, Utils
.NiceLongDate (Timestamp
));
108 string folder
= Hit
.GetFirstProperty ("fixme:folder");
111 details
.AddLabelPair (Catalog
.GetString ("Folder:"), folder
);
113 details
.AddSnippet ();
118 public static SafeProcess
GetClientProcess (string client
, string uri
)
120 SafeProcess p
= null;
122 if (client
== "evolution") {
123 p
= new SafeProcess ();
124 p
.Arguments
= new string [2];
125 p
.Arguments
[0] = "evolution";
126 p
.Arguments
[1] = uri
;
127 #if ENABLE_THUNDERBIRD
128 } else if (client
== "thunderbird") {
129 p
= new SafeProcess ();
130 p
.Arguments
= new string [3];
131 p
.Arguments
[0] = Thunderbird
.ExecutableName
;
132 p
.Arguments
[1] = "-mail";
133 p
.Arguments
[2] = uri
;
140 public override void Open ()
143 if (Hit
.ParentUri
!= null)
144 p
= GetClientProcess (Utils
.GetFirstPropertyOfParent (Hit
, "fixme:client"), Hit
.EscapedParentUri
);
146 p
= GetClientProcess (Utils
.GetFirstPropertyOfParent (Hit
, "fixme:client"), Hit
.EscapedUri
);
155 } catch (SafeProcessException e
) {
156 Console
.WriteLine ("Unable to run {0}: {1}", p
.Arguments
[0], e
.Message
);
160 public void SendInMail ()
162 SafeProcess p
= new SafeProcess ();
165 if (Hit
.ParentUri
!= null)
166 uri
= Hit
.EscapedParentUri
;
168 uri
= Hit
.EscapedUri
;
170 p
.Arguments
= new string [] { "evolution", String.Format ("{0}
;forward
=attached
", uri) };
174 } catch (Exception e) {
175 Console.WriteLine ("Error launching Evolution composer
: " + e.Message);