fix for #20405 - change Organization, Identity Name and FullName to be unicode, using new unicode prefs

r=rhp
This commit is contained in:
alecf%netscape.com 1999-12-02 03:11:52 +00:00
Родитель bc0a4a876a
Коммит 560a14a5da
7 изменённых файлов: 177 добавлений и 55 удалений

Просмотреть файл

@ -85,6 +85,14 @@ interface nsIMsgAccountManager : nsISupports {
*/
readonly attribute nsISupportsArray allServers;
/**
* hack alert
* these carry over from nsMsgMailSession
* I'm keeping them here to make it easy to kill them later
*/
readonly attribute nsIMsgIdentity currentIdentity;
readonly attribute nsIMsgIncomingServer currentServer;
/* summary of summary files folder cache */
readonly attribute nsIMsgFolderCache folderCache;
/*

Просмотреть файл

@ -44,10 +44,10 @@ interface nsIMsgIdentity : nsISupports {
*overriding display name for this identity. if this pref is not set
* then this will return some composed string from the fullname and email
*/
attribute string identityName;
attribute wstring identityName;
/* user's full name, i.e. John Doe */
attribute string fullName;
attribute wstring fullName;
/* user's e-mail address, i.e. john@doe.com */
attribute string email;
@ -56,7 +56,7 @@ interface nsIMsgIdentity : nsISupports {
attribute string replyTo;
/* optional organization */
attribute string organization;
attribute wstring organization;
/* should we compose with HTML by default? */
attribute boolean composeHtml;

Просмотреть файл

@ -193,7 +193,23 @@ static NS_DEFINE_CID(kMsgFolderCacheCID, NS_MSGFOLDERCACHE_CID);
DEST_ID->MACRO_SETTER(""); \
} \
else { \
DEST_ID->MACRO_SETTER(NS_CONST_CAST(char*,(const char*)macro_oldStr)); \
DEST_ID->MACRO_SETTER(macro_oldStr); \
} \
}
static const PRUnichar unicharEmptyString[] = { (PRUnichar)'\0' };
#define COPY_IDENTITY_WSTR_VALUE(SRC_ID,DEST_ID,MACRO_GETTER,MACRO_SETTER) \
{ \
nsXPIDLString macro_oldStr; \
nsresult macro_rv; \
macro_rv = SRC_ID->MACRO_GETTER(getter_Copies(macro_oldStr)); \
if (NS_FAILED(macro_rv)) return macro_rv; \
if (!macro_oldStr) { \
DEST_ID->MACRO_SETTER(unicharEmptyString); \
} \
else { \
DEST_ID->MACRO_SETTER(macro_oldStr); \
} \
}
@ -223,6 +239,17 @@ static NS_DEFINE_CID(kMsgFolderCacheCID, NS_MSGFOLDERCACHE_CID);
} \
}
#define MIGRATE_SIMPLE_WSTR_PREF(PREFNAME,MACRO_OBJECT,MACRO_METHOD) \
{ \
nsresult macro_rv; \
PRUnichar *macro_oldStr = nsnull; \
macro_rv = m_prefs->CopyUnicharPref(PREFNAME, &macro_oldStr); \
if (NS_SUCCEEDED(macro_rv)) { \
MACRO_OBJECT->MACRO_METHOD(macro_oldStr); \
PR_FREEIF(macro_oldStr); \
} \
}
#define MIGRATE_SIMPLE_INT_PREF(PREFNAME,MACRO_OBJECT,MACRO_METHOD) \
{ \
nsresult macro_rv; \
@ -407,7 +434,7 @@ nsMsgAccountManager::getPrefService()
if (!m_prefs)
rv = nsServiceManager::GetService(kPrefServiceCID,
nsCOMTypeInfo<nsIPref>::GetIID(),
NS_GET_IID(nsIPref),
(nsISupports**)&m_prefs);
if (NS_FAILED(rv)) return rv;
@ -719,7 +746,7 @@ nsresult nsMsgAccountManager::GetFolderCache(nsIMsgFolderCache* *aFolderCache)
{
rv = nsComponentManager::CreateInstance(kMsgFolderCacheCID,
NULL,
nsCOMTypeInfo<nsIMsgFolderCache>::GetIID(),
NS_GET_IID(nsIMsgFolderCache),
getter_AddRefs(m_msgFolderCache));
if (NS_FAILED(rv))
return rv;
@ -1360,9 +1387,9 @@ nsresult
nsMsgAccountManager::MigrateIdentity(nsIMsgIdentity *identity)
{
MIGRATE_SIMPLE_STR_PREF(PREF_4X_MAIL_IDENTITY_USEREMAIL,identity,SetEmail)
MIGRATE_SIMPLE_STR_PREF(PREF_4X_MAIL_IDENTITY_USERNAME,identity,SetFullName)
MIGRATE_SIMPLE_WSTR_PREF(PREF_4X_MAIL_IDENTITY_USERNAME,identity,SetFullName)
MIGRATE_SIMPLE_STR_PREF(PREF_4X_MAIL_IDENTITY_REPLY_TO,identity,SetReplyTo)
MIGRATE_SIMPLE_STR_PREF(PREF_4X_MAIL_IDENTITY_ORGANIZATION,identity,SetOrganization)
MIGRATE_SIMPLE_WSTR_PREF(PREF_4X_MAIL_IDENTITY_ORGANIZATION,identity,SetOrganization)
MIGRATE_SIMPLE_BOOL_PREF(PREF_4X_MAIL_COMPOSE_HTML,identity,SetComposeHtml)
MIGRATE_SIMPLE_STR_PREF(PREF_4X_MAIL_DEFAULT_DRAFTS,identity,SetDraftFolder)
CONVERT_4X_URI(identity,DEFAULT_4X_DRAFTS_FOLDER_NAME,GetDraftFolder,SetDraftFolder)
@ -1464,7 +1491,7 @@ nsMsgAccountManager::Convert4XUri(const char *old_uri, const char *default_folde
nsXPIDLCString hostname;
nsXPIDLCString username;
rv = nsComponentManager::CreateInstance(kStandardUrlCID, nsnull, nsCOMTypeInfo<nsIURL>::GetIID(), getter_AddRefs(url));
rv = nsComponentManager::CreateInstance(kStandardUrlCID, nsnull, NS_GET_IID(nsIURL), getter_AddRefs(url));
if (NS_FAILED(rv)) return rv;
rv = url->SetSpec(old_uri);
@ -2139,8 +2166,8 @@ nsMsgAccountManager::CopyIdentity(nsIMsgIdentity *srcIdentity, nsIMsgIdentity *d
COPY_IDENTITY_BOOL_VALUE(srcIdentity,destIdentity,GetComposeHtml,SetComposeHtml)
COPY_IDENTITY_STR_VALUE(srcIdentity,destIdentity,GetEmail,SetEmail)
COPY_IDENTITY_STR_VALUE(srcIdentity,destIdentity,GetReplyTo,SetReplyTo)
COPY_IDENTITY_STR_VALUE(srcIdentity,destIdentity,GetFullName,SetFullName)
COPY_IDENTITY_STR_VALUE(srcIdentity,destIdentity,GetOrganization,SetOrganization)
COPY_IDENTITY_WSTR_VALUE(srcIdentity,destIdentity,GetFullName,SetFullName)
COPY_IDENTITY_WSTR_VALUE(srcIdentity,destIdentity,GetOrganization,SetOrganization)
COPY_IDENTITY_STR_VALUE(srcIdentity,destIdentity,GetDraftFolder,SetDraftFolder)
COPY_IDENTITY_STR_VALUE(srcIdentity,destIdentity,GetStationaryFolder,SetStationaryFolder)
@ -2901,3 +2928,29 @@ nsMsgAccountManager::findServersForIdentity(nsISupports *element, void *aData)
return PR_TRUE;
}
NS_IMETHODIMP
nsMsgAccountManager::GetCurrentIdentity(nsIMsgIdentity** id)
{
NS_ENSURE_ARG_POINTER(id);
nsCOMPtr<nsISupportsArray> identities;
nsresult rv = GetAllIdentities(getter_AddRefs(identities));
if (NS_FAILED(rv)) return rv;
return identities->QueryElementAt(0, NS_GET_IID(nsIMsgIdentity),
(void **)id);
}
NS_IMETHODIMP
nsMsgAccountManager::GetCurrentServer(nsIMsgIncomingServer ** server)
{
NS_ENSURE_ARG_POINTER(server);
nsCOMPtr<nsISupportsArray> servers;
nsresult rv = GetAllServers(getter_AddRefs(servers));
if (NS_FAILED(rv)) return rv;
return servers->QueryElementAt(0, NS_GET_IID(nsIMsgIncomingServer),
(void **)server);
}

Просмотреть файл

@ -129,6 +129,24 @@ nsMsgIdentity::setBoolPref(const char *prefname,
return rv;
}
nsresult
nsMsgIdentity::getUnicharPref(const char *prefname,
PRUnichar **val)
{
nsresult rv = getPrefService();
if (NS_FAILED(rv)) return rv;
char *fullPrefName = getPrefName(m_identityKey, prefname);
rv = m_prefs->CopyUnicharPref(fullPrefName, val);
PR_Free(fullPrefName);
if (NS_FAILED(rv))
rv = getDefaultUnicharPref(prefname, val);
return rv;
}
nsresult
nsMsgIdentity::getCharPref(const char *prefname,
char **val)
@ -146,6 +164,24 @@ nsMsgIdentity::getCharPref(const char *prefname,
return rv;
}
nsresult
nsMsgIdentity::getDefaultUnicharPref(const char *prefname,
PRUnichar **val)
{
nsresult rv = getPrefService();
if (NS_FAILED(rv)) return rv;
char *fullPrefName = getDefaultPrefName(prefname);
rv = m_prefs->CopyUnicharPref(fullPrefName, val);
PR_Free(fullPrefName);
if (NS_FAILED(rv)) {
*val = nsnull; // null is ok to return here
rv = NS_OK;
}
return rv;
}
nsresult
nsMsgIdentity::getDefaultCharPref(const char *prefname,
char **val)
@ -164,6 +200,23 @@ nsMsgIdentity::getDefaultCharPref(const char *prefname,
return rv;
}
nsresult
nsMsgIdentity::setUnicharPref(const char *prefname,
const PRUnichar *val)
{
nsresult rv = getPrefService();
if (NS_FAILED(rv)) return rv;
rv = NS_OK;
char *prefName = getPrefName(m_identityKey, prefname);
if (val)
rv = m_prefs->SetUnicharPref(prefName, val);
else
m_prefs->ClearUserPref(prefName);
PR_Free(prefName);
return rv;
}
nsresult
nsMsgIdentity::setCharPref(const char *prefname,
const char *val)
@ -239,34 +292,36 @@ nsMsgIdentity::SetKey(const char* identityKey)
}
nsresult
nsMsgIdentity::GetIdentityName(char **idName) {
nsMsgIdentity::GetIdentityName(PRUnichar **idName) {
if (!idName) return NS_ERROR_NULL_POINTER;
*idName = nsnull;
nsresult rv = getCharPref("identityName",idName);
nsresult rv = getUnicharPref("identityName",idName);
if (NS_FAILED(rv)) return rv;
// there's probably a better way of doing this
// thats unicode friendly?
if (!(*idName)) {
nsXPIDLCString fullName;
nsXPIDLString fullName;
rv = GetFullName(getter_Copies(fullName));
if (NS_FAILED(rv)) return rv;
nsXPIDLCString email;
rv = GetEmail(getter_Copies(email));
if (NS_FAILED(rv)) return rv;
*idName = PR_smprintf("%s <%s>", (const char*)fullName,
(const char*)email);
nsAutoString str;
str += (const PRUnichar*)fullName;
str += "<";
str += (const char*)email;
str += ">";
*idName = str.ToNewUnicode();
rv = NS_OK;
}
return rv;
}
nsresult nsMsgIdentity::SetIdentityName(const char *idName) {
return setCharPref("identityName", idName);
nsresult nsMsgIdentity::SetIdentityName(const PRUnichar *idName) {
return setUnicharPref("identityName", idName);
}
NS_IMETHODIMP
@ -322,10 +377,10 @@ NS_IMPL_GETSET(nsMsgIdentity, VCard, nsIMsgVCard*, m_vCard);
NS_IMPL_GETTER_STR(nsMsgIdentity::GetKey, m_identityKey);
NS_IMPL_IDPREF_STR(FullName, "fullName");
NS_IMPL_IDPREF_WSTR(FullName, "fullName");
NS_IMPL_IDPREF_STR(Email, "useremail");
NS_IMPL_IDPREF_STR(ReplyTo, "reply_to");
NS_IMPL_IDPREF_STR(Organization, "organization");
NS_IMPL_IDPREF_WSTR(Organization, "organization");
NS_IMPL_IDPREF_BOOL(ComposeHtml, "compose_html");
NS_IMPL_IDPREF_BOOL(AttachVCard, "attach_vcard");
NS_IMPL_IDPREF_BOOL(AttachSignature, "attach_signature");

Просмотреть файл

@ -54,10 +54,15 @@ protected:
nsresult getPrefService();
char *getPrefName(const char *identityKey, const char *pref);
char *getDefaultPrefName(const char *pref);
nsresult getCharPref(const char *pref, char **);
nsresult getDefaultCharPref(const char *pref, char **);
nsresult setCharPref(const char *pref, const char *);
nsresult getUnicharPref(const char *pref, PRUnichar **);
nsresult getDefaultUnicharPref(const char *pref, PRUnichar **);
nsresult setUnicharPref(const char *pref, const PRUnichar *);
nsresult getBoolPref(const char *pref, PRBool *);
nsresult getDefaultBoolPref(const char *pref, PRBool *);
nsresult setBoolPref(const char *pref, PRBool);
@ -81,6 +86,18 @@ nsMsgIdentity::Set##_postfix(const char *value) \
return setCharPref(_prefname, value);\
}
#define NS_IMPL_IDPREF_WSTR(_postfix, _prefname)\
NS_IMETHODIMP \
nsMsgIdentity::Get##_postfix(PRUnichar **retval)\
{ \
return getUnicharPref(_prefname, retval); \
} \
NS_IMETHODIMP \
nsMsgIdentity::Set##_postfix(const PRUnichar *value)\
{ \
return setUnicharPref(_prefname, value);\
}
#define NS_IMPL_IDPREF_BOOL(_postfix, _prefname)\
NS_IMETHODIMP \
nsMsgIdentity::Get##_postfix(PRBool *retval) \

Просмотреть файл

@ -455,9 +455,9 @@ nsresult nsMsgCompose::_SendMsg(MSG_DeliverMode deliverMode,
{
// Pref values are supposed to be stored as UTF-8, so no conversion
nsXPIDLCString email;
nsXPIDLCString fullName;
nsXPIDLString fullName;
nsXPIDLCString replyTo;
nsXPIDLCString organization;
nsXPIDLString organization;
identity->GetEmail(getter_Copies(email));
identity->GetFullName(getter_Copies(fullName));
@ -470,12 +470,16 @@ nsresult nsMsgCompose::_SendMsg(MSG_DeliverMode deliverMode,
nsnull,
nsCOMTypeInfo<nsIMsgHeaderParser>::GetIID(),
getter_AddRefs(parser));
if (parser)
parser->MakeFullAddress(nsnull, NS_CONST_CAST(char*, (const char *)fullName),
NS_CONST_CAST(char*, (const char *)email),
&sender);
if (parser) {
// convert to UTF8 before passing to MakeFullAddress
nsAutoString fullNameStr(fullName);
char *fullNameUTF8 = fullNameStr.ToNewUTF8String();
parser->MakeFullAddress(nsnull, fullNameUTF8, email, &sender);
nsCRT::free(fullNameUTF8);
}
if (!sender)
m_compFields->SetFrom(NS_CONST_CAST(char*, (const char *)email));
m_compFields->SetFrom(email);
else
m_compFields->SetFrom(sender);
PR_FREEIF(sender);
@ -483,8 +487,8 @@ nsresult nsMsgCompose::_SendMsg(MSG_DeliverMode deliverMode,
//Set the reply-to only if the user have not specified one in the message
const char * reply = m_compFields->GetReplyTo();
if (reply == nsnull || *reply == 0)
m_compFields->SetReplyTo(NS_CONST_CAST(char*, (const char *)replyTo));
m_compFields->SetOrganization(NS_CONST_CAST(char*, (const char *)organization));
m_compFields->SetReplyTo(replyTo);
m_compFields->SetOrganization(organization);
#if defined(DEBUG_ducarroz) || defined(DEBUG_seth_)
printf("----------------------------\n");

Просмотреть файл

@ -38,7 +38,7 @@
#include "nsIMsgSend.h"
#include "nsIPref.h"
#include "nscore.h"
#include "nsIMsgMailSession.h"
#include "nsIMsgAccountManager.h"
#include "nsINetSupportDialogService.h"
#include "nsIAppShellService.h"
#include "nsAppShellCIDs.h"
@ -89,7 +89,6 @@ static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
static NS_DEFINE_CID(kSmtpServiceCID, NS_SMTPSERVICE_CID);
static NS_DEFINE_CID(kFileLocatorCID, NS_FILELOCATOR_CID);
static NS_DEFINE_CID(kEventQueueCID, NS_EVENTQUEUE_CID);
static NS_DEFINE_CID(kCMsgMailSessionCID, NS_MSGMAILSESSION_CID);
static NS_DEFINE_CID(kMsgComposeCID, NS_MSGCOMPOSE_CID);
static NS_DEFINE_CID(kMsgCompFieldsCID, NS_MSGCOMPFIELDS_CID);
static NS_DEFINE_CID(kMsgSendCID, NS_MSGSEND_CID);
@ -286,24 +285,17 @@ GetHackIdentity()
{
nsresult rv;
NS_WITH_SERVICE(nsIMsgMailSession, mailSession, kCMsgMailSessionCID, &rv);
if (NS_FAILED(rv))
NS_WITH_SERVICE(nsIMsgAccountManager, accountManager,
NS_MSGACCOUNTMANAGER_PROGID, &rv);
if (NS_FAILED(rv)) return nsnull;
{
printf("Failure on Mail Session Init!\n");
printf("Failure on AccountManager Init!\n");
return nsnull;
}
nsCOMPtr<nsIMsgIdentity> identity = nsnull;
nsCOMPtr<nsIMsgAccountManager> accountManager;
rv = mailSession->GetAccountManager(getter_AddRefs(accountManager));
if (NS_FAILED(rv))
{
printf("Failure getting account Manager!\n");
return nsnull;
}
rv = mailSession->GetCurrentIdentity(getter_AddRefs(identity));
rv = accountManager->GetCurrentIdentity(getter_AddRefs(identity));
if (NS_FAILED(rv))
{
printf("Failure getting Identity!\n");
@ -370,14 +362,7 @@ int main(int argc, char *argv[])
printf("Failed on reading user prefs!\n");
exit(rv);
}
NS_WITH_SERVICE(nsIMsgMailSession, mailSession, kCMsgMailSessionCID, &rv);
if (NS_FAILED(rv) || !mailSession)
{
printf("Failure on Mail Session Init!\n");
return rv;
}
nsIMsgIdentity *identity;
identity = GetHackIdentity();
SendOperationListener *sendListener = nsnull;
@ -391,7 +376,7 @@ int main(int argc, char *argv[])
if (NS_SUCCEEDED(rv) && pMsgCompFields)
{
char *aEmail = nsnull;
char *aFullName = nsnull;
PRUnichar *aFullName = nsnull;
char addr[256];
char subject[256];