NoiseFilter: Dont drop last word of apparent hostnames. Too many non-hostnames can...
[beagle.git] / Filters / FilterKAddressBook.cs
blobcdb0947ce12f1d079dde25fdee1142101964e2b4
1 //
2 // FilterKAddressBook.cs
3 //
4 // Copyright (C) 2006 Debajyoti Bera <dbera.web@gmail.com>
5 //
7 //
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;
29 using System.Collections;
30 using System.IO;
31 using System.Text;
33 using Beagle.Daemon;
34 using Beagle.Util;
36 namespace Beagle.Filters {
38 public class FilterKAddressBook : Beagle.Filters.FilterKCal {
40 public FilterKAddressBook ()
42 AddSupportedFlavor (FilterFlavor.NewFromMimeType (ICalParser.KabcMimeType));
43 SnippetMode = false;
44 if (vCard_property_mapping == null)
45 SetupPropertyMapping ();
48 private static Hashtable vCard_property_mapping = null;
49 override protected Hashtable KCalPropertyMapping {
50 get { return vCard_property_mapping; }
53 private void SetupPropertyMapping () {
54 vCard_property_mapping = new Hashtable ();
55 // KCalProperty (name, comma_sep, keyword, text_or_date)
56 vCard_property_mapping ["FN"] = new KCalProperty ("vCard:FN", false, false, KCalType.Text);
57 vCard_property_mapping ["NICKNAME"] = new KCalProperty ("vCard:NICKNAME", true, false,KCalType.Text);
58 vCard_property_mapping ["BDAY"] = new KCalProperty ("vCard:BDAY", true, false, KCalType.Date);
59 vCard_property_mapping ["TITLE"] = new KCalProperty ("vCard:TITLE", false, false, KCalType.Text);
60 vCard_property_mapping ["ROLE"] = new KCalProperty ("vCard:ROLE", false, false, KCalType.Text);
61 vCard_property_mapping ["CATEGORIES"] = new KCalProperty ("vCard:CATEGORIES", false, false, KCalType.Text);
62 vCard_property_mapping ["NAME"] = new KCalProperty ("vCard:NAME", false, false, KCalType.Text);
63 vCard_property_mapping ["NOTE"] = new KCalProperty ("vCard:NOTE", false, false, KCalType.Text);
64 vCard_property_mapping ["REV"] = new KCalProperty ("dc:date", true, false, KCalType.Date);
65 vCard_property_mapping ["CLASS"] = new KCalProperty ("vCard:CLASS", false, true, KCalType.Text);
66 vCard_property_mapping ["UID"] = new KCalProperty ("vCard:UID", false, true, KCalType.Text);
67 vCard_property_mapping ["EMAIL"] = new KCalProperty ("vCard:EMAIL", false, true, KCalType.Special);
68 vCard_property_mapping ["TEL"] = new KCalProperty ("vCard:TEL", false, true, KCalType.Text);
69 vCard_property_mapping ["URL"] = new KCalProperty ("vCard:URL", false, true,KCalType.Text);
72 override protected string GetPropertyName (string prop_name, ArrayList paramlist)
74 string mapped_prop_name =
75 ((KCalProperty)vCard_property_mapping [prop_name]).property_name;
77 switch (prop_name) {
78 case "TEL":
79 foreach (KCalPropertyParameter vcpp in paramlist) {
80 if (vcpp.param_name == "TYPE") {
81 if (vcpp.param_value == "WORK")
82 return mapped_prop_name + ":WORK";
83 else if (vcpp.param_value == "HOME")
84 return mapped_prop_name + ":HOME";
87 break;
90 return mapped_prop_name;
93 override protected void ProcessPropertySpecial (string prop_name,
94 ArrayList paramlist,
95 string prop_value)
97 if (prop_name == "EMAIL") {
98 foreach (KCalPropertyParameter vcpp in paramlist) {
99 if (vcpp.param_name == "TYPE" &&
100 vcpp.param_value == "PREF")
101 // Default email
102 AddProperty (Beagle.Property.NewKeyword (
103 "vCard:PREFEMAIL",
104 prop_value));
106 AddProperty (Beagle.Property.NewKeyword ("vCard:EMAIL", prop_value));