Mail: Reworking of the unique filename discovery (drafts)

This commit is contained in:
Philippe Saint-Pierre
2012-12-12 21:49:20 -05:00
parent 55ef15c45a
commit 53b234eb1c
+15 -8
View File
@@ -2548,11 +2548,11 @@ TMailWindow::SaveAsDraft()
return status; return status;
case B_OK: 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 // save as some version of the message's subject
strlcpy(fileName, fHeaderView->fSubject->Text(), strlcpy(fileName, fHeaderView->fSubject->Text(),
sizeof(fileName)); sizeof(fileName));
eofn = fileName + strlen(fileName); uint32 originalLength = strlen(fileName);
// convert /, \ and : to - // convert /, \ and : to -
for (char *bad = fileName; (bad = strchr(bad, '/')) != NULL; 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 // Create the file; if the name exists, find a unique name
flags = B_WRITE_ONLY | B_CREATE_FILE | B_FAIL_IF_EXISTS; flags = B_WRITE_ONLY | B_CREATE_FILE | B_FAIL_IF_EXISTS;
for (int32 i = 1; (status = draft.SetTo(&dir, fileName, flags)) int32 i = 1;
!= B_OK; i++) { do {
if (status != B_FILE_EXISTS) status = draft.SetTo(&dir, fileName, flags);
return status; if (status == B_OK)
sprintf(eofn, "%ld", i); 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;
// Cache the ref // Cache the ref
if (fRef == NULL) if (fRef == NULL)