Skip to content

Commit

Permalink
BMailAccountSettings: use BPathFinder.
Browse files Browse the repository at this point in the history
* This allows to put add-ons in non-packaged folders, too.
* Also, Set{In|Out}boundAddOn() only ever looked in the system dir.
  • Loading branch information
axeld committed Nov 7, 2015
1 parent 617793f commit d8c0222
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 30 deletions.
2 changes: 2 additions & 0 deletions headers/os/mail/MailSettings.h
Expand Up @@ -171,6 +171,8 @@ class BMailAccountSettings {

private:
status_t _CreateAccountFilePath();
status_t _GetAddOnRef(const char* subPath,
const char* name, entry_ref& ref);

private:
status_t fStatus;
Expand Down
69 changes: 39 additions & 30 deletions src/kits/mail/MailSettings.cpp
Expand Up @@ -23,6 +23,7 @@
#include <Message.h>
#include <Messenger.h>
#include <Path.h>
#include <PathFinder.h>
#include <String.h>
#include <Window.h>

Expand Down Expand Up @@ -431,23 +432,24 @@ BMailAddOnSettings::Load(const BMessage& message)
return B_BAD_VALUE;

BPath path(pathString);
if (!path.IsAbsolute()) {
directory_which which[] = {
B_USER_ADDONS_DIRECTORY,
B_SYSTEM_ADDONS_DIRECTORY
};

for (size_t i = 0; i < sizeof(which) / sizeof(which[0]); i++) {
status_t status = find_directory(which[i], &path);
if (status != B_OK)
continue;
if (!path.IsAbsolute()) {
BStringList paths;
BPathFinder().FindPaths(B_FIND_PATH_ADD_ONS_DIRECTORY, "mail_daemon",
paths);

path.Append("mail_daemon");
path.Append(pathString);
status_t status = B_ENTRY_NOT_FOUND;

if (BEntry(path.Path()).Exists())
for (int32 i = 0; i < paths.CountStrings(); i++) {
path.SetTo(paths.StringAt(i), pathString);
BEntry entry(path.Path());
if (entry.Exists()) {
status = B_OK;
break;
}
}
if (status != B_OK)
return status;
}

status_t status = get_ref_for_path(path.Path(), &fRef);
Expand Down Expand Up @@ -737,35 +739,23 @@ BMailAccountSettings::ReturnAddress() const
bool
BMailAccountSettings::SetInboundAddOn(const char* name)
{
BPath path;
status_t status = find_directory(B_BEOS_ADDONS_DIRECTORY, &path);
if (status != B_OK)
return false;
path.Append("mail_daemon");
path.Append("inbound_protocols");
path.Append(name);
entry_ref ref;
get_ref_for_path(path.Path(), &ref);
fInboundSettings.SetAddOnRef(ref);
if (_GetAddOnRef("mail_daemon/inbound_protocols", name, ref) != B_OK)
return false;

fInboundSettings.SetAddOnRef(ref);
return true;
}


bool
BMailAccountSettings::SetOutboundAddOn(const char* name)
{
BPath path;
status_t status = find_directory(B_BEOS_ADDONS_DIRECTORY, &path);
if (status != B_OK)
return false;
path.Append("mail_daemon");
path.Append("outbound_protocols");
path.Append(name);
entry_ref ref;
get_ref_for_path(path.Path(), &ref);
fOutboundSettings.SetAddOnRef(ref);
if (_GetAddOnRef("mail_daemon/outbound_protocols", name, ref) != B_OK)
return false;

fOutboundSettings.SetAddOnRef(ref);
return true;
}

Expand Down Expand Up @@ -980,3 +970,22 @@ BMailAccountSettings::_CreateAccountFilePath()
path.Append(fileName);
return fAccountFile.SetTo(path.Path());
}


status_t
BMailAccountSettings::_GetAddOnRef(const char* subPath, const char* name,
entry_ref& ref)
{
BStringList paths;
BPathFinder().FindPaths(B_FIND_PATH_ADD_ONS_DIRECTORY, subPath, paths);

for (int32 i = 0; i < paths.CountStrings(); i++) {
BPath path(paths.StringAt(i), name);
BEntry entry(path.Path());
if (entry.Exists()) {
if (entry.GetRef(&ref) == B_OK)
return B_OK;
}
}
return B_ENTRY_NOT_FOUND;
}

0 comments on commit d8c0222

Please sign in to comment.