Bug 249530 add an option 'send anyway' when there are characters not covered by the selected encoding (r=neil, sr=bienvenu)

git-svn-id: svn://10.0.0.236/trunk@169728 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
jshin%mailaps.org
2005-02-24 04:54:00 +00:00
parent bd776dc434
commit ac543392fb
11 changed files with 164 additions and 26 deletions

View File

@@ -1822,9 +1822,24 @@ function GenericSendMessage( msgType )
{
var dlgTitle = sComposeMsgsBundle.getString("initErrorDlogTitle");
var dlgText = sComposeMsgsBundle.getString("12553"); // NS_ERROR_MSG_MULTILINGUAL_SEND
if (!gPromptService.confirm(window, dlgTitle, dlgText))
return;
fallbackCharset.value = "UTF-8";
var result3 = gPromptService.confirmEx(window, dlgTitle, dlgText,
(gPromptService.BUTTON_TITLE_IS_STRING * gPromptService.BUTTON_POS_0) +
(gPromptService.BUTTON_TITLE_IS_STRING * gPromptService.BUTTON_POS_1) +
(gPromptService.BUTTON_TITLE_CANCEL * gPromptService.BUTTON_POS_2),
sComposeMsgsBundle.getString('sendInUTF8'),
sComposeMsgsBundle.getString('sendAnyway'),
null, null, {value:0});
switch(result3)
{
case 0:
fallbackCharset.value = "UTF-8";
break;
case 1: // send anyway
msgCompFields.needToCheckCharset = false;
break;
case 2: // cancel
return;
}
}
if (fallbackCharset &&
fallbackCharset.value && fallbackCharset.value != "")

View File

@@ -184,7 +184,10 @@ noIdentities=You don't have any email identities yet. Create one with the Accou
12551=Posting message...
## @name NS_ERROR_MSG_MULTILINGUAL_SEND
12553=The message you composed contains characters not found in the selected Character Encoding. While you can choose a different Character Encoding, it is usually safe to use Unicode for mail. To send or save it as Unicode (UTF-8), click OK. To return to the Composer window where you can choose a different Character Encoding, click Cancel.
12553=The message you composed contains characters not found in the selected Character Encoding. While you can choose a different Character Encoding by returning to the composer window, it is usually safe to use Unicode (UTF-8) for mail. If you just send in the current Character Encoding, be aware that those not covered by the current Character Encoding will be turned to question marks and illegible by the recipient.
sendInUTF8=Send in UTF-8
sendAnyway=Send anyway
## @name NS_ERROR_NNTP_NO_CROSS_POSTING
12554=You can only send a message to one news server at a time.

View File

