diff --git a/src/apps/mail/MailApp.cpp b/src/apps/mail/MailApp.cpp index f1a471ea30..6bfd80a864 100644 --- a/src/apps/mail/MailApp.cpp +++ b/src/apps/mail/MailApp.cpp @@ -122,8 +122,7 @@ TMailApp::TMailApp() fAutoMarkRead = true; fSignature = (char*)malloc(strlen(B_TRANSLATE("None")) + 1); strcpy(fSignature, B_TRANSLATE("None")); - fReplyPreamble = (char*)malloc(1); - fReplyPreamble[0] = '\0'; + fReplyPreamble = strdup(B_TRANSLATE("%e wrote:%b")); fMailWindowFrame.Set(0, 0, 0, 0); fSignatureWindowFrame.Set(6, TITLE_BAR_HEIGHT, 6 + kSigWidth, diff --git a/src/apps/mail/MailWindow.cpp b/src/apps/mail/MailWindow.cpp index ec9511feb8..257ef2e498 100644 --- a/src/apps/mail/MailWindow.cpp +++ b/src/apps/mail/MailWindow.cpp @@ -2053,8 +2053,6 @@ TMailWindow::CopyMessage(entry_ref *ref, TMailWindow *src) void TMailWindow::Reply(entry_ref *ref, TMailWindow *window, uint32 type) { - const char *notImplementedString = ""; - fRepliedMail = *ref; SetOriginatingWindow(window); @@ -2105,79 +2103,27 @@ TMailWindow::Reply(entry_ref *ref, TMailWindow *window, uint32 type) // create preamble string - BString replyPreamble = fApp->ReplyPreamble(); + BString preamble = fApp->ReplyPreamble(); - char preamble[1024]; - const char* from = replyPreamble.String(); - char* to = preamble; + BString name; + mail->GetName(&name); + if (name.Length() <= 0) + name = B_TRANSLATE("(Name unavailable)"); - while (*from) { - if (*from == '%') { - // insert special content - int32 length; + BString address(mail->From()); + if (address.Length() <= 0) + address = B_TRANSLATE("(Address unavailable)"); - switch (*++from) { - case 'n': // full name - { - BString fullName(mail->From()); - if (fullName.Length() <= 0) - fullName = "No-From-Address-Available"; - - extract_address_name(fullName); - length = fullName.Length(); - memcpy(to, fullName.String(), length); - to += length; - break; - } - - case 'e': // eMail address - { - const char *address = mail->From(); - if (address == NULL) - address = ""; - length = strlen(address); - memcpy(to, address, length); - to += length; - break; - } - - case 'd': // date - { - const char *date = mail->Date(); - if (date == NULL) - date = "No-Date-Available"; - length = strlen(date); - memcpy(to, date, length); - to += length; - break; - } - - // ToDo: parse stuff! - case 'f': // first name - case 'l': // last name - length = strlen(notImplementedString); - memcpy(to, notImplementedString, length); - to += length; - break; - - default: // Sometimes a % is just a %. - *to++ = *from; - } - } else if (*from == '\\') { - switch (*++from) { - case 'n': - *to++ = '\n'; - break; - - default: - *to++ = *from; - } - } else - *to++ = *from; - - from++; - } - *to = '\0'; + BString date(mail->Date()); + if (date.Length() <= 0) + date = B_TRANSLATE("(Date unavailable)"); + + preamble.ReplaceAll("%n", name); + preamble.ReplaceAll("%e", address); + preamble.ReplaceAll("%d", date); + preamble.ReplaceAll("%b", "\n"); + preamble.ReplaceAll("\\n", "\n"); + // backwards compatability with older settings // insert (if selection) or load (if whole mail) message text into text view @@ -2216,7 +2162,7 @@ TMailWindow::Reply(entry_ref *ref, TMailWindow *window, uint32 type) } fContentView->fTextView->GoToLine(0); - if (strlen(preamble) > 0) + if (preamble.Length() > 0) fContentView->fTextView->Insert(preamble); } else { fContentView->fTextView->LoadMessage(mail, true, preamble); diff --git a/src/apps/mail/Prefs.cpp b/src/apps/mail/Prefs.cpp index 708787de2c..5b5d0f652f 100644 --- a/src/apps/mail/Prefs.cpp +++ b/src/apps/mail/Prefs.cpp @@ -484,8 +484,12 @@ TPrefsWindow::MessageReceived(BMessage* msg) } BTextView *text = fReplyPreamble->TextView(); - // To do: insert at selection point rather than at the end. - text->Insert(text->TextLength(), item->Label(), 2); + int32 selectionStart; + int32 selectionEnd; + text->GetSelection(&selectionStart, &selectionEnd); + if (selectionStart != selectionEnd) + text->Delete(selectionStart, selectionEnd); + text->Insert(item->Label(), 2); } case P_SIG: free(*fNewSignature); @@ -677,29 +681,21 @@ TPrefsWindow::_BuildReplyToMenu(int32 account) BMenu* TPrefsWindow::_BuildReplyPreambleMenu() { - const char *substitutes[] = { -/* To do: Not yet working, leave out for 2.0.0 beta 4: - "%f - First name", - "%l - Last name", -*/ - B_TRANSLATE("%n - Full name"), - B_TRANSLATE("%e - E-mail address"), - B_TRANSLATE("%d - Date"), - "", - B_TRANSLATE("\\n - Newline"), - NULL - }; - BMenu *menu = new BMenu(B_EMPTY_STRING); - for (int32 i = 0; substitutes[i]; i++) { - if (*substitutes[i] == '\0') { - menu->AddSeparatorItem(); - } else { - menu->AddItem(new BMenuItem(substitutes[i], - new BMessage(P_REPLY_PREAMBLE))); - } - } + menu->AddItem(new BMenuItem(B_TRANSLATE("%n - Full name"), + new BMessage(P_REPLY_PREAMBLE))); + + menu->AddItem(new BMenuItem(B_TRANSLATE("%e - E-mail address"), + new BMessage(P_REPLY_PREAMBLE))); + + menu->AddItem(new BMenuItem(B_TRANSLATE("%d - Date"), + new BMessage(P_REPLY_PREAMBLE))); + + menu->AddSeparatorItem(); + + menu->AddItem(new BMenuItem(B_TRANSLATE("%b - Line break"), + new BMessage(P_REPLY_PREAMBLE))); return menu; }