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 // Wrapper around Hit.GetFirstProperty() that deals with child indexables
53 private static string GetFirstProperty (Beagle
.Hit hit
, string prop
)
55 if (hit
.ParentUri
== null)
56 return hit
.GetFirstProperty (prop
);
58 return hit
.GetFirstProperty ("parent:" + prop
);
61 public MailMessage (Beagle
.Hit hit
, Beagle
.Query query
) : base (hit
, query
)
63 Group
= TileGroup
.Conversations
;
65 string title
= GetFirstProperty (hit
, "dc:title");
66 if (title
== null || title
== String
.Empty
)
67 title
= Catalog
.GetString ("(untitled)");
68 Subject
.LabelProp
= Title
= title
;
70 From
.LabelProp
= "<b>" + GetAddress (hit
) + "</b>";
72 Timestamp
= Utils
.ParseTimestamp (GetFirstProperty (hit
, "fixme:date"));
73 Date
.LabelProp
= Utils
.NiceShortDate (Timestamp
);
76 if (GetFirstProperty (Hit
, "fixme:client") == "evolution")
77 AddAction (new TileAction (Catalog
.GetString ("Send in Mail"), SendInMail
));
80 protected override void LoadIcon (Gtk
.Image image
, int size
)
82 if (GetFirstProperty (Hit
, "fixme:isAnswered") != null)
83 image
.Pixbuf
= WidgetFu
.LoadThemeIcon ("stock_mail-replied", size
);
84 else if (GetFirstProperty (Hit
, "fixme:isSeen") != null)
85 image
.Pixbuf
= WidgetFu
.LoadThemeIcon ("stock_mail-open", size
);
87 image
.Pixbuf
= WidgetFu
.LoadThemeIcon ("stock_mail", size
);
90 private static string GetAddress (Beagle
.Hit hit
)
92 bool sent
= (GetFirstProperty (hit
, "fixme:isSent") != null);
93 string address
= sent
? GetFirstProperty (hit
, "fixme:to") : GetFirstProperty (hit
, "fixme:from");
97 if (address
.IndexOf (" <") != -1)
98 address
= address
.Substring (0, address
.IndexOf (" <"));
103 protected override DetailsPane
GetDetails ()
105 DetailsPane details
= new DetailsPane ();
107 bool sent
= (GetFirstProperty (Hit
, "fixme:isSent") != null);
109 details
.AddLabelPair (Catalog
.GetString ("Subject:"), SubjectLabel
.Text
);
111 string label
= sent
? Catalog
.GetString ("To:") : Catalog
.GetString ("From:");
112 details
.AddLabelPair (label
, GetAddress (Hit
));
114 label
= sent
? Catalog
.GetString ("Date Sent:") : Catalog
.GetString ("Date Received:");
115 details
.AddLabelPair (label
, Utils
.NiceLongDate (Timestamp
));
117 string folder
= Hit
.GetFirstProperty ("fixme:folder");
120 details
.AddLabelPair (Catalog
.GetString ("Folder:"), folder
);
122 details
.AddSnippet ();
127 public static SafeProcess
GetClientProcess (string client
, string uri
)
129 SafeProcess p
= null;
131 if (client
== "evolution") {
132 p
= new SafeProcess ();
133 p
.Arguments
= new string [2];
134 p
.Arguments
[0] = "evolution";
135 p
.Arguments
[1] = uri
;
136 } else if (client
== "thunderbird") {
137 p
= new SafeProcess ();
138 p
.Arguments
= new string [3];
139 p
.Arguments
[0] = Thunderbird
.ExecutableName
;
140 p
.Arguments
[1] = "-mail";
141 p
.Arguments
[2] = uri
;
147 public override void Open ()
150 if (Hit
.ParentUri
!= null)
151 p
= GetClientProcess (GetFirstProperty ( Hit
, "fixme:client"), Hit
.EscapedParentUri
);
153 p
= GetClientProcess (GetFirstProperty ( Hit
, "fixme:client"), Hit
.EscapedUri
);
162 } catch (SafeProcessException e
) {
163 Console
.WriteLine ("Unable to run {0}: {1}", p
.Arguments
[0], e
.Message
);
167 public void SendInMail ()
169 SafeProcess p
= new SafeProcess ();
172 if (Hit
.ParentUri
!= null)
173 uri
= Hit
.EscapedParentUri
;
175 uri
= Hit
.EscapedUri
;
177 p
.Arguments
= new string [] { "evolution", String.Format ("{0}
;forward
=attached
", uri) };
181 } catch (Exception e) {
182 Console.WriteLine ("Error launching Evolution composer
: " + e.Message);