3
// GNOME Do is the legal property of its developers, whose names are too
4
// numerous to list here. Please refer to the COPYRIGHT file distributed with
5
// this source distribution.
7
// This program is free software: you can redistribute it and/or modify it under
8
// the terms of the GNU General Public License as published by the Free Software
9
// Foundation, either version 3 of the License, or (at your option) any later
12
// This program is distributed in the hope that it will be useful, but WITHOUT
13
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17
// You should have received a copy of the GNU General Public License along with
18
// this program. If not, see <http://www.gnu.org/licenses/>.
21
using System.Text.RegularExpressions;
29
public class EmailAction : AbstractAction
31
public override string Name {
33
return Catalog.GetString ("Email");
37
public override string Description {
39
return Catalog.GetString ("Compose a new email to a friend.");
43
public override string Icon {
44
get { return "stock_mail-compose"; }
47
public override Type [] SupportedItemTypes {
51
typeof (IContactDetailItem),
57
public override Type [] SupportedModifierItemTypes {
65
public override bool ModifierItemsOptional {
69
public override bool SupportsItem (IItem item)
71
if (item is ContactItem) {
72
foreach (string detail in (item as ContactItem).Details) {
73
if (detail.StartsWith ("email"))
76
} else if (item is IContactDetailItem) {
77
return (item as IContactDetailItem).Key.StartsWith ("email");
78
} else if (item is ITextItem) {
80
// Regex should conform to RFC2822.
81
@"[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?"
82
).IsMatch ((item as ITextItem).Text);
87
public override IItem [] Perform (IItem [] items, IItem [] modItems)
89
string emails, email, body;
91
emails = email = string.Empty;
92
foreach (IItem item in items) {
93
if (item is ContactItem) {
94
ContactItem contact = item as ContactItem;
95
email = contact ["email"];
98
foreach (string detail in contact.Details) {
99
if (detail.StartsWith ("email")) {
100
email = contact [detail];
105
} else if (item is IContactDetailItem) {
106
email = (item as IContactDetailItem).Value;
107
} else if (item is ITextItem) {
108
email = (item as ITextItem).Text;
110
emails += email + ",";
114
if (modItems.Length > 0) {
115
body = "?body=" + (modItems [0] as ITextItem).Text
116
.Replace ("\"", "\\\""); // Try to escape quotes...
118
Util.Environment.Open ("\"mailto:" + emails + body + "\"");