Mail: Reworking of the unique filename discovery (drafts)
This commit is contained in:
parent
55ef15c45a
commit
53b234eb1c
@ -2548,11 +2548,11 @@ TMailWindow::SaveAsDraft()
|
||||
return status;
|
||||
case B_OK:
|
||||
{
|
||||
char fileName[B_FILE_NAME_LENGTH], *eofn;
|
||||
char fileName[B_FILE_NAME_LENGTH];
|
||||
// save as some version of the message's subject
|
||||
strlcpy(fileName, fHeaderView->fSubject->Text(),
|
||||
sizeof(fileName));
|
||||
eofn = fileName + strlen(fileName);
|
||||
uint32 originalLength = strlen(fileName);
|
||||
|
||||
// convert /, \ and : to -
|
||||
for (char *bad = fileName; (bad = strchr(bad, '/')) != NULL;
|
||||
@ -2564,12 +2564,19 @@ TMailWindow::SaveAsDraft()
|
||||
|
||||
// Create the file; if the name exists, find a unique name
|
||||
flags = B_WRITE_ONLY | B_CREATE_FILE | B_FAIL_IF_EXISTS;
|
||||
for (int32 i = 1; (status = draft.SetTo(&dir, fileName, flags))
|
||||
!= B_OK; i++) {
|
||||
if (status != B_FILE_EXISTS)
|
||||
int32 i = 1;
|
||||
do {
|
||||
status = draft.SetTo(&dir, fileName, flags);
|
||||
if (status == B_OK)
|
||||
break;
|
||||
char appendix[B_FILE_NAME_LENGTH];
|
||||
sprintf(appendix, " %ld", i++);
|
||||
int32 pos = min_c(sizeof(fileName) - strlen(appendix),
|
||||
originalLength);
|
||||
sprintf(fileName + pos, "%s", appendix);
|
||||
} while (status == B_FILE_EXISTS);
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
sprintf(eofn, "%ld", i);
|
||||
}
|
||||
|
||||
// Cache the ref
|
||||
if (fRef == NULL)
|
||||
|
Loading…
Reference in New Issue
Block a user