* 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
This commit is contained in:
@@ -20,8 +20,7 @@
|
|||||||
class BPath;
|
class BPath;
|
||||||
|
|
||||||
|
|
||||||
typedef enum
|
typedef enum {
|
||||||
{
|
|
||||||
B_MAIL_SHOW_STATUS_WINDOW_NEVER = 0,
|
B_MAIL_SHOW_STATUS_WINDOW_NEVER = 0,
|
||||||
B_MAIL_SHOW_STATUS_WINDOW_WHEN_SENDING = 1,
|
B_MAIL_SHOW_STATUS_WINDOW_WHEN_SENDING = 1,
|
||||||
B_MAIL_SHOW_STATUS_WINDOW_WHEN_ACTIVE = 2,
|
B_MAIL_SHOW_STATUS_WINDOW_WHEN_ACTIVE = 2,
|
||||||
@@ -29,8 +28,7 @@ typedef enum
|
|||||||
} b_mail_status_window_option;
|
} b_mail_status_window_option;
|
||||||
|
|
||||||
|
|
||||||
typedef enum
|
typedef enum {
|
||||||
{
|
|
||||||
B_MAIL_STATUS_LOOK_TITLED = 0,
|
B_MAIL_STATUS_LOOK_TITLED = 0,
|
||||||
B_MAIL_STATUS_LOOK_NORMAL_BORDER = 1,
|
B_MAIL_STATUS_LOOK_NORMAL_BORDER = 1,
|
||||||
B_MAIL_STATUS_LOOK_FLOATING = 2,
|
B_MAIL_STATUS_LOOK_FLOATING = 2,
|
||||||
@@ -39,9 +37,6 @@ typedef enum
|
|||||||
} b_mail_status_window_look;
|
} b_mail_status_window_look;
|
||||||
|
|
||||||
|
|
||||||
BString default_sent_directory();
|
|
||||||
|
|
||||||
|
|
||||||
class BMailSettings {
|
class BMailSettings {
|
||||||
public:
|
public:
|
||||||
BMailSettings();
|
BMailSettings();
|
||||||
@@ -57,7 +52,7 @@ public:
|
|||||||
|
|
||||||
uint32 ShowStatusWindow();
|
uint32 ShowStatusWindow();
|
||||||
void SetShowStatusWindow(uint32 mode);
|
void SetShowStatusWindow(uint32 mode);
|
||||||
|
|
||||||
bool DaemonAutoStarts();
|
bool DaemonAutoStarts();
|
||||||
void SetDaemonAutoStarts(bool does_it);
|
void SetDaemonAutoStarts(bool does_it);
|
||||||
|
|
||||||
@@ -91,8 +86,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class AddonSettings
|
class AddonSettings {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
AddonSettings();
|
AddonSettings();
|
||||||
|
|
||||||
@@ -106,6 +100,7 @@ public:
|
|||||||
BMessage& EditSettings();
|
BMessage& EditSettings();
|
||||||
|
|
||||||
bool HasBeenModified();
|
bool HasBeenModified();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BMessage fSettings;
|
BMessage fSettings;
|
||||||
entry_ref fAddonRef;
|
entry_ref fAddonRef;
|
||||||
@@ -114,8 +109,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class MailAddonSettings : public AddonSettings
|
class MailAddonSettings : public AddonSettings {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
bool Load(const BMessage& message);
|
bool Load(const BMessage& message);
|
||||||
bool Save(BMessage& message);
|
bool Save(BMessage& message);
|
||||||
@@ -127,13 +121,13 @@ public:
|
|||||||
AddonSettings* FilterSettingsAt(int32 index);
|
AddonSettings* FilterSettingsAt(int32 index);
|
||||||
|
|
||||||
bool HasBeenModified();
|
bool HasBeenModified();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<AddonSettings> fFiltersSettings;
|
std::vector<AddonSettings> fFiltersSettings;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class BMailAccountSettings
|
class BMailAccountSettings {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
BMailAccountSettings();
|
BMailAccountSettings();
|
||||||
BMailAccountSettings(BEntry account);
|
BMailAccountSettings(BEntry account);
|
||||||
@@ -176,9 +170,11 @@ class BMailAccountSettings
|
|||||||
bool HasBeenModified();
|
bool HasBeenModified();
|
||||||
|
|
||||||
const BEntry& AccountFile();
|
const BEntry& AccountFile();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
status_t _CreateAccountFilePath();
|
status_t _CreateAccountFilePath();
|
||||||
|
|
||||||
|
private:
|
||||||
status_t fStatus;
|
status_t fStatus;
|
||||||
BEntry fAccountFile;
|
BEntry fAccountFile;
|
||||||
|
|
||||||
|
|||||||
@@ -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 <Message.h>
|
||||||
|
#include <Path.h>
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
@@ -10,13 +10,14 @@
|
|||||||
#include <Button.h>
|
#include <Button.h>
|
||||||
#include <TextControl.h>
|
#include <TextControl.h>
|
||||||
|
|
||||||
#include <FileConfigView.h>
|
|
||||||
#include <FindDirectory.h>
|
|
||||||
#include <Path.h>
|
|
||||||
#include <ProtocolConfigView.h>
|
|
||||||
#include <MailAddon.h>
|
#include <MailAddon.h>
|
||||||
|
#include <Path.h>
|
||||||
|
|
||||||
|
#include <FileConfigView.h>
|
||||||
|
#include <ProtocolConfigView.h>
|
||||||
|
#include <MailPrivate.h>
|
||||||
#include <MDRLanguage.h>
|
#include <MDRLanguage.h>
|
||||||
|
|
||||||
#include "IMAPFolderConfig.h"
|
#include "IMAPFolderConfig.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -52,12 +53,11 @@ IMAPConfig::IMAPConfig(MailAddonSettings& settings,
|
|||||||
| B_MAIL_PROTOCOL_HAS_FLAVORS
|
| B_MAIL_PROTOCOL_HAS_FLAVORS
|
||||||
#endif
|
#endif
|
||||||
),
|
),
|
||||||
|
|
||||||
fAddonSettings(settings)
|
fAddonSettings(settings)
|
||||||
{
|
{
|
||||||
#ifdef USE_SSL
|
#ifdef USE_SSL
|
||||||
AddFlavor("No encryption");
|
AddFlavor("No encryption");
|
||||||
AddFlavor("SSL");
|
AddFlavor("SSL");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SetTo(settings);
|
SetTo(settings);
|
||||||
@@ -70,18 +70,13 @@ IMAPConfig::IMAPConfig(MailAddonSettings& settings,
|
|||||||
((BControl *)(FindView("delete_remote_when_local")))->SetEnabled(true);
|
((BControl *)(FindView("delete_remote_when_local")))->SetEnabled(true);
|
||||||
((BControl *)(FindView("delete_remote_when_local")))->MoveBy(0, -25);
|
((BControl *)(FindView("delete_remote_when_local")))->MoveBy(0, -25);
|
||||||
|
|
||||||
|
|
||||||
fIMAPFolderButton = new BButton(frame, "IMAP Folders", "IMAP Folders",
|
fIMAPFolderButton = new BButton(frame, "IMAP Folders", "IMAP Folders",
|
||||||
new BMessage(kMsgOpenIMAPFolder));
|
new BMessage(kMsgOpenIMAPFolder));
|
||||||
AddChild(fIMAPFolderButton);
|
AddChild(fIMAPFolderButton);
|
||||||
|
|
||||||
frame.right -= 10;
|
frame.right -= 10;
|
||||||
|
|
||||||
BPath defaultFolder;
|
BPath defaultFolder = BPrivate::default_mail_directory();
|
||||||
if (find_directory(B_USER_DIRECTORY, &defaultFolder) == B_OK)
|
|
||||||
defaultFolder.Append("mail");
|
|
||||||
else
|
|
||||||
defaultFolder.SetTo("/boot/home/mail/");
|
|
||||||
defaultFolder.Append(accountSettings.Name());
|
defaultFolder.Append(accountSettings.Name());
|
||||||
|
|
||||||
fFileView = new BMailFileConfigView("Destination:", "destination",
|
fFileView = new BMailFileConfigView("Destination:", "destination",
|
||||||
@@ -131,7 +126,7 @@ IMAPConfig::MessageReceived(BMessage* message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BMailProtocolConfigView::MessageReceived(message);
|
BMailProtocolConfigView::MessageReceived(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include <FileConfigView.h>
|
#include <FileConfigView.h>
|
||||||
#include <MailAddon.h>
|
#include <MailAddon.h>
|
||||||
|
#include <MailPrivate.h>
|
||||||
#include <ProtocolConfigView.h>
|
#include <ProtocolConfigView.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -47,7 +48,7 @@ POP3ConfigView::POP3ConfigView(MailAddonSettings& settings,
|
|||||||
SetTo(settings);
|
SetTo(settings);
|
||||||
|
|
||||||
fFileView = new BMailFileConfigView("Destination:", "destination",
|
fFileView = new BMailFileConfigView("Destination:", "destination",
|
||||||
false, "/boot/home/mail/in");
|
false, BPrivate::default_mail_in_directory().Path());
|
||||||
fFileView->SetTo(&settings.Settings(), NULL);
|
fFileView->SetTo(&settings.Settings(), NULL);
|
||||||
AddChild(fFileView);
|
AddChild(fFileView);
|
||||||
float w, h;
|
float w, h;
|
||||||
|
|||||||
@@ -10,9 +10,10 @@
|
|||||||
#include <TextControl.h>
|
#include <TextControl.h>
|
||||||
|
|
||||||
#include <FileConfigView.h>
|
#include <FileConfigView.h>
|
||||||
#include <MDRLanguage.h>
|
|
||||||
#include <MailAddon.h>
|
#include <MailAddon.h>
|
||||||
|
#include <MDRLanguage.h>
|
||||||
#include <MenuField.h>
|
#include <MenuField.h>
|
||||||
|
#include <MailPrivate.h>
|
||||||
#include <ProtocolConfigView.h>
|
#include <ProtocolConfigView.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -23,45 +24,42 @@ public:
|
|||||||
status_t Archive(BMessage *into, bool deep = true) const;
|
status_t Archive(BMessage *into, bool deep = true) const;
|
||||||
void GetPreferredSize(float *width, float *height);
|
void GetPreferredSize(float *width, float *height);
|
||||||
private:
|
private:
|
||||||
BMailFileConfigView* fFileView;
|
BMailFileConfigView* fFileView;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
SMTPConfigView::SMTPConfigView(MailAddonSettings& settings,
|
SMTPConfigView::SMTPConfigView(MailAddonSettings& settings,
|
||||||
BMailAccountSettings& accountSettings)
|
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
|
BMailProtocolConfigView(B_MAIL_PROTOCOL_HAS_AUTH_METHODS
|
||||||
| B_MAIL_PROTOCOL_HAS_USERNAME | B_MAIL_PROTOCOL_HAS_PASSWORD
|
| B_MAIL_PROTOCOL_HAS_USERNAME | B_MAIL_PROTOCOL_HAS_PASSWORD
|
||||||
| B_MAIL_PROTOCOL_HAS_HOSTNAME)
|
| B_MAIL_PROTOCOL_HAS_HOSTNAME
|
||||||
#endif
|
#ifdef USE_SSL
|
||||||
|
| B_MAIL_PROTOCOL_HAS_FLAVORS
|
||||||
|
#endif
|
||||||
|
)
|
||||||
{
|
{
|
||||||
#ifdef USE_SSL
|
#ifdef USE_SSL
|
||||||
AddFlavor("Unencrypted");
|
AddFlavor("Unencrypted");
|
||||||
AddFlavor("SSL");
|
AddFlavor("SSL");
|
||||||
AddFlavor("STARTTLS");
|
AddFlavor("STARTTLS");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
AddAuthMethod(MDR_DIALECT_CHOICE("None","無し"), false);
|
AddAuthMethod(MDR_DIALECT_CHOICE("None","無し"), false);
|
||||||
AddAuthMethod(MDR_DIALECT_CHOICE("ESMTP","ESMTP"));
|
AddAuthMethod(MDR_DIALECT_CHOICE("ESMTP","ESMTP"));
|
||||||
AddAuthMethod(MDR_DIALECT_CHOICE("POP3 before SMTP","送信前に受信する"),
|
AddAuthMethod(MDR_DIALECT_CHOICE("POP3 before SMTP","送信前に受信する"), false);
|
||||||
false);
|
|
||||||
|
|
||||||
BTextControl *control = (BTextControl *)(FindView("host"));
|
BTextControl *control = (BTextControl *)(FindView("host"));
|
||||||
control->SetLabel(MDR_DIALECT_CHOICE("SMTP server: ","SMTPサーバ: "));
|
control->SetLabel(MDR_DIALECT_CHOICE("SMTP server: ","SMTPサーバ: "));
|
||||||
|
|
||||||
// Reset the dividers after changing one
|
// Reset the dividers after changing one
|
||||||
float widestLabel=0;
|
float widestLabel = 0;
|
||||||
for (int32 i = CountChildren(); i-- > 0;) {
|
for (int32 i = CountChildren(); i-- > 0;) {
|
||||||
if(BTextControl *text = dynamic_cast<BTextControl *>(ChildAt(i)))
|
if (BTextControl *text = dynamic_cast<BTextControl *>(ChildAt(i)))
|
||||||
widestLabel = MAX(widestLabel,text->StringWidth(text->Label()) + 5);
|
widestLabel = MAX(widestLabel,text->StringWidth(text->Label()) + 5);
|
||||||
}
|
}
|
||||||
for (int32 i = CountChildren(); i-- > 0;) {
|
for (int32 i = CountChildren(); i-- > 0;) {
|
||||||
if(BTextControl *text = dynamic_cast<BTextControl *>(ChildAt(i)))
|
if (BTextControl *text = dynamic_cast<BTextControl *>(ChildAt(i)))
|
||||||
text->SetDivider(widestLabel);
|
text->SetDivider(widestLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,8 +68,8 @@ SMTPConfigView::SMTPConfigView(MailAddonSettings& settings,
|
|||||||
|
|
||||||
SetTo(settings);
|
SetTo(settings);
|
||||||
|
|
||||||
fFileView = new BMailFileConfigView("Destination:", "destination",
|
fFileView = new BMailFileConfigView("Destination:", "path", false,
|
||||||
false, default_sent_directory());
|
BPrivate::default_mail_out_directory().Path());
|
||||||
fFileView->SetTo(&settings.Settings(), NULL);
|
fFileView->SetTo(&settings.Settings(), NULL);
|
||||||
AddChild(fFileView);
|
AddChild(fFileView);
|
||||||
float w, h;
|
float w, h;
|
||||||
|
|||||||
@@ -16,8 +16,7 @@
|
|||||||
#include <NodeMessage.h>
|
#include <NodeMessage.h>
|
||||||
|
|
||||||
|
|
||||||
struct mail_header_field
|
struct mail_header_field {
|
||||||
{
|
|
||||||
const char *rfc_name;
|
const char *rfc_name;
|
||||||
|
|
||||||
const char *attr_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 },
|
{ "To", B_MAIL_ATTR_TO, B_STRING_TYPE },
|
||||||
{ "From", B_MAIL_ATTR_FROM, B_STRING_TYPE },
|
{ "From", B_MAIL_ATTR_FROM, B_STRING_TYPE },
|
||||||
{ "Cc", B_MAIL_ATTR_CC, B_STRING_TYPE },
|
{ "Cc", B_MAIL_ATTR_CC, B_STRING_TYPE },
|
||||||
@@ -53,15 +51,11 @@ HaikuMailFormatFilter::HaikuMailFormatFilter(MailProtocol& protocol,
|
|||||||
BMailAccountSettings* settings)
|
BMailAccountSettings* settings)
|
||||||
:
|
:
|
||||||
MailFilter(protocol, NULL),
|
MailFilter(protocol, NULL),
|
||||||
|
fAccountID(settings->AccountID()),
|
||||||
fAccountId(settings->AccountID()),
|
|
||||||
fAccountName(settings->Name())
|
fAccountName(settings->Name())
|
||||||
{
|
{
|
||||||
const BMessage* outboundSettings = &settings->OutboundSettings().Settings();
|
const BMessage* outboundSettings = &settings->OutboundSettings().Settings();
|
||||||
if (outboundSettings->FindString("destination", &fOutboundDirectory)
|
outboundSettings->FindString("destination", &fOutboundDirectory);
|
||||||
!= B_OK) {
|
|
||||||
fOutboundDirectory = default_sent_directory();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -72,7 +66,7 @@ HaikuMailFormatFilter::HeaderFetched(const entry_ref& ref, BFile* file)
|
|||||||
|
|
||||||
BMessage attributes;
|
BMessage attributes;
|
||||||
// TODO attributes.AddInt32(B_MAIL_ATTR_CONTENT, length);
|
// 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);
|
attributes.AddString(B_MAIL_ATTR_ACCOUNT, fAccountName);
|
||||||
|
|
||||||
BString header;
|
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_FLAGS, B_INT32_TYPE, 0, &flags, sizeof(int32));
|
||||||
file->WriteAttr(B_MAIL_ATTR_STATUS, B_STRING_TYPE, 0, "Sent", 5);
|
file->WriteAttr(B_MAIL_ATTR_STATUS, B_STRING_TYPE, 0, "Sent", 5);
|
||||||
|
|
||||||
if (fOutboundDirectory == "")
|
if (!fOutboundDirectory.IsEmpty()) {
|
||||||
return;
|
create_directory(fOutboundDirectory, 755);
|
||||||
create_directory(fOutboundDirectory, 755);
|
BDirectory dir(fOutboundDirectory);
|
||||||
BDirectory dir(fOutboundDirectory);
|
fMailProtocol.Looper()->TriggerFileMove(ref, dir);
|
||||||
fMailProtocol.Looper()->TriggerFileMove(ref, dir);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -236,7 +230,7 @@ HaikuMailFormatFilter::_ExtractName(const BString& from)
|
|||||||
name.Remove(0, 1);
|
name.Remove(0, 1);
|
||||||
name.Trim();
|
name.Trim();
|
||||||
}
|
}
|
||||||
if (name != "")
|
if (name != "")
|
||||||
return name;
|
return name;
|
||||||
|
|
||||||
// empty name extract email address
|
// empty name extract email address
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ private:
|
|||||||
const BString& name);
|
const BString& name);
|
||||||
BString _ExtractName(const BString& from);
|
BString _ExtractName(const BString& from);
|
||||||
|
|
||||||
int32 fAccountId;
|
private:
|
||||||
|
int32 fAccountID;
|
||||||
BString fAccountName;
|
BString fAccountName;
|
||||||
BString fOutboundDirectory;
|
BString fOutboundDirectory;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,15 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2003 Dr. Zoidberg Enterprises. All rights reserved.
|
* 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.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
//! The mail daemon's settings
|
//! The mail daemon's settings
|
||||||
|
|
||||||
|
|
||||||
#include <MailSettings.h>
|
#include <MailSettings.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <Directory.h>
|
#include <Directory.h>
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
@@ -20,26 +25,7 @@
|
|||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <MailPrivate.h>
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - BMailSettings
|
// #pragma mark - BMailSettings
|
||||||
@@ -81,7 +67,8 @@ BMailSettings::Save(bigtime_t /*timeout*/)
|
|||||||
|
|
||||||
path.Append("Mail");
|
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)
|
if (result < B_OK)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
@@ -95,7 +82,7 @@ status_t
|
|||||||
BMailSettings::Reload()
|
BMailSettings::Reload()
|
||||||
{
|
{
|
||||||
status_t ret;
|
status_t ret;
|
||||||
|
|
||||||
BPath path;
|
BPath path;
|
||||||
ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
|
ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
|
||||||
if (ret != B_OK) {
|
if (ret != B_OK) {
|
||||||
@@ -103,9 +90,9 @@ BMailSettings::Reload()
|
|||||||
strerror(ret));
|
strerror(ret));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
path.Append("Mail/new_mail_daemon");
|
path.Append("Mail/new_mail_daemon");
|
||||||
|
|
||||||
// open
|
// open
|
||||||
BFile settings(path.Path(),B_READ_ONLY);
|
BFile settings(path.Path(),B_READ_ONLY);
|
||||||
ret = settings.InitCheck();
|
ret = settings.InitCheck();
|
||||||
@@ -114,7 +101,7 @@ BMailSettings::Reload()
|
|||||||
path.Path(), strerror(ret));
|
path.Path(), strerror(ret));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// read settings
|
// read settings
|
||||||
BMessage tmp;
|
BMessage tmp;
|
||||||
ret = tmp.Unflatten(&settings);
|
ret = tmp.Unflatten(&settings);
|
||||||
@@ -205,7 +192,7 @@ BMailSettings::StatusWindowFrame()
|
|||||||
BRect frame;
|
BRect frame;
|
||||||
if (fData.FindRect("StatusWindowFrame", &frame) != B_OK)
|
if (fData.FindRect("StatusWindowFrame", &frame) != B_OK)
|
||||||
return BRect(100, 100, 200, 120);
|
return BRect(100, 100, 200, 120);
|
||||||
|
|
||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,7 +240,7 @@ BMailSettings::SetStatusWindowLook(int32 look)
|
|||||||
{
|
{
|
||||||
if (fData.ReplaceInt32("StatusWindowLook",look))
|
if (fData.ReplaceInt32("StatusWindowLook",look))
|
||||||
fData.AddInt32("StatusWindowLook",look);
|
fData.AddInt32("StatusWindowLook",look);
|
||||||
|
|
||||||
BMessage msg('lkch');
|
BMessage msg('lkch');
|
||||||
msg.AddInt32("StatusWindowLook",look);
|
msg.AddInt32("StatusWindowLook",look);
|
||||||
BMessenger("application/x-vnd.Be-POST").SendMessage(&msg);
|
BMessenger("application/x-vnd.Be-POST").SendMessage(&msg);
|
||||||
@@ -366,7 +353,6 @@ BMailAccounts::BMailAccounts()
|
|||||||
creationTimeList.insert(creationTimeList.begin() + insertIndex,
|
creationTimeList.insert(creationTimeList.begin() + insertIndex,
|
||||||
creationTime);
|
creationTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -911,7 +897,7 @@ BMailAccountSettings::_CreateAccountFilePath()
|
|||||||
|
|
||||||
BString fileName = fAccountName;
|
BString fileName = fAccountName;
|
||||||
if (fileName == "")
|
if (fileName == "")
|
||||||
fileName << fAccountID;
|
fileName << fAccountID;
|
||||||
for (int i = 0; ; i++) {
|
for (int i = 0; ; i++) {
|
||||||
BString testFileName = fileName;
|
BString testFileName = fileName;
|
||||||
if (i != 0) {
|
if (i != 0) {
|
||||||
@@ -923,7 +909,7 @@ BMailAccountSettings::_CreateAccountFilePath()
|
|||||||
BEntry testEntry(testPath.Path());
|
BEntry testEntry(testPath.Path());
|
||||||
if (!testEntry.Exists()) {
|
if (!testEntry.Exists()) {
|
||||||
fileName = testFileName;
|
fileName = testFileName;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+62
-25
@@ -4,36 +4,71 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <Messenger.h>
|
#include <MailPrivate.h>
|
||||||
#include <String.h>
|
|
||||||
#include <Entry.h>
|
|
||||||
#include <File.h>
|
|
||||||
#include <Path.h>
|
|
||||||
#include <Directory.h>
|
|
||||||
#include <Locker.h>
|
|
||||||
#include <Autolock.h>
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <Autolock.h>
|
||||||
|
#include <Directory.h>
|
||||||
|
#include <Entry.h>
|
||||||
|
#include <File.h>
|
||||||
|
#include <FindDirectory.h>
|
||||||
|
#include <Locker.h>
|
||||||
|
#include <Messenger.h>
|
||||||
|
#include <Path.h>
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
|
||||||
#define timeout 5e5
|
#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;
|
status_t ret = B_OK;
|
||||||
BString leaf = name;
|
BString leaf = name;
|
||||||
leaf << ".tmp";
|
leaf << ".tmp";
|
||||||
|
|
||||||
BEntry settings_entry;
|
BEntry settings_entry;
|
||||||
BFile tmpfile;
|
BFile tmpfile;
|
||||||
bigtime_t now = system_time();
|
bigtime_t now = system_time();
|
||||||
|
|
||||||
create_directory(path.Path(), 0777);
|
create_directory(path.Path(), 0777);
|
||||||
{
|
{
|
||||||
BDirectory account_dir(path.Path());
|
BDirectory account_dir(path.Path());
|
||||||
@@ -44,7 +79,7 @@ status_t MailInternal::WriteMessageFile(const BMessage& archive, const BPath& pa
|
|||||||
path.Path(), strerror(ret));
|
path.Path(), strerror(ret));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get an entry for the tempfile
|
// get an entry for the tempfile
|
||||||
// Get it here so that failure doesn't create any problems
|
// Get it here so that failure doesn't create any problems
|
||||||
ret = settings_entry.SetTo(&account_dir,leaf.String());
|
ret = settings_entry.SetTo(&account_dir,leaf.String());
|
||||||
@@ -55,11 +90,11 @@ status_t MailInternal::WriteMessageFile(const BMessage& archive, const BPath& pa
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Save to a temporary file
|
// Save to a temporary file
|
||||||
//
|
//
|
||||||
|
|
||||||
// Our goal is to write to a tempfile and then use 'rename' to
|
// Our goal is to write to a tempfile and then use 'rename' to
|
||||||
// link that file into place once it contains valid contents.
|
// link that file into place once it contains valid contents.
|
||||||
// Given the filesystem's guarantee of atomic "rename" oper-
|
// 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
|
// we get the Relink() api. An implementation of the above
|
||||||
// follows.
|
// follows.
|
||||||
//
|
//
|
||||||
|
|
||||||
// Create or open
|
// Create or open
|
||||||
ret = B_TIMED_OUT;
|
ret = B_TIMED_OUT;
|
||||||
while (system_time() - now < timeout) //-ATT-no timeout arg. Setting by #define
|
while (system_time() - now < timeout) //-ATT-no timeout arg. Setting by #define
|
||||||
{
|
{
|
||||||
ret = tmpfile.SetTo(&settings_entry, B_WRITE_ONLY | B_CREATE_FILE);
|
ret = tmpfile.SetTo(&settings_entry, B_WRITE_ONLY | B_CREATE_FILE);
|
||||||
if (ret != B_BUSY) break;
|
if (ret != B_BUSY) break;
|
||||||
|
|
||||||
// wait 1/100th second
|
// wait 1/100th second
|
||||||
snooze((bigtime_t)1e4);
|
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));
|
path.Path(), leaf.String(), (float)timeout/1e6, strerror(ret));
|
||||||
return ret==B_BUSY? B_TIMED_OUT:ret;
|
return ret==B_BUSY? B_TIMED_OUT:ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// lock
|
// lock
|
||||||
ret = B_TIMED_OUT;
|
ret = B_TIMED_OUT;
|
||||||
while (system_time() - now < timeout)
|
while (system_time() - now < timeout)
|
||||||
{
|
{
|
||||||
ret = tmpfile.Lock(); //-ATT-changed account_file to tmpfile. Is that allowed?
|
ret = tmpfile.Lock(); //-ATT-changed account_file to tmpfile. Is that allowed?
|
||||||
if (ret != B_BUSY) break;
|
if (ret != B_BUSY) break;
|
||||||
|
|
||||||
// wait 1/100th second
|
// wait 1/100th second
|
||||||
snooze((bigtime_t)1e4);
|
snooze((bigtime_t)1e4);
|
||||||
}
|
}
|
||||||
@@ -147,10 +182,10 @@ status_t MailInternal::WriteMessageFile(const BMessage& archive, const BPath& pa
|
|||||||
// that's OK.
|
// that's OK.
|
||||||
return ret==B_BUSY? B_TIMED_OUT:ret;
|
return ret==B_BUSY? B_TIMED_OUT:ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// truncate
|
// truncate
|
||||||
tmpfile.SetSize(0);
|
tmpfile.SetSize(0);
|
||||||
|
|
||||||
// write
|
// write
|
||||||
ret = archive.Flatten(&tmpfile);
|
ret = archive.Flatten(&tmpfile);
|
||||||
if (ret != B_OK)
|
if (ret != B_OK)
|
||||||
@@ -159,7 +194,7 @@ status_t MailInternal::WriteMessageFile(const BMessage& archive, const BPath& pa
|
|||||||
path.Path(), leaf.String(), strerror(ret));
|
path.Path(), leaf.String(), strerror(ret));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure it's actually writen
|
// ensure it's actually writen
|
||||||
ret = tmpfile.Sync();
|
ret = tmpfile.Sync();
|
||||||
if (ret != B_OK)
|
if (ret != B_OK)
|
||||||
@@ -168,7 +203,7 @@ status_t MailInternal::WriteMessageFile(const BMessage& archive, const BPath& pa
|
|||||||
path.Path(), leaf.String(), strerror(ret));
|
path.Path(), leaf.String(), strerror(ret));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// clobber old settings
|
// clobber old settings
|
||||||
ret = settings_entry.Rename(name,true);
|
ret = settings_entry.Rename(name,true);
|
||||||
if (ret != B_OK)
|
if (ret != B_OK)
|
||||||
@@ -177,7 +212,9 @@ status_t MailInternal::WriteMessageFile(const BMessage& archive, const BPath& pa
|
|||||||
path.Path(), name, strerror(ret));
|
path.Path(), name, strerror(ret));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace BPrivate
|
||||||
|
|||||||
Reference in New Issue
Block a user