IMAP: New folders will now adopt default mail attributes.
* Added a function CopyMailFolderAttributes() that copies the attribute layout from the text/x-email default query folder. * This using the new CopyAttributes() method in libshared that is pretty much a copy of a similar method from copyattr. However, I did not replace the latter, as that one allows for more fine grained error reporting (and attribute filtering). * Closes ticket #3498.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011, Haiku, Inc. All rights reserved.
|
||||
* Copyright 2011-2016, Haiku, Inc. All rights reserved.
|
||||
* Copyright 2001-2003 Dr. Zoidberg Enterprises. All rights reserved.
|
||||
*/
|
||||
#ifndef ZOIDBERG_GARGOYLE_MAIL_UTIL_H
|
||||
@@ -102,5 +102,7 @@ void extract_address_name(BString &address);
|
||||
void get_address_list(BList &list, const char *string,
|
||||
void (*cleanupFunc)(BString &) = NULL);
|
||||
|
||||
status_t CopyMailFolderAttributes(const char* targetPath);
|
||||
|
||||
|
||||
#endif /* ZOIDBERG_GARGOYLE_MAIL_UTIL_H */
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2016 Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef ATTRIBUTE_UTILITIES_H
|
||||
#define ATTRIBUTE_UTILITIES_H
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
class BNode;
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
status_t CopyAttributes(BNode& source, BNode& destination);
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
|
||||
#endif // ATTRIBUTE_UTILITIES_H
|
||||
@@ -13,6 +13,8 @@
|
||||
#include "IMAPFolder.h"
|
||||
#include "Utilities.h"
|
||||
|
||||
#include <mail_util.h>
|
||||
|
||||
|
||||
IMAPProtocol::IMAPProtocol(const BMailAccountSettings& settings)
|
||||
:
|
||||
@@ -280,6 +282,8 @@ IMAPProtocol::_CreateFolder(const BString& mailbox, const BString& separator)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CopyMailFolderAttributes(path.Path());
|
||||
|
||||
entry_ref ref;
|
||||
status = get_ref_for_path(path.Path(), &ref);
|
||||
if (status != B_OK) {
|
||||
|
||||
@@ -58,7 +58,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
||||
SharedLibrary $(libmail) :
|
||||
$(sources)
|
||||
:
|
||||
be bnetapi textencoding tracker
|
||||
be bnetapi textencoding tracker libshared.a
|
||||
[ TargetLibstdc++ ]
|
||||
$(TARGET_NETWORK_LIBS)
|
||||
$(TARGET_SELECT_UNAME_ETC_LIB)
|
||||
|
||||
@@ -14,14 +14,17 @@
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <FindDirectory.h>
|
||||
#include <List.h>
|
||||
#include <Locker.h>
|
||||
#include <parsedate.h>
|
||||
#include <Path.h>
|
||||
#include <String.h>
|
||||
#include <UTF8.h>
|
||||
|
||||
#include <mail_encoding.h>
|
||||
|
||||
#include <AttributeUtilities.h>
|
||||
#include <CharacterSet.h>
|
||||
#include <CharacterSetRoster.h>
|
||||
|
||||
@@ -1547,3 +1550,20 @@ get_address_list(BList &list, const char *string,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
CopyMailFolderAttributes(const char* targetPath)
|
||||
{
|
||||
BPath path;
|
||||
status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
|
||||
path.Append("Tracker");
|
||||
path.Append("DefaultQueryTemplates");
|
||||
path.Append("text_x-email");
|
||||
|
||||
BNode source(path.Path());
|
||||
BNode target(targetPath);
|
||||
return BPrivate::CopyAttributes(source, target);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2005-2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Copyright 2016, Axel Dörfler, axeld@pinc-software.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include "AttributeUtilities.h"
|
||||
|
||||
#include <fs_attr.h>
|
||||
#include <Node.h>
|
||||
#include <StorageDefs.h>
|
||||
|
||||
|
||||
static const int kCopyBufferSize = 64 * 1024;
|
||||
// 64 KB
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
status_t
|
||||
CopyAttributes(BNode& source, BNode& destination)
|
||||
{
|
||||
char attrName[B_ATTR_NAME_LENGTH];
|
||||
while (source.GetNextAttrName(attrName) == B_OK) {
|
||||
// get attr info
|
||||
attr_info attrInfo;
|
||||
status_t status = source.GetAttrInfo(attrName, &attrInfo);
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
|
||||
// copy the attribute
|
||||
char buffer[kCopyBufferSize];
|
||||
off_t offset = 0;
|
||||
off_t bytesLeft = attrInfo.size;
|
||||
|
||||
// Go at least once through the loop, so that an empty attribute will be
|
||||
// created as well
|
||||
do {
|
||||
size_t toRead = kCopyBufferSize;
|
||||
if ((off_t)toRead > bytesLeft)
|
||||
toRead = bytesLeft;
|
||||
|
||||
// read
|
||||
ssize_t bytesRead = source.ReadAttr(attrName, attrInfo.type,
|
||||
offset, buffer, toRead);
|
||||
if (bytesRead < 0)
|
||||
return bytesRead;
|
||||
|
||||
// write
|
||||
ssize_t bytesWritten = destination.WriteAttr(attrName,
|
||||
attrInfo.type, offset, buffer, bytesRead);
|
||||
if (bytesWritten < 0)
|
||||
return bytesWritten;
|
||||
|
||||
bytesLeft -= bytesRead;
|
||||
offset += bytesRead;
|
||||
} while (bytesLeft > 0);
|
||||
}
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
@@ -29,6 +29,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
||||
StaticLibrary [ MultiArchDefaultGristFiles libshared.a ] :
|
||||
AboutMenuItem.cpp
|
||||
ArgumentVector.cpp
|
||||
AttributeUtilities.cpp
|
||||
CalendarView.cpp
|
||||
ColorQuantizer.cpp
|
||||
CommandPipe.cpp
|
||||
|
||||
Reference in New Issue
Block a user