* 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:
parent
cffd2917a3
commit
21c22141b8
@ -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<AddonSettings> 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;
|
||||
|
||||
|
25
headers/private/mail/MailPrivate.h
Normal file
25
headers/private/mail/MailPrivate.h
Normal file
@ -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 <TextControl.h>
|
||||
|
||||
#include <FileConfigView.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <Path.h>
|
||||
#include <ProtocolConfigView.h>
|
||||
#include <MailAddon.h>
|
||||
#include <Path.h>
|
||||
|
||||
#include <FileConfigView.h>
|
||||
#include <ProtocolConfigView.h>
|
||||
#include <MailPrivate.h>
|
||||
#include <MDRLanguage.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include <FileConfigView.h>
|
||||
#include <MailAddon.h>
|
||||
#include <MailPrivate.h>
|
||||
#include <ProtocolConfigView.h>
|
||||
|
||||
|
||||
@ -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;
|
||||
|
@ -10,9 +10,10 @@
|
||||
#include <TextControl.h>
|
||||
|
||||
#include <FileConfigView.h>
|
||||
#include <MDRLanguage.h>
|
||||
#include <MailAddon.h>
|
||||
#include <MDRLanguage.h>
|
||||
#include <MenuField.h>
|
||||
#include <MailPrivate.h>
|
||||
#include <ProtocolConfigView.h>
|
||||
|
||||
|
||||
@ -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<BTextControl *>(ChildAt(i)))
|
||||
if (BTextControl *text = dynamic_cast<BTextControl *>(ChildAt(i)))
|
||||
widestLabel = MAX(widestLabel,text->StringWidth(text->Label()) + 5);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
@ -16,8 +16,7 @@
|
||||
#include <NodeMessage.h>
|
||||
|
||||
|
||||
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
|
||||
|
@ -28,7 +28,8 @@ private:
|
||||
const BString& name);
|
||||
BString _ExtractName(const BString& from);
|
||||
|
||||
int32 fAccountId;
|
||||
private:
|
||||
int32 fAccountID;
|
||||
BString fAccountName;
|
||||
BString fOutboundDirectory;
|
||||
};
|
||||
|
@ -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 <MailSettings.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <Directory.h>
|
||||
#include <Entry.h>
|
||||
#include <File.h>
|
||||
@ -20,26 +25,7 @@
|
||||
#include <String.h>
|
||||
#include <Window.h>
|
||||
|
||||
#include <stdio.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();
|
||||
}
|
||||
#include <MailPrivate.h>
|
||||
|
||||
|
||||
// #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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,36 +4,71 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <Messenger.h>
|
||||
#include <String.h>
|
||||
#include <Entry.h>
|
||||
#include <File.h>
|
||||
#include <Path.h>
|
||||
#include <Directory.h>
|
||||
#include <Locker.h>
|
||||
#include <Autolock.h>
|
||||
#include <MailPrivate.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
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user