xref: /haiku/src/add-ons/mail_daemon/inbound_protocols/imap/Settings.cpp (revision 1deede7388b04dbeec5af85cae7164735ea9e70d)
1 /*
2  * Copyright 2011-2013, Axel Dörfler, axeld@pinc-software.de.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include "Settings.h"
8 
9 #include <crypt.h>
10 
11 
12 Settings::Settings(const char* accountName, const BMessage& archive)
13 	:
14 	fMessage(archive),
15 	fAccountName(accountName)
16 {
17 }
18 
19 
20 Settings::~Settings()
21 {
22 }
23 
24 
25 BNetworkAddress
26 Settings::ServerAddress() const
27 {
28 	return BNetworkAddress(Server(), Port());
29 }
30 
31 
32 BString
33 Settings::Server() const
34 {
35 	return fMessage.GetString("server", "");
36 }
37 
38 
39 uint16
40 Settings::Port() const
41 {
42 	int32 port;
43 	if (fMessage.FindInt32("port", &port) == B_OK)
44 		return port;
45 
46 	return UseSSL() ? 993 : 143;
47 }
48 
49 
50 bool
51 Settings::UseSSL() const
52 {
53 	return fMessage.GetInt32("flavor", 1) == 1;
54 }
55 
56 
57 BString
58 Settings::Username() const
59 {
60 	return fMessage.GetString("username", "");
61 }
62 
63 
64 BString
65 Settings::Password() const
66 {
67 	BString password;
68 	char* passwd = get_passwd(&fMessage, "cpasswd");
69 	if (passwd != NULL) {
70 		password = passwd;
71 		delete[] passwd;
72 		return password;
73 	}
74 
75 	return "";
76 }
77 
78 
79 BPath
80 Settings::Destination() const
81 {
82 	BPath path(fMessage.FindString("destination"));
83 	if (path.Path() == NULL) {
84 		// Use default directory
85 		path = "/boot/home/mail";
86 		path.Append(fAccountName.String());
87 	}
88 	return path;
89 }
90 
91 
92 int32
93 Settings::MaxConnections() const
94 {
95 	return fMessage.GetInt32("max connections", 1);
96 }
97 
98 
99 bool
100 Settings::IdleMode() const
101 {
102 	return fMessage.GetBool("idle", true);
103 }
104 
105 
106 int32
107 Settings::BodyFetchLimit() const
108 {
109 	return fMessage.GetInt32("partial_download_limit", -1);
110 }
111 
112 bool
113 Settings::DeleteRemoteWhenLocal() const
114 {
115 	return fMessage.FindBool("delete_remote_when_local");
116 }
117