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/>.
22
using System.Collections.Generic;
23
using System.Text.RegularExpressions;
32
public class EmailAction : AbstractAction
34
public override string Name {
36
return Catalog.GetString ("Email");
40
public override string Description {
42
return Catalog.GetString ("Compose a new email to a friend.");
46
public override string Icon {
47
get { return "stock_mail-compose"; }
50
public override IEnumerable<Type> SupportedItemTypes {
54
typeof (IContactDetailItem),
60
public override IEnumerable<Type> SupportedModifierItemTypes {
62
yield return typeof (ITextItem);
66
public override bool ModifierItemsOptional {
70
public override bool SupportsItem (IItem item)
72
if (item is ContactItem) {
73
foreach (string detail in (item as ContactItem).Details) {
74
if (detail.StartsWith ("email"))
77
} else if (item is IContactDetailItem) {
78
return (item as IContactDetailItem).Key.StartsWith ("email");
79
} else if (item is ITextItem) {
81
// Regex should conform to RFC2822.
82
@"[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])?"
83
).IsMatch ((item as ITextItem).Text);
88
public override IEnumerable<IItem> Perform (IEnumerable<IItem> items, IEnumerable<IItem> modItems)
90
string emails, email, body;
92
emails = email = string.Empty;
93
foreach (IItem item in items) {
94
if (item is ContactItem) {
95
ContactItem contact = item as ContactItem;
96
email = contact ["email"];
99
foreach (string detail in contact.Details) {
100
if (detail.StartsWith ("email")) {
101
email = contact [detail];
106
} else if (item is IContactDetailItem) {
107
email = (item as IContactDetailItem).Value;
108
} else if (item is ITextItem) {
109
email = (item as ITextItem).Text;
111
emails += email + ",";
115
if (modItems.Any ()) {
116
body = "?body=" + (modItems.First () as ITextItem).Text
117
.Replace ("\"", "\\\""); // Try to escape quotes...
119
Util.Environment.Open ("\"mailto:" + emails + body + "\"");