зеркало из https://github.com/mozilla/gecko-dev.git
Fix for bug 37697. Add support of preferFormat and html and plaintext domains list. R=chuang, SR=mscott,bienvenu
This commit is contained in:
Родитель
02b9f094e8
Коммит
f50ca26bd5
|
@ -30,7 +30,7 @@ interface nsIAddrDatabase;
|
|||
#include "nsVoidArray.h"
|
||||
%}
|
||||
|
||||
[uuid(97448252-F189-11d4-A422-001083003D0C)]
|
||||
[scriptable, uuid(97448252-F189-11d4-A422-001083003D0C)]
|
||||
interface nsIAbPreferMailFormat {
|
||||
const unsigned long unknown = 0;
|
||||
const unsigned long plaintext = 1;
|
||||
|
|
|
@ -108,37 +108,40 @@ interface nsIMsgCompose : nsISupports {
|
|||
in nsIMsgIdentity identity);
|
||||
|
||||
/* ... */
|
||||
void CloseWindow();
|
||||
void CloseWindow();
|
||||
|
||||
/*
|
||||
AttachmentPrettyName will return only the leafName if the it's a file URL.
|
||||
It will also convert the filename to the right character set.
|
||||
This UI utility function should probably go into it's own class
|
||||
*/
|
||||
wstring AttachmentPrettyName(in wstring url);
|
||||
/*
|
||||
AttachmentPrettyName will return only the leafName if the it's a file URL.
|
||||
It will also convert the filename to the right character set.
|
||||
This UI utility function should probably go into it's own class
|
||||
*/
|
||||
wstring AttachmentPrettyName(in wstring url);
|
||||
|
||||
/*
|
||||
...
|
||||
CheckAndPopulateRecipients will perform several task:
|
||||
1) if populateMailList is true, it will populate mailing presents in the compose field
|
||||
2) if returnNoHTMLRecipients is true, build a list of non HTML recipient
|
||||
3) return the lowest common format prefered by recipients (unknow, plaintext or html)
|
||||
*/
|
||||
wstring CheckAndPopulateRecipients(in boolean populateMailList, in boolean returnNoHTMLRecipients);
|
||||
unsigned long CheckAndPopulateRecipients(in boolean populateMailList, in boolean returnNonHTMLRecipients, out wstring nonHTMLRecipients);
|
||||
|
||||
/* GetNoHtmlNewsgroups: if null is passed as recipient, the function will automatically
|
||||
looks for newsgroups stored in compose fields
|
||||
*/
|
||||
wstring GetNoHtmlNewsgroups(in wstring newsgroups);
|
||||
|
||||
/* bodyConvertible: The level of "convertibility" to plaintext
|
||||
* @return a value from nsIMsgCompConvertible.
|
||||
*/
|
||||
long bodyConvertible();
|
||||
/* GetNoHtmlNewsgroups: if null is passed as recipient, the function will automatically
|
||||
looks for newsgroups stored in compose fields
|
||||
*/
|
||||
wstring GetNoHtmlNewsgroups(in wstring newsgroups);
|
||||
|
||||
/* bodyConvertible: The level of "convertibility" to plaintext
|
||||
* @return a value from nsIMsgCompConvertible.
|
||||
*/
|
||||
long bodyConvertible();
|
||||
|
||||
/* SetSignature: will replace the curr.
|
||||
*/
|
||||
void SetSignature(in nsIMsgIdentity identity);
|
||||
/* SetSignature: will replace the curr.
|
||||
*/
|
||||
void SetSignature(in nsIMsgIdentity identity);
|
||||
|
||||
/* ResetNodeEventHandlers: Temporary API to go around bug 26528. THis API will be removed when bug 26528 is fixed.
|
||||
*/
|
||||
void ResetNodeEventHandlers(in nsIDOMNode node);
|
||||
/* ResetNodeEventHandlers: Temporary API to go around bug 26528. THis API will be removed when bug 26528 is fixed.
|
||||
*/
|
||||
void ResetNodeEventHandlers(in nsIDOMNode node);
|
||||
|
||||
/* ... */
|
||||
attribute nsIEditorShell editor;
|
||||
|
|
|
@ -23,6 +23,7 @@ var msgCompSendFormat = Components.interfaces.nsIMsgCompSendFormat;
|
|||
var msgCompConvertible = Components.interfaces.nsIMsgCompConvertible;
|
||||
var msgCompType = Components.interfaces.nsIMsgCompType;
|
||||
var msgCompFormat = Components.interfaces.nsIMsgCompFormat;
|
||||
var abPreferMailFormat = Components.interfaces.nsIAbPreferMailFormat;
|
||||
|
||||
var accountManagerContractID = "@mozilla.org/messenger/account-manager;1";
|
||||
var accountManager = Components.classes[accountManagerContractID].getService(Components.interfaces.nsIMsgAccountManager);
|
||||
|
@ -1614,7 +1615,7 @@ function DetermineHTMLAction(convertible)
|
|||
if (! msgCompose.composeHTML)
|
||||
{
|
||||
try {
|
||||
msgCompose.CheckAndPopulateRecipients(true, false);
|
||||
msgCompose.CheckAndPopulateRecipients(true, false, null);
|
||||
} catch(ex) {}
|
||||
return msgCompSendFormat.PlainText;
|
||||
}
|
||||
|
@ -1623,18 +1624,20 @@ function DetermineHTMLAction(convertible)
|
|||
{
|
||||
//Well, before we ask, see if we can figure out what to do for ourselves
|
||||
|
||||
var noHtmlRecipients;
|
||||
var noHtmlRecipients = new String("");
|
||||
var noHtmlnewsgroups;
|
||||
var preferFormat;
|
||||
|
||||
//Check the address book for the HTML property for each recipient
|
||||
try {
|
||||
noHtmlRecipients = msgCompose.CheckAndPopulateRecipients(true, true);
|
||||
preferFormat = msgCompose.CheckAndPopulateRecipients(true, true, noHtmlRecipients);
|
||||
} catch(ex)
|
||||
{
|
||||
var msgCompFields = msgCompose.compFields;
|
||||
noHtmlRecipients = msgCompFields.GetTo() + "," + msgCompFields.GetCc() + "," + msgCompFields.GetBcc();
|
||||
preferFormat = abPreferMailFormat.unknown;
|
||||
}
|
||||
dump("DetermineHTMLAction: noHtmlRecipients are " + noHtmlRecipients + "\n");
|
||||
dump("DetermineHTMLAction: preferFormat = " + preferFormat + ", noHtmlRecipients are " + noHtmlRecipients + "\n");
|
||||
|
||||
//Check newsgroups now...
|
||||
try {
|
||||
|
@ -1651,15 +1654,22 @@ function DetermineHTMLAction(convertible)
|
|||
|
||||
if (noHtmlnewsgroups == "")
|
||||
{
|
||||
//See if a preference has been set to tell us what to do. Note that we do not honor that
|
||||
//preference for newsgroups. Only for e-mail addresses.
|
||||
var action = prefs.GetIntPref("mail.default_html_action");
|
||||
switch (action)
|
||||
switch (preferFormat)
|
||||
{
|
||||
case msgCompSendFormat.PlainText :
|
||||
case msgCompSendFormat.HTML :
|
||||
case msgCompSendFormat.Both :
|
||||
return action;
|
||||
case abPreferMailFormat.plaintext :
|
||||
return msgCompSendFormat.PlainText;
|
||||
|
||||
default :
|
||||
//See if a preference has been set to tell us what to do. Note that we do not honor that
|
||||
//preference for newsgroups. Only for e-mail addresses.
|
||||
var action = prefs.GetIntPref("mail.default_html_action");
|
||||
switch (action)
|
||||
{
|
||||
case msgCompSendFormat.PlainText :
|
||||
case msgCompSendFormat.HTML :
|
||||
case msgCompSendFormat.Both :
|
||||
return action;
|
||||
}
|
||||
}
|
||||
}
|
||||
return msgCompSendFormat.AskUser;
|
||||
|
@ -1670,7 +1680,7 @@ function DetermineHTMLAction(convertible)
|
|||
else
|
||||
{
|
||||
try {
|
||||
msgCompose.CheckAndPopulateRecipients(true, false);
|
||||
msgCompose.CheckAndPopulateRecipients(true, false, null);
|
||||
} catch(ex) {}
|
||||
}
|
||||
|
||||
|
|
|
@ -2392,20 +2392,23 @@ nsresult nsMsgCompose::GetMailListAddresses(nsString& name, nsISupportsArray* ma
|
|||
}
|
||||
|
||||
|
||||
nsresult nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, PRBool returnNoHTMLRecipients, PRUnichar **_retval)
|
||||
NS_IMETHODIMP nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, PRBool returnNonHTMLRecipients, PRUnichar **nonHTMLRecipients, PRUint32 *_retval)
|
||||
{
|
||||
#define MAX_OF_RECIPIENT_ARRAY 3
|
||||
|
||||
if (!populateMailList && (!returnNoHTMLRecipients || !_retval))
|
||||
if (returnNonHTMLRecipients && !nonHTMLRecipients || !_retval)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
if (_retval)
|
||||
*_retval = nsnull;
|
||||
PRInt32 i;
|
||||
PRInt32 j;
|
||||
PRInt32 k;
|
||||
|
||||
if (nonHTMLRecipients)
|
||||
*nonHTMLRecipients = nsnull;
|
||||
if (_retval)
|
||||
*_retval = nsIAbPreferMailFormat::unknown;
|
||||
|
||||
/* First, build an array with original recipients */
|
||||
nsCOMPtr<nsISupportsArray> recipientsList[MAX_OF_RECIPIENT_ARRAY];
|
||||
|
||||
|
@ -2589,16 +2592,10 @@ nsresult nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, PRBoo
|
|||
}
|
||||
else
|
||||
{
|
||||
PRUint32 preferFormat = nsIAbPreferMailFormat::unknown;
|
||||
rv = existingCard->GetPreferMailFormat(&preferFormat);
|
||||
newRecipient->mPreferFormat = nsIAbPreferMailFormat::unknown;
|
||||
rv = existingCard->GetPreferMailFormat(&newRecipient->mPreferFormat);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
if (preferFormat == nsIAbPreferMailFormat::html)
|
||||
newRecipient->mAcceptHtml = PR_TRUE;
|
||||
else
|
||||
newRecipient->mAcceptHtml = PR_FALSE;
|
||||
newRecipient->mProcessed = PR_TRUE;
|
||||
}
|
||||
recipient->mProcessed = PR_TRUE;
|
||||
}
|
||||
rv = recipientsList[i]->InsertElementAt(newRecipient, j + 1);
|
||||
NS_RELEASE(newRecipient);
|
||||
|
@ -2620,16 +2617,10 @@ nsresult nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, PRBoo
|
|||
rv = abDataBase->GetCardForEmailAddress(abDirectory, emailStr, getter_AddRefs(existingCard));
|
||||
if (NS_SUCCEEDED(rv) && existingCard)
|
||||
{
|
||||
PRUint32 preferFormat;
|
||||
rv = existingCard->GetPreferMailFormat(&preferFormat);
|
||||
recipient->mPreferFormat = nsIAbPreferMailFormat::unknown;
|
||||
rv = existingCard->GetPreferMailFormat(&recipient->mPreferFormat);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
if (preferFormat == nsIAbPreferMailFormat::html)
|
||||
recipient->mAcceptHtml = PR_TRUE;
|
||||
else
|
||||
recipient->mAcceptHtml = PR_FALSE;
|
||||
recipient->mProcessed = PR_TRUE;
|
||||
}
|
||||
recipient->mProcessed = PR_TRUE;
|
||||
}
|
||||
else
|
||||
stillNeedToSearch = PR_TRUE;
|
||||
|
@ -2643,10 +2634,26 @@ nsresult nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, PRBoo
|
|||
}
|
||||
}
|
||||
|
||||
/* Finally return the list of non HTML recipient if requested and/or rebuilt the recipient field*/
|
||||
/* Finally return the list of non HTML recipient if requested and/or rebuilt the recipient field.
|
||||
Also, check for domain preference when preferFormat is unknown
|
||||
*/
|
||||
nsAutoString recipientsStr;
|
||||
nsAutoString nonHtmlRecipientsStr;
|
||||
nsAutoString plaintextDomains;
|
||||
nsAutoString htmlDomains;
|
||||
nsAutoString domain;
|
||||
|
||||
nsCOMPtr<nsIPref> prefs (do_GetService(NS_PREF_CONTRACTID));
|
||||
if (prefs)
|
||||
{
|
||||
nsXPIDLString str;
|
||||
prefs->CopyUnicharPref("mailnews.plaintext_domains", getter_Copies(str));
|
||||
plaintextDomains = str;
|
||||
prefs->CopyUnicharPref("mailnews.html_domains", getter_Copies(str));
|
||||
htmlDomains = str;
|
||||
}
|
||||
|
||||
*_retval = -1;
|
||||
for (i = 0; i < MAX_OF_RECIPIENT_ARRAY; i ++)
|
||||
{
|
||||
recipientsStr.SetLength(0);
|
||||
|
@ -2656,7 +2663,41 @@ nsresult nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, PRBoo
|
|||
{
|
||||
nsMsgRecipient* recipient = NS_STATIC_CAST(nsMsgRecipient*, recipientsList[i]->ElementAt(j));
|
||||
if (recipient)
|
||||
{
|
||||
{
|
||||
/* if we don't have a prefer format for a recipient, check the domain in case we have a format defined for it */
|
||||
if (recipient->mPreferFormat == nsIAbPreferMailFormat::unknown &&
|
||||
(plaintextDomains.Length() || htmlDomains.Length()))
|
||||
{
|
||||
PRInt32 atPos = recipient->mEmail.FindChar('@');
|
||||
if (atPos >= 0)
|
||||
{
|
||||
recipient->mEmail.Right(domain, recipient->mEmail.Length() - atPos - 1);
|
||||
if (plaintextDomains.Find(domain, PR_TRUE) >= 0)
|
||||
recipient->mPreferFormat = nsIAbPreferMailFormat::plaintext;
|
||||
else
|
||||
if (htmlDomains.Find(domain, PR_TRUE) >= 0)
|
||||
recipient->mPreferFormat = nsIAbPreferMailFormat::html;
|
||||
}
|
||||
}
|
||||
|
||||
/* setup return value */
|
||||
switch (recipient->mPreferFormat)
|
||||
{
|
||||
case nsIAbPreferMailFormat::html :
|
||||
if (*_retval == -1)
|
||||
*_retval = nsIAbPreferMailFormat::html;
|
||||
break;
|
||||
|
||||
case nsIAbPreferMailFormat::plaintext :
|
||||
if (*_retval == -1 || *_retval == nsIAbPreferMailFormat::html)
|
||||
*_retval = nsIAbPreferMailFormat::plaintext;
|
||||
break;
|
||||
|
||||
default :
|
||||
*_retval = nsIAbPreferMailFormat::unknown;
|
||||
break;
|
||||
}
|
||||
|
||||
if (populateMailList)
|
||||
{
|
||||
if (! recipientsStr.IsEmpty())
|
||||
|
@ -2664,7 +2705,7 @@ nsresult nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, PRBoo
|
|||
recipientsStr.Append(recipient->mAddress);
|
||||
}
|
||||
|
||||
if (returnNoHTMLRecipients && !recipient->mAcceptHtml)
|
||||
if (returnNonHTMLRecipients && recipient->mPreferFormat != nsIAbPreferMailFormat::html)
|
||||
{
|
||||
if (! nonHtmlRecipientsStr.IsEmpty())
|
||||
nonHtmlRecipientsStr.AppendWithConversion(',');
|
||||
|
@ -2688,8 +2729,8 @@ nsresult nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, PRBoo
|
|||
}
|
||||
}
|
||||
|
||||
if (returnNoHTMLRecipients)
|
||||
*_retval = nonHtmlRecipientsStr.ToNewUnicode();
|
||||
if (returnNonHTMLRecipients)
|
||||
*nonHTMLRecipients = nonHtmlRecipientsStr.ToNewUnicode();
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
@ -3183,16 +3224,16 @@ NS_INTERFACE_MAP_BEGIN(nsMsgRecipient)
|
|||
NS_INTERFACE_MAP_END
|
||||
|
||||
nsMsgRecipient::nsMsgRecipient() :
|
||||
mAcceptHtml(PR_FALSE),
|
||||
mPreferFormat(nsIAbPreferMailFormat::unknown),
|
||||
mProcessed(PR_FALSE)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsMsgRecipient::nsMsgRecipient(nsString fullAddress, nsString email, PRBool acceptHtml, PRBool processed) :
|
||||
nsMsgRecipient::nsMsgRecipient(nsString fullAddress, nsString email, PRUint32 preferFormat, PRBool processed) :
|
||||
mAddress(fullAddress),
|
||||
mEmail(email),
|
||||
mAcceptHtml(acceptHtml),
|
||||
mPreferFormat(preferFormat),
|
||||
mProcessed(processed)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "nsIMimeHeaders.h"
|
||||
#include "nsIBaseWindow.h"
|
||||
#include "nsIAbDirectory.h"
|
||||
#include "nsIAbCard.h"
|
||||
|
||||
// Forward declares
|
||||
class QuotingOutputStreamListener;
|
||||
|
@ -246,15 +247,16 @@ class nsMsgRecipient : public nsISupports
|
|||
{
|
||||
public:
|
||||
nsMsgRecipient();
|
||||
nsMsgRecipient(nsString fullAddress, nsString email, PRBool acceptHtml = PR_FALSE, PRBool processed = PR_FALSE);
|
||||
nsMsgRecipient(nsString fullAddress, nsString email, PRUint32 preferFormat = nsIAbPreferMailFormat::unknown,
|
||||
PRBool processed = PR_FALSE);
|
||||
virtual ~nsMsgRecipient();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
public:
|
||||
nsString mAddress; /* full email address (name + email) */
|
||||
nsString mEmail; /* email address only */
|
||||
PRBool mAcceptHtml;
|
||||
nsString mAddress; /* full email address (name + email) */
|
||||
nsString mEmail; /* email address only */
|
||||
PRUint32 mPreferFormat; /* nsIAbPreferMailFormat:: unknown, plaintext or html */
|
||||
PRBool mProcessed;
|
||||
};
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче