mirror of
https://github.com/mjl-/mox.git
synced 2025-07-12 18:24:35 +03:00
Before moving message files in imapserver and webmail API, ensure the message destination directory for the newly assigned IDs exist.
Example symptom, when deleting a message in the webmail (which moves to Trash): l=error m="duplicating message in old mailbox for current sessions" err="link data/accounts/mjl/msg/I/368638 data/accounts/mjl/msg/J/368640: no such file or directory" pkg=webmail Problem introduced a few weeks ago, where moving messages starting duplicating the message first, and the copy is erased once all references (in IMAP sessions) to the old mailbox have been removed.
This commit is contained in:
@ -3198,9 +3198,19 @@ func OpenEmail(log mlog.Log, email string, checkLoginDisabled bool) (*Account, s
|
||||
return acc, accountName, dest, nil
|
||||
}
|
||||
|
||||
// We store max 1<<shift files in each subdir of an account "msg" directory.
|
||||
// Defaults to 1 for easy use in tests. Set to 13, for 8k message files, in main
|
||||
// for normal operation.
|
||||
var msgFilesPerDirShift = 1
|
||||
var msgFilesPerDir int64 = 1 << msgFilesPerDirShift
|
||||
|
||||
func MsgFilesPerDirShiftSet(shift int) {
|
||||
msgFilesPerDirShift = shift
|
||||
msgFilesPerDir = 1 << shift
|
||||
}
|
||||
|
||||
// 64 characters, must be power of 2 for MessagePath
|
||||
const msgDirChars = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-_"
|
||||
const msgFilesPerDir = 8 * 1024
|
||||
|
||||
// MessagePath returns the filename of the on-disk filename, relative to the
|
||||
// containing directory such as <account>/msg or queue.
|
||||
@ -3212,7 +3222,7 @@ func MessagePath(messageID int64) string {
|
||||
// messagePathElems returns the elems, for a single join without intermediate
|
||||
// string allocations.
|
||||
func messagePathElems(messageID int64) []string {
|
||||
v := messageID >> 13 // 8k files per directory.
|
||||
v := messageID >> msgFilesPerDirShift
|
||||
dir := ""
|
||||
for {
|
||||
dir += string(msgDirChars[int(v)&(len(msgDirChars)-1)])
|
||||
|
Reference in New Issue
Block a user