@@ -41,7 +41,7 @@
#include "nsISupportsArray.idl"
[scriptable, uuid(3E89CAE3-BD2D-11d2-8293-000000000000)]
[scriptable, uuid(ABEFCAD2-47E9-4363-A3AA-8A76E7D96CE4)]
interface nsIMsgCompFields : nsISupports {
attribute AString from;
@@ -108,6 +108,14 @@ interface nsIMsgCompFields : nsISupports {
// Check if the composing mail headers can be converted to a mail charset.
boolean checkCharsetConversion(out string fallbackCharset);
/**
* Indicates whether we need to check if the current |DocumentCharset|
* can represent all the characters in the message body. It should be
* initialized to true and set to false when 'Send Anyway' is selected
* by a user. (bug 249530)
*/
attribute boolean needToCheckCharset;
attribute nsISupports securityInfo;
};

View File

@@ -1770,9 +1770,24 @@ function GenericSendMessage( msgType )
{
var dlgTitle = sComposeMsgsBundle.getString("initErrorDlogTitle");
var dlgText = sComposeMsgsBundle.getString("12553"); // NS_ERROR_MSG_MULTILINGUAL_SEND
if (!gPromptService.confirm(window, dlgTitle, dlgText))
return;
fallbackCharset.value = "UTF-8";
var result3 = gPromptService.confirmEx(window, dlgTitle, dlgText,
(gPromptService.BUTTON_TITLE_IS_STRING * gPromptService.BUTTON_POS_0) +
(gPromptService.BUTTON_TITLE_IS_STRING * gPromptService.BUTTON_POS_1) +
(gPromptService.BUTTON_TITLE_CANCEL * gPromptService.BUTTON_POS_2),
sComposeMsgsBundle.getString('sendInUTF8'),
sComposeMsgsBundle.getString('sendAnyway'),
null, null, {value:0});
switch(result3)
{
case 0:
fallbackCharset.value = "UTF-8";
break;
case 1: // send anyway
msgCompFields.needToCheckCharset = false;
break;
case 2: // cancel
return;
}
}
if (fallbackCharset &&
fallbackCharset.value && fallbackCharset.value != "")

View File

@@ -184,7 +184,10 @@ noIdentities=You don't have any email identities yet. Create one with the Accou
12551=Posting message...
## @name NS_ERROR_MSG_MULTILINGUAL_SEND
12553=The message you composed contains characters not found in the selected Character Encoding. While you can choose a different Character Encoding, it is usually safe to use Unicode for mail. To send or save it as Unicode (UTF-8), click OK. To return to the Composer window where you can choose a different Character Encoding, click Cancel.
12553=The message you composed contains characters not found in the selected Character Encoding. While you can choose a different Character Encoding by returning to the composer window, it is usually safe to use Unicode (UTF-8) for mail. If you just send in the current Character Encoding, be aware that those not covered by the current Character Encoding will be turned to question marks and illegible by the recipient.
sendInUTF8=Send in UTF-8
sendAnyway=Send anyway
## @name NS_ERROR_NNTP_NO_CROSS_POSTING
12554=You can only send a message to one news server at a time.

View File

@@ -69,6 +69,7 @@ nsMsgCompFields::nsMsgCompFields()
m_returnReceipt = PR_FALSE;
m_receiptHeaderType = nsIMsgMdnGenerator::eDntType;
m_bodyIsAsciiOnly = PR_FALSE;
m_needToCheckCharset = PR_TRUE;
// Get the default charset from pref, use this as a mail charset.
nsXPIDLString charset;
@@ -777,3 +778,16 @@ NS_IMETHODIMP nsMsgCompFields::CheckCharsetConversion(char **fallbackCharset, PR
return NS_OK;
}
NS_IMETHODIMP nsMsgCompFields::GetNeedToCheckCharset(PRBool *_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
*_retval = m_needToCheckCharset;
return NS_OK;
}
NS_IMETHODIMP nsMsgCompFields::SetNeedToCheckCharset(PRBool aCheck)
{
m_needToCheckCharset = aCheck;
return NS_OK;
}

View File

@@ -179,6 +179,7 @@ protected:
PRBool m_bodyIsAsciiOnly;
PRInt32 m_receiptHeaderType; /* receipt header type */
nsCString m_DefaultCharacterSet;
PRBool m_needToCheckCharset;
nsCOMPtr<nsISupports> mSecureCompFields;
};

View File

