Skip to content

Commit

Permalink
Mail: Reworking of the unique filename discovery (drafts)
Browse files Browse the repository at this point in the history
  • Loading branch information
stpere committed Dec 13, 2012
1 parent 55ef15c commit 53b234e
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/apps/mail/MailWindow.cpp
Expand Up @@ -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;
Expand All @@ -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)
return status;
sprintf(eofn, "%ld", i);
}
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;

// Cache the ref
if (fRef == NULL)
Expand Down

0 comments on commit 53b234e

Please sign in to comment.