From 21c22141b824642aa223699f976711e4b9f53cb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sun, 19 Jun 2011 22:11:04 +0000 Subject: [PATCH] * Removed default_sent_directory(), and introduced default_mail{_in|_out}_directory() methods in the BPrivate namespace. * Used these methods in the inbound/outbound protocols. * Moved WriteMessageFile() into the BPrivate namespace as well, and put its prototype into a new header MailPrivate.h along with the new directory getters. * Removed the automatic copy to the sent directory again, and only have one directory for incoming mail. Incidentally, this fixed #7509, although the underlying filter restriction remains. * Automatic whitespace cleanups, some style cleanups. Sorry for the mess. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42260 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/mail/MailSettings.h | 24 +++-- headers/private/mail/MailPrivate.h | 25 ++++++ .../inbound_protocols/imap/imap_config.cpp | 23 ++--- .../inbound_protocols/pop3/ConfigView.cpp | 3 +- .../outbound_protocols/smtp/ConfigView.cpp | 34 ++++---- src/kits/mail/HaikuMailFormatFilter.cpp | 28 +++--- src/kits/mail/HaikuMailFormatFilter.h | 3 +- src/kits/mail/MailSettings.cpp | 48 ++++------ src/kits/mail/numailkit.cpp | 87 +++++++++++++------ 9 files changed, 154 insertions(+), 121 deletions(-) create mode 100644 headers/private/mail/MailPrivate.h diff --git a/headers/os/mail/MailSettings.h b/headers/os/mail/MailSettings.h index c6816ad2a1..1d04a03144 100644 --- a/headers/os/mail/MailSettings.h +++ b/headers/os/mail/MailSettings.h @@ -20,8 +20,7 @@ class BPath; -typedef enum -{ +typedef enum { B_MAIL_SHOW_STATUS_WINDOW_NEVER = 0, B_MAIL_SHOW_STATUS_WINDOW_WHEN_SENDING = 1, B_MAIL_SHOW_STATUS_WINDOW_WHEN_ACTIVE = 2, @@ -29,8 +28,7 @@ typedef enum } b_mail_status_window_option; -typedef enum -{ +typedef enum { B_MAIL_STATUS_LOOK_TITLED = 0, B_MAIL_STATUS_LOOK_NORMAL_BORDER = 1, B_MAIL_STATUS_LOOK_FLOATING = 2, @@ -39,9 +37,6 @@ typedef enum } b_mail_status_window_look; -BString default_sent_directory(); - - class BMailSettings { public: BMailSettings(); @@ -57,7 +52,7 @@ public: uint32 ShowStatusWindow(); void SetShowStatusWindow(uint32 mode); - + bool DaemonAutoStarts(); void SetDaemonAutoStarts(bool does_it); @@ -91,8 +86,7 @@ private: }; -class AddonSettings -{ +class AddonSettings { public: AddonSettings(); @@ -106,6 +100,7 @@ public: BMessage& EditSettings(); bool HasBeenModified(); + private: BMessage fSettings; entry_ref fAddonRef; @@ -114,8 +109,7 @@ private: }; -class MailAddonSettings : public AddonSettings -{ +class MailAddonSettings : public AddonSettings { public: bool Load(const BMessage& message); bool Save(BMessage& message); @@ -127,13 +121,13 @@ public: AddonSettings* FilterSettingsAt(int32 index); bool HasBeenModified(); + private: std::vector fFiltersSettings; }; -class BMailAccountSettings -{ +class BMailAccountSettings { public: BMailAccountSettings(); BMailAccountSettings(BEntry account); @@ -176,9 +170,11 @@ class BMailAccountSettings bool HasBeenModified(); const BEntry& AccountFile(); + private: status_t _CreateAccountFilePath(); +private: status_t fStatus; BEntry fAccountFile; diff --git a/headers/private/mail/MailPrivate.h b/headers/private/mail/MailPrivate.h new file mode 100644 index 0000000000..74b8afaeba --- /dev/null +++ b/headers/private/mail/MailPrivate.h @@ -0,0 +1,25 @@ +/* + * Copyright 2011, Haiku Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef MAIL_PRIVATE_H +#define MAIL_PRIVATE_H + + +#include +#include + + +namespace BPrivate { + +BPath default_mail_directory(); +BPath default_mail_in_directory(); +BPath default_mail_out_directory(); + +status_t WriteMessageFile(const BMessage& archive, const BPath& path, + const char* name); + +} // namespace BPrivate + + +#endif // MAIL_PRIVATE_H diff --git a/src/add-ons/mail_daemon/inbound_protocols/imap/imap_config.cpp b/src/add-ons/mail_daemon/inbound_protocols/imap/imap_config.cpp index 95f0539ef7..5760cd67ed 100644 --- a/src/add-ons/mail_daemon/inbound_protocols/imap/imap_config.cpp +++ b/src/add-ons/mail_daemon/inbound_protocols/imap/imap_config.cpp @@ -10,13 +10,14 @@ #include #include -#include -#include -#include -#include #include +#include +#include +#include +#include #include + #include "IMAPFolderConfig.h" @@ -52,12 +53,11 @@ IMAPConfig::IMAPConfig(MailAddonSettings& settings, | B_MAIL_PROTOCOL_HAS_FLAVORS #endif ), - fAddonSettings(settings) { #ifdef USE_SSL - AddFlavor("No encryption"); - AddFlavor("SSL"); + AddFlavor("No encryption"); + AddFlavor("SSL"); #endif SetTo(settings); @@ -70,18 +70,13 @@ IMAPConfig::IMAPConfig(MailAddonSettings& settings, ((BControl *)(FindView("delete_remote_when_local")))->SetEnabled(true); ((BControl *)(FindView("delete_remote_when_local")))->MoveBy(0, -25); - fIMAPFolderButton = new BButton(frame, "IMAP Folders", "IMAP Folders", new BMessage(kMsgOpenIMAPFolder)); AddChild(fIMAPFolderButton); frame.right -= 10; - BPath defaultFolder; - if (find_directory(B_USER_DIRECTORY, &defaultFolder) == B_OK) - defaultFolder.Append("mail"); - else - defaultFolder.SetTo("/boot/home/mail/"); + BPath defaultFolder = BPrivate::default_mail_directory(); defaultFolder.Append(accountSettings.Name()); fFileView = new BMailFileConfigView("Destination:", "destination", @@ -131,7 +126,7 @@ IMAPConfig::MessageReceived(BMessage* message) } default: - BMailProtocolConfigView::MessageReceived(message); + BMailProtocolConfigView::MessageReceived(message); } } diff --git a/src/add-ons/mail_daemon/inbound_protocols/pop3/ConfigView.cpp b/src/add-ons/mail_daemon/inbound_protocols/pop3/ConfigView.cpp index 445b811cad..319e18ed31 100644 --- a/src/add-ons/mail_daemon/inbound_protocols/pop3/ConfigView.cpp +++ b/src/add-ons/mail_daemon/inbound_protocols/pop3/ConfigView.cpp @@ -9,6 +9,7 @@ #include #include +#include #include @@ -47,7 +48,7 @@ POP3ConfigView::POP3ConfigView(MailAddonSettings& settings, SetTo(settings); fFileView = new BMailFileConfigView("Destination:", "destination", - false, "/boot/home/mail/in"); + false, BPrivate::default_mail_in_directory().Path()); fFileView->SetTo(&settings.Settings(), NULL); AddChild(fFileView); float w, h; diff --git a/src/add-ons/mail_daemon/outbound_protocols/smtp/ConfigView.cpp b/src/add-ons/mail_daemon/outbound_protocols/smtp/ConfigView.cpp index 05766a2a8c..a24a145520 100644 --- a/src/add-ons/mail_daemon/outbound_protocols/smtp/ConfigView.cpp +++ b/src/add-ons/mail_daemon/outbound_protocols/smtp/ConfigView.cpp @@ -10,9 +10,10 @@ #include #include -#include #include +#include #include +#include #include @@ -23,45 +24,42 @@ public: status_t Archive(BMessage *into, bool deep = true) const; void GetPreferredSize(float *width, float *height); private: - BMailFileConfigView* fFileView; + BMailFileConfigView* fFileView; }; SMTPConfigView::SMTPConfigView(MailAddonSettings& settings, BMailAccountSettings& accountSettings) : - #ifdef USE_SSL - BMailProtocolConfigView( B_MAIL_PROTOCOL_HAS_AUTH_METHODS - | B_MAIL_PROTOCOL_HAS_USERNAME | B_MAIL_PROTOCOL_HAS_PASSWORD - | B_MAIL_PROTOCOL_HAS_HOSTNAME | B_MAIL_PROTOCOL_HAS_FLAVORS) - #else BMailProtocolConfigView(B_MAIL_PROTOCOL_HAS_AUTH_METHODS | B_MAIL_PROTOCOL_HAS_USERNAME | B_MAIL_PROTOCOL_HAS_PASSWORD - | B_MAIL_PROTOCOL_HAS_HOSTNAME) - #endif + | B_MAIL_PROTOCOL_HAS_HOSTNAME +#ifdef USE_SSL + | B_MAIL_PROTOCOL_HAS_FLAVORS +#endif + ) { - #ifdef USE_SSL +#ifdef USE_SSL AddFlavor("Unencrypted"); AddFlavor("SSL"); AddFlavor("STARTTLS"); - #endif +#endif AddAuthMethod(MDR_DIALECT_CHOICE("None","無し"), false); AddAuthMethod(MDR_DIALECT_CHOICE("ESMTP","ESMTP")); - AddAuthMethod(MDR_DIALECT_CHOICE("POP3 before SMTP","送信前に受信する"), - false); + AddAuthMethod(MDR_DIALECT_CHOICE("POP3 before SMTP","送信前に受信する"), false); BTextControl *control = (BTextControl *)(FindView("host")); control->SetLabel(MDR_DIALECT_CHOICE("SMTP server: ","SMTPサーバ: ")); // Reset the dividers after changing one - float widestLabel=0; + float widestLabel = 0; for (int32 i = CountChildren(); i-- > 0;) { - if(BTextControl *text = dynamic_cast(ChildAt(i))) + if (BTextControl *text = dynamic_cast(ChildAt(i))) widestLabel = MAX(widestLabel,text->StringWidth(text->Label()) + 5); } for (int32 i = CountChildren(); i-- > 0;) { - if(BTextControl *text = dynamic_cast(ChildAt(i))) + if (BTextControl *text = dynamic_cast(ChildAt(i))) text->SetDivider(widestLabel); } @@ -70,8 +68,8 @@ SMTPConfigView::SMTPConfigView(MailAddonSettings& settings, SetTo(settings); - fFileView = new BMailFileConfigView("Destination:", "destination", - false, default_sent_directory()); + fFileView = new BMailFileConfigView("Destination:", "path", false, + BPrivate::default_mail_out_directory().Path()); fFileView->SetTo(&settings.Settings(), NULL); AddChild(fFileView); float w, h; diff --git a/src/kits/mail/HaikuMailFormatFilter.cpp b/src/kits/mail/HaikuMailFormatFilter.cpp index 0ff026281d..3462bc00be 100644 --- a/src/kits/mail/HaikuMailFormatFilter.cpp +++ b/src/kits/mail/HaikuMailFormatFilter.cpp @@ -16,8 +16,7 @@ #include -struct mail_header_field -{ +struct mail_header_field { const char *rfc_name; const char *attr_name; @@ -26,8 +25,7 @@ struct mail_header_field }; -static const mail_header_field gDefaultFields[] = -{ +static const mail_header_field gDefaultFields[] = { { "To", B_MAIL_ATTR_TO, B_STRING_TYPE }, { "From", B_MAIL_ATTR_FROM, B_STRING_TYPE }, { "Cc", B_MAIL_ATTR_CC, B_STRING_TYPE }, @@ -53,15 +51,11 @@ HaikuMailFormatFilter::HaikuMailFormatFilter(MailProtocol& protocol, BMailAccountSettings* settings) : MailFilter(protocol, NULL), - - fAccountId(settings->AccountID()), + fAccountID(settings->AccountID()), fAccountName(settings->Name()) { const BMessage* outboundSettings = &settings->OutboundSettings().Settings(); - if (outboundSettings->FindString("destination", &fOutboundDirectory) - != B_OK) { - fOutboundDirectory = default_sent_directory(); - } + outboundSettings->FindString("destination", &fOutboundDirectory); } @@ -72,7 +66,7 @@ HaikuMailFormatFilter::HeaderFetched(const entry_ref& ref, BFile* file) BMessage attributes; // TODO attributes.AddInt32(B_MAIL_ATTR_CONTENT, length); - attributes.AddInt32(B_MAIL_ATTR_ACCOUNT_ID, fAccountId); + attributes.AddInt32(B_MAIL_ATTR_ACCOUNT_ID, fAccountID); attributes.AddString(B_MAIL_ATTR_ACCOUNT, fAccountName); BString header; @@ -198,11 +192,11 @@ HaikuMailFormatFilter::MessageSent(const entry_ref& ref, BFile* file) file->WriteAttr(B_MAIL_ATTR_FLAGS, B_INT32_TYPE, 0, &flags, sizeof(int32)); file->WriteAttr(B_MAIL_ATTR_STATUS, B_STRING_TYPE, 0, "Sent", 5); - if (fOutboundDirectory == "") - return; - create_directory(fOutboundDirectory, 755); - BDirectory dir(fOutboundDirectory); - fMailProtocol.Looper()->TriggerFileMove(ref, dir); + if (!fOutboundDirectory.IsEmpty()) { + create_directory(fOutboundDirectory, 755); + BDirectory dir(fOutboundDirectory); + fMailProtocol.Looper()->TriggerFileMove(ref, dir); + } } @@ -236,7 +230,7 @@ HaikuMailFormatFilter::_ExtractName(const BString& from) name.Remove(0, 1); name.Trim(); } - if (name != "") + if (name != "") return name; // empty name extract email address diff --git a/src/kits/mail/HaikuMailFormatFilter.h b/src/kits/mail/HaikuMailFormatFilter.h index c72ec779a4..7c1b72c5a6 100644 --- a/src/kits/mail/HaikuMailFormatFilter.h +++ b/src/kits/mail/HaikuMailFormatFilter.h @@ -28,7 +28,8 @@ private: const BString& name); BString _ExtractName(const BString& from); - int32 fAccountId; +private: + int32 fAccountID; BString fAccountName; BString fOutboundDirectory; }; diff --git a/src/kits/mail/MailSettings.cpp b/src/kits/mail/MailSettings.cpp index 3d75f67eee..15311bae37 100644 --- a/src/kits/mail/MailSettings.cpp +++ b/src/kits/mail/MailSettings.cpp @@ -1,15 +1,20 @@ /* * Copyright 2001-2003 Dr. Zoidberg Enterprises. All rights reserved. - * Copyright 2004-2009, Haiku Inc. All rights reserved. + * Copyright 2004-2011, Haiku Inc. All rights reserved. * * Distributed under the terms of the MIT License. */ + //! The mail daemon's settings #include +#include +#include +#include + #include #include #include @@ -20,26 +25,7 @@ #include #include -#include -#include -#include - - -namespace MailInternal { - status_t WriteMessageFile(const BMessage& archive, const BPath& path, - const char* name); -} - - -BString -default_sent_directory() -{ - BPath path; - if (find_directory(B_USER_DIRECTORY, &path) != B_OK) - path.SetTo("/boot/home"); - path.Append("mail/sent"); - return path.Path(); -} +#include // #pragma mark - BMailSettings @@ -81,7 +67,8 @@ BMailSettings::Save(bigtime_t /*timeout*/) path.Append("Mail"); - status_t result = MailInternal::WriteMessageFile(fData,path,"new_mail_daemon"); + status_t result = BPrivate::WriteMessageFile(fData, path, + "new_mail_daemon"); if (result < B_OK) return result; @@ -95,7 +82,7 @@ status_t BMailSettings::Reload() { status_t ret; - + BPath path; ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path); if (ret != B_OK) { @@ -103,9 +90,9 @@ BMailSettings::Reload() strerror(ret)); return ret; } - + path.Append("Mail/new_mail_daemon"); - + // open BFile settings(path.Path(),B_READ_ONLY); ret = settings.InitCheck(); @@ -114,7 +101,7 @@ BMailSettings::Reload() path.Path(), strerror(ret)); return ret; } - + // read settings BMessage tmp; ret = tmp.Unflatten(&settings); @@ -205,7 +192,7 @@ BMailSettings::StatusWindowFrame() BRect frame; if (fData.FindRect("StatusWindowFrame", &frame) != B_OK) return BRect(100, 100, 200, 120); - + return frame; } @@ -253,7 +240,7 @@ BMailSettings::SetStatusWindowLook(int32 look) { if (fData.ReplaceInt32("StatusWindowLook",look)) fData.AddInt32("StatusWindowLook",look); - + BMessage msg('lkch'); msg.AddInt32("StatusWindowLook",look); BMessenger("application/x-vnd.Be-POST").SendMessage(&msg); @@ -366,7 +353,6 @@ BMailAccounts::BMailAccounts() creationTimeList.insert(creationTimeList.begin() + insertIndex, creationTime); } - } } @@ -911,7 +897,7 @@ BMailAccountSettings::_CreateAccountFilePath() BString fileName = fAccountName; if (fileName == "") - fileName << fAccountID; + fileName << fAccountID; for (int i = 0; ; i++) { BString testFileName = fileName; if (i != 0) { @@ -923,7 +909,7 @@ BMailAccountSettings::_CreateAccountFilePath() BEntry testEntry(testPath.Path()); if (!testEntry.Exists()) { fileName = testFileName; - break; + break; } } diff --git a/src/kits/mail/numailkit.cpp b/src/kits/mail/numailkit.cpp index 8c21526fcb..cb058d644e 100644 --- a/src/kits/mail/numailkit.cpp +++ b/src/kits/mail/numailkit.cpp @@ -4,36 +4,71 @@ */ -#include -#include -#include -#include -#include -#include -#include -#include +#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + #define timeout 5e5 -namespace MailInternal { -status_t WriteMessageFile(const BMessage& archive, const BPath& path, const char* name); +namespace BPrivate { + +BPath +default_mail_directory() +{ + BPath path; + if (find_directory(B_USER_DIRECTORY, &path) == B_OK) + path.Append("mail"); + else + path.SetTo("/boot/home/mail/"); + + return path; } -status_t MailInternal::WriteMessageFile(const BMessage& archive, const BPath& path, const char* name) +BPath +default_mail_in_directory() +{ + BPath path = default_mail_directory(); + path.Append("in"); + + return path; +} + + +BPath +default_mail_out_directory() +{ + BPath path = default_mail_directory(); + path.Append("out"); + + return path; +} + + +status_t +WriteMessageFile(const BMessage& archive, const BPath& path, const char* name) { status_t ret = B_OK; BString leaf = name; leaf << ".tmp"; - + BEntry settings_entry; BFile tmpfile; bigtime_t now = system_time(); - + create_directory(path.Path(), 0777); { BDirectory account_dir(path.Path()); @@ -44,7 +79,7 @@ status_t MailInternal::WriteMessageFile(const BMessage& archive, const BPath& pa path.Path(), strerror(ret)); return ret; } - + // get an entry for the tempfile // Get it here so that failure doesn't create any problems ret = settings_entry.SetTo(&account_dir,leaf.String()); @@ -55,11 +90,11 @@ status_t MailInternal::WriteMessageFile(const BMessage& archive, const BPath& pa return ret; } } - + // // Save to a temporary file // - + // Our goal is to write to a tempfile and then use 'rename' to // link that file into place once it contains valid contents. // Given the filesystem's guarantee of atomic "rename" oper- @@ -110,14 +145,14 @@ status_t MailInternal::WriteMessageFile(const BMessage& archive, const BPath& pa // we get the Relink() api. An implementation of the above // follows. // - + // Create or open ret = B_TIMED_OUT; while (system_time() - now < timeout) //-ATT-no timeout arg. Setting by #define { ret = tmpfile.SetTo(&settings_entry, B_WRITE_ONLY | B_CREATE_FILE); if (ret != B_BUSY) break; - + // wait 1/100th second snooze((bigtime_t)1e4); } @@ -127,14 +162,14 @@ status_t MailInternal::WriteMessageFile(const BMessage& archive, const BPath& pa path.Path(), leaf.String(), (float)timeout/1e6, strerror(ret)); return ret==B_BUSY? B_TIMED_OUT:ret; } - + // lock ret = B_TIMED_OUT; while (system_time() - now < timeout) { ret = tmpfile.Lock(); //-ATT-changed account_file to tmpfile. Is that allowed? if (ret != B_BUSY) break; - + // wait 1/100th second snooze((bigtime_t)1e4); } @@ -147,10 +182,10 @@ status_t MailInternal::WriteMessageFile(const BMessage& archive, const BPath& pa // that's OK. return ret==B_BUSY? B_TIMED_OUT:ret; } - + // truncate tmpfile.SetSize(0); - + // write ret = archive.Flatten(&tmpfile); if (ret != B_OK) @@ -159,7 +194,7 @@ status_t MailInternal::WriteMessageFile(const BMessage& archive, const BPath& pa path.Path(), leaf.String(), strerror(ret)); return ret; } - + // ensure it's actually writen ret = tmpfile.Sync(); if (ret != B_OK) @@ -168,7 +203,7 @@ status_t MailInternal::WriteMessageFile(const BMessage& archive, const BPath& pa path.Path(), leaf.String(), strerror(ret)); return ret; } - + // clobber old settings ret = settings_entry.Rename(name,true); if (ret != B_OK) @@ -177,7 +212,9 @@ status_t MailInternal::WriteMessageFile(const BMessage& archive, const BPath& pa path.Path(), name, strerror(ret)); return ret; } - + return B_OK; } + +} // namespace BPrivate