@@ -986,13 +986,22 @@ NS_IMETHODIMP nsMsgCompose::SendMsg(MSG_DeliverMode deliverMode, nsIMsgIdentity
// charset. ask whether to convert to UTF-8 or go back to reset
// charset with a wider repertoire. (bug 233361) (if not mapi blind send)
if (NS_ERROR_UENC_NOMAPPING == rv && m_editor) {
PRBool sendInUTF8;
rv = nsMsgAskBooleanQuestionByID(prompt,
NS_ERROR_MSG_MULTILINGUAL_SEND, &sendInUTF8);
if (!sendInUTF8)
return NS_ERROR_MSG_MULTILINGUAL_SEND;
CopyUTF16toUTF8(msgBody.get(), outCString);
m_compFields->SetCharacterSet("UTF-8");
PRBool needToCheckCharset;
m_compFields->GetNeedToCheckCharset(&needToCheckCharset);
if (needToCheckCharset) {
PRInt32 answer = nsMsgAskAboutUncoveredCharacters(prompt);
switch (answer) {
case 0 : // convert to UTF-8
CopyUTF16toUTF8(msgBody.get(), outCString);
m_compFields->SetCharacterSet("UTF-8");
break;
case 1 : // send anyway
break;
case 2 : // return to the editor
default :
return NS_ERROR_MSG_MULTILINGUAL_SEND;
}
}
}
// re-label to the fallback charset
else if (fallbackCharset)

View File

@@ -152,3 +152,59 @@ nsMsgAskBooleanQuestionByString(nsIPrompt * aPrompt, const PRUnichar * msg, PRBo
return NS_OK;
}
// returns 0 (send in UTF-8) in case of error
PRInt32
nsMsgAskAboutUncoveredCharacters(nsIPrompt * aPrompt)
{
PRInt32 result;
nsCOMPtr<nsIPrompt> dialog = aPrompt;
if (!dialog)
{
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
if (wwatch)
wwatch->GetNewPrompter(0, getter_AddRefs(dialog));
}
NS_ENSURE_TRUE(dialog, 0);
nsCOMPtr<nsIStringBundleService> bundleService =
do_GetService(NS_STRINGBUNDLE_CONTRACTID);
NS_ENSURE_TRUE(bundleService, 0);
nsCOMPtr<nsIStringBundle> composeBundle;
bundleService->CreateBundle("chrome://messenger/locale/messengercompose/"
"composeMsgs.properties",
getter_AddRefs(composeBundle));
NS_ENSURE_TRUE(composeBundle, 0);
nsXPIDLString title;
nsXPIDLString msg;
nsXPIDLString button0;
nsXPIDLString button1;
composeBundle->
GetStringFromName(NS_LITERAL_STRING("initErrorDlogTitle").get(),
getter_Copies(title));
composeBundle->
GetStringFromID(NS_ERROR_GET_CODE(NS_ERROR_MSG_MULTILINGUAL_SEND),
getter_Copies(msg));
composeBundle->
GetStringFromName(NS_LITERAL_STRING("sendInUTF8").get(),
getter_Copies(button0));
composeBundle->
GetStringFromName(NS_LITERAL_STRING("sendAnyway").get(),
getter_Copies(button1));
nsresult rv = dialog->
ConfirmEx(title, msg,
nsIPrompt::BUTTON_TITLE_IS_STRING * nsIPrompt::BUTTON_POS_0 +
nsIPrompt::BUTTON_TITLE_IS_STRING * nsIPrompt::BUTTON_POS_1 +
nsIPrompt::BUTTON_TITLE_CANCEL * nsIPrompt::BUTTON_POS_2 +
nsIPrompt::BUTTON_POS_0_DEFAULT,
button0, button1, nsnull, nsnull, 0, &result);
NS_ENSURE_SUCCESS(rv, 0);
return result;
}

View File

@@ -49,5 +49,6 @@ nsresult nsMsgDisplayMessageByID(nsIPrompt * aPrompt, PRInt32 msgID, const
nsresult nsMsgDisplayMessageByString(nsIPrompt * aPrompt, const PRUnichar * msg, const PRUnichar * windowTitle = nsnull);
nsresult nsMsgAskBooleanQuestionByID(nsIPrompt * aPrompt, PRInt32 msgID, PRBool *answer, const PRUnichar * windowTitle = nsnull);
nsresult nsMsgAskBooleanQuestionByString(nsIPrompt * aPrompt, const PRUnichar * msg, PRBool *answer, const PRUnichar * windowTitle = nsnull);
PRInt32 nsMsgAskAboutUncoveredCharacters(nsIPrompt * aPrompt);
#endif /* _nsMsgPrompts_H_ */

View File

@@ -1766,17 +1766,26 @@ nsMsgComposeAndSend::GetBodyFromEditor()
getter_Copies(outCString), getter_Copies(fallbackCharset));
if (NS_ERROR_UENC_NOMAPPING == rv) {
PRBool sendInUTF8;
nsCOMPtr<nsIPrompt> prompt;
GetDefaultPrompt(getter_AddRefs(prompt));
rv = nsMsgAskBooleanQuestionByID(prompt, NS_ERROR_MSG_MULTILINGUAL_SEND,
&sendInUTF8);
if (!sendInUTF8) {
Recycle(bodyText);
return NS_ERROR_MSG_MULTILINGUAL_SEND;
PRBool needToCheckCharset;
mCompFields->GetNeedToCheckCharset(&needToCheckCharset);
printf("need to check charset=%d\n", needToCheckCharset);
if (needToCheckCharset) {
nsCOMPtr<nsIPrompt> prompt;
GetDefaultPrompt(getter_AddRefs(prompt));
PRInt32 answer = nsMsgAskAboutUncoveredCharacters(prompt);
switch (answer) {
case 0 : // convert to UTF-8
CopyUTF16toUTF8(bodyText, outCString);
mCompFields->SetCharacterSet("UTF-8"); // tag as UTF-8
break;
case 1 : // send anyway
break;
case 2 : // return to the editor
default :
Recycle(bodyText);
return NS_ERROR_MSG_MULTILINGUAL_SEND;
}
}
CopyUTF16toUTF8(bodyText, outCString);
mCompFields->SetCharacterSet("UTF-8"); // tag as UTF-8
}
// re-label to the fallback charset
else if (fallbackCharset)
@@ -2994,6 +3003,10 @@ nsMsgComposeAndSend::InitCompositionFields(nsMsgCompFields *fields)
mCompFields->SetSecurityInfo(secInfo);
PRBool needToCheckCharset;
fields->GetNeedToCheckCharset(&needToCheckCharset);
mCompFields->SetNeedToCheckCharset(needToCheckCharset);
// Check the fields for legitimacy...
//
if ( m_deliver_mode != nsMsgSaveAsDraft && m_deliver_mode != nsMsgSaveAsTemplate )