6 Copyright (c) 1991-2001, Be Incorporated. All rights reserved.
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in 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 TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN
23 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
29 BeMail(TM), Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or
30 registered trademarks of Be Incorporated in the United States and other
31 countries. Other brand product names are registered trademarks or trademarks
32 of their respective holders. All rights reserved.
38 #include <Application.h>
41 #include <CharacterSet.h>
42 #include <CharacterSetRoster.h>
43 #include <Directory.h>
46 #include <FindDirectory.h>
49 #include <MailSettings.h>
54 #include <mail_encoding.h>
57 #define B_TRANSLATION_CONTEXT "Settings"
60 using namespace BPrivate
;
65 fMailWindowFrame(BRect(0, 0, 200, 400)),
71 fAttachAttributes(true),
73 fShowButtonBar(kShowToolBar
),
74 fWarnAboutUnencodableCharacters(true),
75 fStartWithSpellCheckOn(false),
79 fMailCharacterSet(B_MS_WINDOWS_CONVERSION
),
80 fContentFont(be_fixed_font
)
82 fSignature
= B_TRANSLATE("None");
86 fContentFont
.SetSpacing(B_BITMAP_SPACING
);
88 _CheckForSpamFilterExistence();
98 Settings::SetPrintSettings(const BMessage
* printSettings
)
100 BAutolock
lock(be_app
);
102 if (printSettings
== fPrintSettings
)
105 delete fPrintSettings
;
107 fPrintSettings
= new BMessage(*printSettings
);
109 fPrintSettings
= NULL
;
114 Settings::HasPrintSettings()
116 BAutolock
lock(be_app
);
117 return fPrintSettings
!= NULL
;
122 Settings::PrintSettings()
124 BAutolock
lock(be_app
);
125 return BMessage(*fPrintSettings
);
130 Settings::ClearPrintSettings()
132 delete fPrintSettings
;
133 fPrintSettings
= NULL
;
138 Settings::SetWindowFrame(BRect frame
)
140 BAutolock
lock(be_app
);
141 fMailWindowFrame
= frame
;
146 Settings::WindowFrame()
148 BAutolock
lock(be_app
);
149 return fMailWindowFrame
;
154 Settings::_GetSettingsPath(BPath
&path
)
156 status_t status
= find_directory(B_USER_SETTINGS_DIRECTORY
, &path
);
161 return create_directory(path
.Path(), 0755);
166 Settings::SaveSettings()
168 BMailSettings chainSettings
;
170 if (fDefaultChain
!= ~0UL) {
171 chainSettings
.SetDefaultOutboundChainID(fDefaultChain
);
172 chainSettings
.Save();
176 status_t status
= _GetSettingsPath(path
);
180 path
.Append("Mail Settings~");
183 status
= file
.SetTo(path
.Path(),
184 B_READ_WRITE
| B_CREATE_FILE
| B_ERASE_FILE
);
189 BMessage
settings('BeMl');
190 settings
.AddRect("MailWindowSize", fMailWindowFrame
);
192 font_family fontFamily
;
193 font_style fontStyle
;
194 fContentFont
.GetFamilyAndStyle(&fontFamily
, &fontStyle
);
196 settings
.AddString("FontFamily", fontFamily
);
197 settings
.AddString("FontStyle", fontStyle
);
198 settings
.AddFloat("FontSize", fContentFont
.Size());
200 settings
.AddBool("WordWrapMode", fWrapMode
);
201 settings
.AddBool("AutoMarkRead", fAutoMarkRead
);
202 settings
.AddString("SignatureText", fSignature
);
203 settings
.AddInt32("CharacterSet", fMailCharacterSet
);
204 settings
.AddInt8("ShowButtonBar", fShowButtonBar
);
205 settings
.AddInt32("UseAccountFrom", fUseAccountFrom
);
206 settings
.AddBool("ColoredQuotes", fColoredQuotes
);
207 settings
.AddString("ReplyPreamble", fReplyPreamble
);
208 settings
.AddBool("AttachAttributes", fAttachAttributes
);
209 settings
.AddBool("WarnAboutUnencodableCharacters",
210 fWarnAboutUnencodableCharacters
);
211 settings
.AddBool("StartWithSpellCheck", fStartWithSpellCheckOn
);
214 status
= entry
.SetTo(path
.Path());
218 status
= settings
.Flatten(&file
);
219 if (status
== B_OK
) {
220 // replace original settings file
221 status
= entry
.Rename("Mail Settings", true);
230 Settings::LoadSettings()
232 BMailSettings chainSettings
;
233 fDefaultChain
= chainSettings
.DefaultOutboundChainID();
236 status_t status
= _GetSettingsPath(path
);
240 path
.Append("Mail Settings");
243 status
= file
.SetTo(path
.Path(), B_READ_ONLY
);
244 if (status
!= B_OK
) {
245 _GetSettingsPath(path
);
246 path
.Append("BeMail Settings");
247 status
= file
.SetTo(path
.Path(), B_READ_ONLY
);
253 status
= settings
.Unflatten(&file
);
254 if (status
< B_OK
|| settings
.what
!= 'BeMl')
258 if (settings
.FindRect("MailWindowSize", &rect
) == B_OK
)
259 fMailWindowFrame
= rect
;
263 const char *fontFamily
;
264 if (settings
.FindString("FontFamily", &fontFamily
) == B_OK
) {
265 const char *fontStyle
;
266 if (settings
.FindString("FontStyle", &fontStyle
) == B_OK
) {
268 if (settings
.FindFloat("FontSize", &size
) == B_OK
) {
270 fContentFont
.SetSize(size
);
272 if (fontFamily
[0] && fontStyle
[0]) {
273 fContentFont
.SetFamilyAndStyle(
274 fontFamily
[0] ? fontFamily
: NULL
,
275 fontStyle
[0] ? fontStyle
: NULL
);
281 fWrapMode
= settings
.GetBool("WordWrapMode", fWrapMode
);
282 fAutoMarkRead
= settings
.GetBool("AutoMarkRead", fAutoMarkRead
);
285 if (settings
.FindString("SignatureText", &string
) == B_OK
)
288 if (settings
.FindInt32("CharacterSet", &int32Value
) == B_OK
)
289 fMailCharacterSet
= int32Value
;
290 if (fMailCharacterSet
!= B_MAIL_UTF8_CONVERSION
291 && fMailCharacterSet
!= B_MAIL_US_ASCII_CONVERSION
292 && BCharacterSetRoster::GetCharacterSetByConversionID(fMailCharacterSet
)
294 fMailCharacterSet
= B_MS_WINDOWS_CONVERSION
;
297 fShowButtonBar
= settings
.GetInt8("ShowButtonBar", fShowButtonBar
);
299 if (settings
.FindInt32("UseAccountFrom", &int32Value
) == B_OK
)
300 fUseAccountFrom
= int32Value
;
301 if (fUseAccountFrom
< ACCOUNT_USE_DEFAULT
302 || fUseAccountFrom
> ACCOUNT_FROM_MAIL
)
303 fUseAccountFrom
= ACCOUNT_USE_DEFAULT
;
305 fColoredQuotes
= settings
.GetBool("ColoredQuotes", fColoredQuotes
);
307 if (settings
.FindString("ReplyPreamble", &string
) == B_OK
)
308 fReplyPreamble
= string
;
310 fAttachAttributes
= settings
.GetBool("AttachAttributes", fAttachAttributes
);
311 fWarnAboutUnencodableCharacters
= settings
.GetBool(
312 "WarnAboutUnencodableCharacters", fWarnAboutUnencodableCharacters
);
313 fStartWithSpellCheckOn
= settings
.GetBool("StartWithSpellCheck",
314 fStartWithSpellCheckOn
);
321 Settings::AutoMarkRead()
323 BAutolock
lock(be_app
);
324 return fAutoMarkRead
;
329 Settings::Signature()
331 BAutolock
lock(be_app
);
332 return BString(fSignature
);
337 Settings::ReplyPreamble()
339 BAutolock
lock(be_app
);
340 return BString(fReplyPreamble
);
347 BAutolock
lock(be_app
);
353 Settings::AttachAttributes()
355 BAutolock
lock(be_app
);
356 return fAttachAttributes
;
361 Settings::ColoredQuotes()
363 BAutolock
lock(be_app
);
364 return fColoredQuotes
;
369 Settings::ShowButtonBar()
371 BAutolock
lock(be_app
);
372 return fShowButtonBar
;
377 Settings::WarnAboutUnencodableCharacters()
379 BAutolock
lock(be_app
);
380 return fWarnAboutUnencodableCharacters
;
385 Settings::StartWithSpellCheckOn()
387 BAutolock
lock(be_app
);
388 return fStartWithSpellCheckOn
;
393 Settings::SetDefaultChain(uint32 chain
)
395 BAutolock
lock(be_app
);
396 fDefaultChain
= chain
;
401 Settings::DefaultChain()
403 BAutolock
lock(be_app
);
404 return fDefaultChain
;
409 Settings::UseAccountFrom()
411 BAutolock
lock(be_app
);
412 return fUseAccountFrom
;
417 Settings::MailCharacterSet()
419 BAutolock
lock(be_app
);
420 return fMailCharacterSet
;
425 Settings::ContentFont()
427 BAutolock
lock(be_app
);
433 Settings::_CheckForSpamFilterExistence()
435 int32 addonNameIndex
;
436 const char* addonNamePntr
;
437 BDirectory inChainDir
;
439 BEntry settingsEntry
;
441 BMessage settingsMessage
;
443 fShowSpamGUI
= false;
445 if (find_directory(B_USER_SETTINGS_DIRECTORY
, &path
) != B_OK
)
447 path
.Append("Mail/chains/inbound");
448 if (inChainDir
.SetTo(path
.Path()) != B_OK
)
451 while (inChainDir
.GetNextEntry (&settingsEntry
, true) == B_OK
) {
452 if (!settingsEntry
.IsFile())
454 if (settingsFile
.SetTo (&settingsEntry
, B_READ_ONLY
) != B_OK
)
456 if (settingsMessage
.Unflatten (&settingsFile
) != B_OK
)
458 for (addonNameIndex
= 0;
459 B_OK
== settingsMessage
.FindString("filter_addons",
460 addonNameIndex
, &addonNamePntr
);
462 if (strstr(addonNamePntr
, "Spam Filter") != NULL
) {