-fpermissive to allow GCC to compile old C++
[oweals/cde.git] / cde / programs / dtmail / dtmail / MailRcSource.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $TOG: MailRcSource.C /main/13 1999/03/25 13:41:38 mgreess $ */
24 /*
25  *+SNOTICE
26  *
27  *      RESTRICTED CONFIDENTIAL INFORMATION:
28  *      
29  *      The information in this document is subject to special
30  *      restrictions in a confidential disclosure agreement bertween
31  *      HP, IBM, Sun, USL, SCO and Univel.  Do not distribute this
32  *      document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
33  *      Sun's specific written approval.  This documment and all copies
34  *      and derivative works thereof must be returned or destroyed at
35  *      Sun's request.
36  *
37  *      Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
38  *
39  *+ENOTICE
40  */
41
42 #include <EUSCompat.h>
43 #include <DtMail/PropSource.hh>
44 #include <DtMail/DtMailTypes.h>
45 #include <DtMail/DtVirtArray.hh>
46 #include "str_utils.h"
47
48 #include "DmxPrintOptions.h"
49
50 static PropDefaults static_defaults[] ={
51 { "retrieveinterval",           "300" },
52 { "bell",                       "1" },
53 { "flash",                      "0" },
54 { "headerlines",                "15" },
55 { "showto",                     "f"  },
56 { "showmsgnum",                 "f"  },
57 { "popuplines",                 "24" },
58 { "toolcols",                   "80" },
59 { "indentprefix",               ">" },
60 { "hideattachments",            "f" },
61 { "folder",                     "~" },
62 { "filefolder",                 "~" },
63 { "dontunifyselection",         "f" },
64 { "dontunifyfileselection",     "f" },
65 { "confirmattachments",         "f" },
66 { "confirmattachmentthreshold", "64" },
67 { "cachedfilemenusize",         "10" },
68 { "dontdisplaycachedfiles",     "f" },
69 { "record",                     "" },
70 { "dontlogmessages",            "f" },
71 { "keepdeleted",                "f"  },
72 { "quietdelete",                "f"  },
73 { "expert",                     "f"   },
74 { "strictmime",                 "f"  },
75 { "cdetooltalklock",            "f"  },
76 { "allnet",                     "f"  },
77 { "metoo",                      "f"  },
78 { "usealternates",              "f"  },
79 { "deaddir",                    "~/dead_letter"  },
80 { "saveinterval",               "30" },
81 { DMX_PROPKEY_HEADER_LEFT,      DMX_PROPVAL_SUBJECT_HEADER },
82 { DMX_PROPKEY_HEADER_RIGHT,     DMX_PROPVAL_EMPTY },
83 { DMX_PROPKEY_FOOTER_LEFT,      DMX_PROPVAL_USER_NAME },
84 { DMX_PROPKEY_FOOTER_RIGHT,     DMX_PROPVAL_PAGE_NUMBER },
85 { DMX_PROPKEY_MARGIN_TOP,       DMX_PROPVAL_DFLT_MARGIN },
86 { DMX_PROPKEY_MARGIN_RIGHT,     DMX_PROPVAL_DFLT_MARGIN },
87 { DMX_PROPKEY_MARGIN_BOTTOM,    DMX_PROPVAL_DFLT_MARGIN },
88 { DMX_PROPKEY_MARGIN_LEFT,      DMX_PROPVAL_DFLT_MARGIN },
89 { DMX_PROPKEY_PRINT_HEADERS,    DMX_PROPVAL_STANDARD },
90 { DMX_PROPKEY_MESSAGE_SEPARATOR,DMX_PROPVAL_PAGE_BREAK },
91 { DMX_PROPKEY_SEPARATOR_STRING, "-" },
92 { NULL,                         NULL }
93 };
94
95 DtVirtArray<PropDefaults*> *PropSource::_dynamic_defaults =
96         new DtVirtArray<PropDefaults*> (20);
97
98 PropSource::PropSource(DtMail::MailRc *m_rc,  char *key)
99 {
100     _mail_rc = m_rc;
101     _key = key;
102 }
103
104 PropSource::~PropSource() {;}
105
106 void
107 PropSource::setDefaultValue(char *key, char *value)
108 {
109     PropDefaults *df;
110
111     for (int i=0; i<_dynamic_defaults->length(); i++)
112     {
113         df = (PropDefaults*) (*_dynamic_defaults)[i];
114         if (0 == strcmp(key, df->key))
115         {
116             if (NULL != df->value) free((void*) df->value);
117             df->value = strdup(value);
118             return;
119         }
120     }
121
122     df = (PropDefaults*) malloc(sizeof(PropDefaults));
123     df->key = strdup(key);
124     df->value = strdup(value);
125     _dynamic_defaults->append(df);
126 }
127
128 const char *
129 PropSource::getDefaultValue(void)
130 {
131     PropDefaults *df;
132
133     for (int i=0; i<_dynamic_defaults->length(); i++)
134     {
135         df = (PropDefaults*) (*_dynamic_defaults)[i];
136         if (0 == strcmp(_key, df->key)) return strdup(df->value);
137     }
138
139     for (df=static_defaults; df->key; df++)
140       if (strcasecmp(_key, df->key) == 0) return strdup(df->value);
141
142     return strdup(PropSourceDEFAULTVALUE);
143 }
144
145 // MailRcSource::getValue
146 // gets the value from the mailrc hash table and returns it
147 /////////////////////////////////////////////////////////////////
148 const char *MailRcSource::getValue(DtMailBoolean decrypt)
149 {
150   const char *value = NULL;
151   DtMailEnv error;
152
153   _mail_rc->getValue(error, _key , &value, decrypt);
154
155   if (value == NULL || error.isSet())
156   {
157       value = getDefaultValue();
158       return value;
159   }
160   
161   return value;
162 }
163
164 // MailRcSource::setValue
165 // Sets the passed value into the mailrc hash tables
166 /////////////////////////////////////////////////////////////////
167 void MailRcSource::setValue(char *value, DtMailBoolean encrypt)
168 {
169   DtMailEnv error;
170
171   const char * d_value = getDefaultValue();
172
173   if (strcmp(d_value, value))
174     _mail_rc->setValue(error, _key , value, encrypt);
175   else
176     _mail_rc->removeValue(error, _key);
177 }