4 // Copyright (C) 2004 Novell, Inc.
8 // Permission is hereby granted, free of charge, to any person obtaining a
9 // copy of this software and associated documentation files (the "Software"),
10 // to deal in the Software without restriction, including without limitation
11 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 // and/or sell copies of the Software, and to permit persons to whom the
13 // Software is furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 // DEALINGS IN THE SOFTWARE.
28 using System
.Collections
;
29 using System
.Diagnostics
;
31 using System
.Text
.RegularExpressions
;
32 using BU
= Beagle
.Util
;
36 namespace Beagle
.Tile
{
38 [HitFlavor (Name
="Email", Rank
=1100, Emblem
="emblem-mail-message.png", Color
="#f5f5f5",
40 public class TileMailMessage
: TileFromHitTemplate
{
44 string groupwise_name
;
50 static bool ebook_failed
= false;
53 public TileMailMessage (Hit _hit
) : base (_hit
,
54 "template-mail-message.html")
58 protected override void PopulateTemplate ()
60 base.PopulateTemplate ();
62 bool sent
= (Hit
["fixme:isSent"] != null);
66 str
= Hit
["fixme:subject"];
68 str
= String
.Format ("<i>{0}</i>", Catalog
.GetString ("No Subject"));
69 if (Hit
["_IsDeleted"] != null)
70 str
= "<strike>" + str
+ "</strike>";
71 Template
["Subject"] = str
;
73 Template
["ToFrom"] = sent
? Catalog
.GetString ("To") : Catalog
.GetString ("From");
76 // Limit the number of recipients to 3, so the
77 // tile doesn't look terrible.
78 ICollection list
= InternetAddress
.ParseString (Hit
["fixme:to"]);
81 Template
["Who"] = Hit
["fixme:to"];
83 StringBuilder sb
= new StringBuilder ();
86 foreach (InternetAddress ia
in list
) {
87 sb
.Append (ia
.ToString (false));
97 Template
["Who"] = sb
.ToString ();
100 Template
["Who"] = Hit
["fixme:from"];
102 Template
["Folder"] = Hit
["fixme:folder"];
103 Template
["Account"] = Hit
["fixme:account"];
104 Template
["SentReceived"] = sent
? Catalog
.GetString ("Sent") : Catalog
.GetString ("Received");
105 Template
["When"] = sent
? Hit
["fixme:sentdate"] : Hit
["fixme:received"];
108 if (Hit
["fixme:isAnswered"] != null)
109 icon
= Images
.GetHtmlSourceForStock ("stock_mail-replied", 48);
110 else if (Hit
["fixme:isSeen"] != null)
111 icon
= Images
.GetHtmlSourceForStock ("stock_mail-open", 48);
113 icon
= Images
.GetHtmlSourceForStock ("stock_mail", 48);
115 Template
["Icon"] = icon
;
116 if (Hit
["fixme:isFlagged"] != null)
117 Template
["FollowupIcon"] = Images
.GetHtmlSourceForStock ("stock_mail-priority-high", 16);
118 if (Hit
["fixme:hasAttachments"] != null)
119 Template
["AttachmentIcon"] = Images
.GetHtmlSourceForStock ("stock_attach", 16);
121 GetImNames (Template
["Who"]);
124 if (aim_name
!= null)
125 Template
["CanSendIm"] = "";
129 private string GetEmail (string who
)
131 Regex re
= new Regex (@".*<(?<email>.*)>");
132 MatchCollection matches
= re
.Matches (who
);
133 foreach (Match match
in matches
) {
134 if (match
.Length
!= 0) {
135 return match
.Groups
["email"].ToString ();
142 private void GetImNames (string who
)
145 Evolution
.Book addressbook
= null;
151 addressbook
= Evolution
.Book
.NewSystemAddressbook ();
152 addressbook
.Open (true);
153 } catch (Exception e
) {
154 Console
.WriteLine ("\nCould not open Evolution addressbook:\n" + e
);
159 string email
= GetEmail (who
);
161 System
.Console
.WriteLine ("Looking for im name for {0}",
163 System
.Console
.WriteLine ("FIXME: This query is using the Evolution addressbook instead of querying Beagle directly. This is slow, dumb, etc.");
166 String
.Format ("(is \"email\" \"{0}\")", email
);
168 Evolution
.BookQuery query
= Evolution
.BookQuery
.FromString (qstr
);
173 Evolution
.Contact
[] matches
= addressbook
.GetContacts (query
);
174 foreach (Evolution
.Contact c
in matches
) {
175 if (c
.ImAim
.Length
> 0)
176 aim_name
= c
.ImAim
[0];
177 if (c
.ImIcq
.Length
> 0)
178 icq_name
= c
.ImIcq
[0];
179 if (c
.ImJabber
.Length
> 0)
180 jabber_name
= c
.ImJabber
[0];
181 if (c
.ImMsn
.Length
> 0)
182 msn_name
= c
.ImMsn
[0];
183 if (c
.ImYahoo
.Length
> 0)
184 yahoo_name
= c
.ImYahoo
[0];
185 if (c
.ImGroupwise
.Length
> 0)
186 groupwise_name
= c
.ImGroupwise
[0];
192 public override void Open ()
194 Process p
= new Process ();
195 p
.StartInfo
.UseShellExecute
= false;
196 p
.StartInfo
.FileName
= "evolution";
197 p
.StartInfo
.Arguments
= "'" + Hit
.Uri
+ "'";
201 } catch (System
.ComponentModel
.Win32Exception e
) {
202 Console
.WriteLine ("Unable to run {0}: {1}", p
.StartInfo
.FileName
, e
.Message
);
210 bool sent
= (Hit
["fixme:isSent"] != null);
211 string address
= sent
? Hit
["fixme:to"] : Hit
["fixme:from"];
213 Process p
= new Process ();
214 p
.StartInfo
.UseShellExecute
= false;
215 p
.StartInfo
.FileName
= "evolution";
216 p
.StartInfo
.Arguments
= "'mailto:" + address
+ "'";
220 } catch (System
.ComponentModel
.Win32Exception e
) {
221 Console
.WriteLine ("Unable to run {0}: {1}", p
.StartInfo
.FileName
, e
.Message
);
227 public void SendIm ()
229 if (aim_name
!= null)
230 SendImAim (aim_name
);
231 if (groupwise_name
!= null)
232 SendImGroupwise (groupwise_name
);
233 if (icq_name
!= null)
234 SendImIcq (icq_name
);
235 if (jabber_name
!= null)
236 SendImJabber (jabber_name
);
237 if (msn_name
!= null)
238 SendImMsn (msn_name
);
239 if (yahoo_name
!= null)
240 SendImYahoo (yahoo_name
);