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 12Settings::Settings(const char* accountName, const BMessage& archive) 13 : 14 fMessage(archive), 15 fAccountName(accountName) 16{ 17} 18 19 20Settings::~Settings() 21{ 22} 23 24 25BNetworkAddress 26Settings::ServerAddress() const 27{ 28 return BNetworkAddress(Server(), Port()); 29} 30 31 32BString 33Settings::Server() const 34{ 35 return fMessage.GetString("server", ""); 36} 37 38 39uint16 40Settings::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 50bool 51Settings::UseSSL() const 52{ 53 return fMessage.GetInt32("flavor", 1) == 1; 54} 55 56 57BString 58Settings::Username() const 59{ 60 return fMessage.GetString("username", ""); 61} 62 63 64BString 65Settings::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 79BPath 80Settings::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 92int32 93Settings::MaxConnections() const 94{ 95 return fMessage.GetInt32("max connections", 1); 96} 97 98 99bool 100Settings::IdleMode() const 101{ 102 return fMessage.GetBool("idle", true); 103} 104 105 106int32 107Settings::BodyFetchLimit() const 108{ 109 return fMessage.GetInt32("partial_download_limit", -1); 110} 111 112bool 113Settings::DeleteRemoteWhenLocal() const 114{ 115 return fMessage.FindBool("delete_remote_when_local"); 116} 117