fix default account names r=alecf 29579
git-svn-id: svn://10.0.0.236/trunk@76715 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -49,6 +49,12 @@ interface nsIMsgIncomingServer : nsISupports {
|
||||
*/
|
||||
attribute wstring prettyName;
|
||||
|
||||
/**
|
||||
* helper function to construct the pretty name in a server type
|
||||
* specific way - e.g., mail for foo@test.com, news on news.mozilla.org
|
||||
*/
|
||||
readonly attribute wstring constructedPrettyName;
|
||||
|
||||
/**
|
||||
* hostname of the server
|
||||
*/
|
||||
|
||||
@@ -506,30 +506,11 @@ nsMsgIncomingServer::GetPrettyName(PRUnichar **retval) {
|
||||
nsresult rv = GetUnicharValue("name", getter_Copies(val));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsAutoString prettyName(val);
|
||||
|
||||
// if there's no name, then just return the hostname
|
||||
if (prettyName.IsEmpty()) {
|
||||
|
||||
nsXPIDLCString username;
|
||||
rv = GetUsername(getter_Copies(username));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if ((const char*)username &&
|
||||
PL_strcmp((const char*)username, "")!=0) {
|
||||
prettyName.AssignWithConversion(username);
|
||||
prettyName.AppendWithConversion(" on ");
|
||||
}
|
||||
|
||||
nsXPIDLCString hostname;
|
||||
rv = GetHostName(getter_Copies(hostname));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
prettyName.AppendWithConversion(hostname);
|
||||
}
|
||||
|
||||
*retval = prettyName.ToNewUnicode();
|
||||
|
||||
if (nsCRT::strlen(val) == 0)
|
||||
return GetConstructedPrettyName(retval);
|
||||
else
|
||||
*retval = nsCRT::strdup(val);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -547,6 +528,35 @@ nsMsgIncomingServer::SetPrettyName(const PRUnichar *value)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
// construct the pretty name to show to the user if they haven't
|
||||
// specified one. This should be overridden for news and mail.
|
||||
NS_IMETHODIMP
|
||||
nsMsgIncomingServer::GetConstructedPrettyName(PRUnichar **retval)
|
||||
{
|
||||
|
||||
nsXPIDLCString username;
|
||||
nsAutoString prettyName;
|
||||
nsresult rv = GetUsername(getter_Copies(username));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if ((const char*)username &&
|
||||
PL_strcmp((const char*)username, "")!=0) {
|
||||
prettyName.AssignWithConversion(username);
|
||||
prettyName.AppendWithConversion(" on ");
|
||||
}
|
||||
|
||||
nsXPIDLCString hostname;
|
||||
rv = GetHostName(getter_Copies(hostname));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
prettyName.AppendWithConversion(hostname);
|
||||
|
||||
*retval = prettyName.ToNewUnicode();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgIncomingServer::ToString(PRUnichar** aResult) {
|
||||
nsString servername; servername.AssignWithConversion("[nsIMsgIncomingServer: ");
|
||||
|
||||
@@ -323,3 +323,6 @@
|
||||
## @loc None
|
||||
5056=There are no new messages on the server.
|
||||
|
||||
## @name IMAP_DEFAULT_ACCOUNT_NAME
|
||||
## @loc None
|
||||
5057=Mail for %S
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
|
||||
#include "nsIMAPHostSessionList.h"
|
||||
#include "nsImapIncomingServer.h"
|
||||
#include "nsIMsgAccountManager.h"
|
||||
#include "nsIMsgIdentity.h"
|
||||
#include "nsIImapUrl.h"
|
||||
#include "nsIUrlListener.h"
|
||||
#include "nsIEventQueue.h"
|
||||
@@ -159,6 +161,73 @@ NS_IMETHODIMP nsImapIncomingServer::SetKey(const char * aKey) // override nsMsg
|
||||
return rv;
|
||||
}
|
||||
|
||||
// construct the pretty name to show to the user if they haven't
|
||||
// specified one. This should be overridden for news and mail.
|
||||
NS_IMETHODIMP
|
||||
nsImapIncomingServer::GetConstructedPrettyName(PRUnichar **retval)
|
||||
{
|
||||
|
||||
nsXPIDLCString username;
|
||||
nsXPIDLCString hostName;
|
||||
nsresult rv;
|
||||
|
||||
NS_WITH_SERVICE(nsIMsgAccountManager, accountManager,
|
||||
NS_MSGACCOUNTMANAGER_PROGID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsISupportsArray> identities;
|
||||
rv = accountManager->GetIdentitiesForServer(this,
|
||||
getter_AddRefs(identities));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIMsgIdentity> identity;
|
||||
|
||||
rv = identities->QueryElementAt(0, NS_GET_IID(nsIMsgIdentity),
|
||||
(void **)getter_AddRefs(identity));
|
||||
|
||||
nsAutoString emailAddress;
|
||||
|
||||
if (NS_SUCCEEDED(rv) && identity)
|
||||
{
|
||||
nsXPIDLCString identityEmailAddress;
|
||||
identity->GetEmail(getter_Copies(identityEmailAddress));
|
||||
emailAddress.AssignWithConversion(identityEmailAddress);
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = GetUsername(getter_Copies(username));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = GetHostName(getter_Copies(hostName));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if ((const char*)username && (const char *) hostName &&
|
||||
PL_strcmp((const char*)username, "")!=0) {
|
||||
emailAddress.AssignWithConversion(username);
|
||||
emailAddress.AppendWithConversion("@");
|
||||
emailAddress.AppendWithConversion(hostName);
|
||||
|
||||
}
|
||||
}
|
||||
rv = GetStringBundle();
|
||||
if (m_stringBundle)
|
||||
{
|
||||
nsXPIDLString prettyName;
|
||||
const PRUnichar *formatStrings[] =
|
||||
{
|
||||
emailAddress.GetUnicode(),
|
||||
};
|
||||
rv = m_stringBundle->FormatStringFromID(IMAP_DEFAULT_ACCOUNT_NAME,
|
||||
formatStrings, 1,
|
||||
getter_Copies(prettyName));
|
||||
*retval = nsCRT::strdup(prettyName);
|
||||
return NS_OK;
|
||||
}
|
||||
else
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsImapIncomingServer::GetLocalStoreType(char ** type)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(type);
|
||||
@@ -1488,11 +1557,9 @@ static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
|
||||
|
||||
#define IMAP_MSGS_URL "chrome://messenger/locale/imapMsgs.properties"
|
||||
|
||||
NS_IMETHODIMP nsImapIncomingServer::GetImapStringByID(PRInt32 aMsgId, PRUnichar **aString)
|
||||
nsresult nsImapIncomingServer::GetStringBundle()
|
||||
{
|
||||
nsAutoString resultString; resultString.AssignWithConversion("???");
|
||||
nsresult res = NS_OK;
|
||||
|
||||
nsresult res;
|
||||
if (!m_stringBundle)
|
||||
{
|
||||
char* propertyURL = NULL;
|
||||
@@ -1507,6 +1574,15 @@ NS_IMETHODIMP nsImapIncomingServer::GetImapStringByID(PRInt32 aMsgId, PRUnichar
|
||||
res = sBundleService->CreateBundle(propertyURL, locale, getter_AddRefs(m_stringBundle));
|
||||
}
|
||||
}
|
||||
return (m_stringBundle) ? NS_OK : res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImapIncomingServer::GetImapStringByID(PRInt32 aMsgId, PRUnichar **aString)
|
||||
{
|
||||
nsAutoString resultString; resultString.AssignWithConversion("???");
|
||||
nsresult res = NS_OK;
|
||||
|
||||
GetStringBundle();
|
||||
if (m_stringBundle)
|
||||
{
|
||||
PRUnichar *ptrv = nsnull;
|
||||
|
||||
@@ -61,6 +61,7 @@ public:
|
||||
NS_IMETHOD PerformBiff();
|
||||
NS_IMETHOD PerformExpand(nsIMsgWindow *aMsgWindow);
|
||||
NS_IMETHOD CloseCachedConnections();
|
||||
NS_IMETHOD GetConstructedPrettyName(PRUnichar **retval);
|
||||
|
||||
protected:
|
||||
nsresult GetFolder(const char* name, nsIMsgFolder** pFolder);
|
||||
@@ -72,6 +73,7 @@ protected:
|
||||
PRBool NoDescendentsAreVerified(nsIFolder *parentFolder);
|
||||
PRBool AllDescendentsAreNoSelect(nsIFolder *parentFolder);
|
||||
|
||||
nsresult GetStringBundle();
|
||||
private:
|
||||
nsresult SubscribeToFolder(const PRUnichar *aName, PRBool subscribe);
|
||||
nsresult CreateImapConnection (nsIEventQueue* aEventQueue,
|
||||
|
||||
@@ -88,5 +88,5 @@ NS_END_EXTERN_C
|
||||
#define IMAP_NET_TIMEOUT_ERROR 5054
|
||||
#define IMAP_MOVE_FOLDER_TO_TRASH 5055
|
||||
#define IMAP_NO_NEW_MESSAGES 5056
|
||||
|
||||
#define IMAP_DEFAULT_ACCOUNT_NAME 5057
|
||||
#endif /* _nsImapStringBundle_H__ */
|
||||
|
||||
Reference in New Issue
Block a user