#34355, for a new pop server, the copies and folders prefs should point to the pop server,
not the local server.

#22889, #37464, news article urls not displaying, and they causing autosubscribe to happen.

#36661, fix problems with autosubscribe / article url problem, if they happen before
we migrated and if there is no accounts.

#8216,  a successful cancelling of a news posting removes message from thread pane

r=alecf
This commit is contained in:
sspitzer%netscape.com 2000-05-23 02:38:00 +00:00
Родитель fdebe98e3b
Коммит 2eda7c7b6c
15 изменённых файлов: 385 добавлений и 164 удалений

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

@ -263,7 +263,7 @@ function createAccount(accountData)
var identity = am.createIdentity();
/* new nntp identities should use plain text by default
* we wan't that GNKSA (The Good Net-Keeping Seal of Approval) */
* we want that GNKSA (The Good Net-Keeping Seal of Approval) */
if (server.type == "nntp") {
identity.composeHtml = false;
}

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

@ -98,43 +98,8 @@ nsSubscribableServer::SetAsSubscribedInSubscribeDS(const char *aURI)
NS_IMETHODIMP
nsSubscribableServer::UpdateSubscribedInSubscribeDS()
{
#ifdef DEBUG_SUBSCRIBE
printf("UpdateSubscribedInSubscribeDS()");
#endif
nsresult rv;
nsCOMPtr<nsIEnumerator> subFolders;
nsCOMPtr<nsIFolder> rootFolder;
nsCOMPtr<nsIFolder> currFolder;
rv = mIncomingServer->GetRootFolder(getter_AddRefs(rootFolder));
if (NS_FAILED(rv)) return rv;
rv = rootFolder->GetSubFolders(getter_AddRefs(subFolders));
if (NS_FAILED(rv)) return rv;
nsAdapterEnumerator *simpleEnumerator = new nsAdapterEnumerator(subFolders);
if (simpleEnumerator == nsnull) return NS_ERROR_OUT_OF_MEMORY;
PRBool moreFolders;
while (NS_SUCCEEDED(simpleEnumerator->HasMoreElements(&moreFolders)) && moreFolders) {
nsCOMPtr<nsISupports> child;
rv = simpleEnumerator->GetNext(getter_AddRefs(child));
if (NS_SUCCEEDED(rv) && child) {
currFolder = do_QueryInterface(child, &rv);
if (NS_SUCCEEDED(rv) && currFolder) {
nsXPIDLCString uri;
rv = currFolder->GetURI(getter_Copies(uri));
if (NS_SUCCEEDED(rv)) {
rv = SetAsSubscribedInSubscribeDS((const char *)uri);
}
}
}
}
delete simpleEnumerator;
return NS_OK;
NS_ASSERTION(PR_FALSE,"override this.");
return NS_ERROR_FAILURE;
}

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

@ -1860,6 +1860,7 @@ NS_IMETHODIMP
nsImapIncomingServer::OnStopRunningUrl(nsIURI *url, nsresult exitCode)
{
nsresult rv;
rv = UpdateSubscribedInSubscribeDS();
if (NS_FAILED(rv)) return rv;
@ -1898,9 +1899,10 @@ nsImapIncomingServer::SetAsSubscribedInSubscribeDS(const char *aURI)
NS_IMETHODIMP
nsImapIncomingServer::UpdateSubscribedInSubscribeDS()
{
NS_ASSERTION(mInner,"not initialized");
if (!mInner) return NS_ERROR_FAILURE;
return mInner->UpdateSubscribedInSubscribeDS();
#ifdef DEBUG_sspitzer
printf("for imap, do this when we populate\n");
#endif
return NS_OK;
}
NS_IMETHODIMP

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

@ -30,6 +30,7 @@ interface nsIUrlListener;
[scriptable, uuid(ee87cc60-1dd1-11b2-b25a-ff87320f212d)]
interface nsILocalMailIncomingServer : nsISupports {
void createDefaultMailboxes(in nsIFileSpec path);
void setFlagsOnDefaultMailboxes();
nsIURI getNewMail(in nsIMsgWindow aMsgWindow, in nsIUrlListener aUrlListener);
};

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

@ -562,7 +562,8 @@ NS_IMETHODIMP nsMsgLocalMailFolder::AddSubfolder(nsAutoString *name,
|| name->CompareWithConversion("Outbox", PR_TRUE) == 0)
flags |= MSG_FOLDER_FLAG_QUEUE;
#if 0
//These should probably be read in from a preference. Hacking in here for the moment.
// the logic for this has been moved into
// SetFlagsOnDefaultMailboxes()
else if(name->Compare("Sent", PR_TRUE) == 0)
folder->SetFlag(MSG_FOLDER_FLAG_SENTMAIL);
else if(name->Compare("Drafts", PR_TRUE) == 0)
@ -672,13 +673,16 @@ nsMsgLocalMailFolder::GetSubFolders(nsIEnumerator* *result)
newFlags |= (MSG_FOLDER_FLAG_DIRECTORY | MSG_FOLDER_FLAG_ELIDED);
SetFlag(newFlags);
PRBool createdDefaultMailboxes = PR_FALSE;
nsCOMPtr<nsILocalMailIncomingServer> localMailServer;
if (isServer) {
nsCOMPtr<nsIMsgIncomingServer> server;
rv = GetServer(getter_AddRefs(server));
if (NS_FAILED(rv)) return rv;
if (!server) return NS_ERROR_FAILURE;
nsCOMPtr<nsILocalMailIncomingServer> localMailServer = do_QueryInterface(server, &rv);
localMailServer = do_QueryInterface(server, &rv);
if (NS_FAILED(rv)) return rv;
if (!localMailServer) return NS_ERROR_FAILURE;
@ -686,12 +690,22 @@ nsMsgLocalMailFolder::GetSubFolders(nsIEnumerator* *result)
rv = NS_NewFileSpecWithSpec(path, getter_AddRefs(spec));
if (NS_FAILED(rv)) return rv;
// first create the folders on disk (as empty files)
rv = localMailServer->CreateDefaultMailboxes(spec);
if (NS_FAILED(rv)) return rv;
createdDefaultMailboxes = PR_TRUE;
}
// now, discover those folders
rv = CreateSubFolders(path);
if (NS_FAILED(rv)) return rv;
// must happen after CreateSubFolders, or the folders won't exist.
if (createdDefaultMailboxes && localMailServer) {
rv = localMailServer->SetFlagsOnDefaultMailboxes();
if (NS_FAILED(rv)) return rv;
}
}
UpdateSummaryTotals(PR_FALSE);

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

@ -57,6 +57,64 @@ nsNoIncomingServer::GetLocalStoreType(char **type)
return NS_OK;
}
NS_IMETHODIMP
nsNoIncomingServer::SetFlagsOnDefaultMailboxes()
{
nsresult rv;
nsCOMPtr<nsIFolder> rootFolder;
rv = GetRootFolder(getter_AddRefs(rootFolder));
if (NS_FAILED(rv)) return rv;
if (!rootFolder) return NS_ERROR_FAILURE;
nsCOMPtr <nsIFolder> folder;
nsCOMPtr <nsIMsgFolder> msgFolder;
// notice, no Inbox
rv = rootFolder->FindSubFolder("Sent", getter_AddRefs(folder));
if (NS_FAILED(rv)) return rv;
if (!folder) return NS_ERROR_FAILURE;
msgFolder = do_QueryInterface(folder);
if (!msgFolder) return NS_ERROR_FAILURE;
rv = msgFolder->SetFlag(MSG_FOLDER_FLAG_SENTMAIL);
if (NS_FAILED(rv)) return rv;
rv = rootFolder->FindSubFolder("Drafts", getter_AddRefs(folder));
if (NS_FAILED(rv)) return rv;
if (!folder) return NS_ERROR_FAILURE;
msgFolder = do_QueryInterface(folder);
if (!msgFolder) return NS_ERROR_FAILURE;
rv = msgFolder->SetFlag(MSG_FOLDER_FLAG_DRAFTS);
if (NS_FAILED(rv)) return rv;
rv = rootFolder->FindSubFolder("Templates", getter_AddRefs(folder));
if (NS_FAILED(rv)) return rv;
if (!folder) return NS_ERROR_FAILURE;
msgFolder = do_QueryInterface(folder);
if (!msgFolder) return NS_ERROR_FAILURE;
rv = msgFolder->SetFlag(MSG_FOLDER_FLAG_TEMPLATES);
if (NS_FAILED(rv)) return rv;
rv = rootFolder->FindSubFolder("Trash", getter_AddRefs(folder));
if (NS_FAILED(rv)) return rv;
if (!folder) return NS_ERROR_FAILURE;
msgFolder = do_QueryInterface(folder);
if (!msgFolder) return NS_ERROR_FAILURE;
rv = msgFolder->SetFlag(MSG_FOLDER_FLAG_TRASH);
if (NS_FAILED(rv)) return rv;
rv = rootFolder->FindSubFolder("Unsent Messages", getter_AddRefs(folder));
if (NS_FAILED(rv)) return rv;
if (!folder) return NS_ERROR_FAILURE;
msgFolder = do_QueryInterface(folder);
if (!msgFolder) return NS_ERROR_FAILURE;
rv = msgFolder->SetFlag(MSG_FOLDER_FLAG_QUEUE);
if (NS_FAILED(rv)) return rv;
return NS_OK;
}
NS_IMETHODIMP nsNoIncomingServer::CreateDefaultMailboxes(nsIFileSpec *path)
{
nsresult rv;
@ -65,8 +123,8 @@ NS_IMETHODIMP nsNoIncomingServer::CreateDefaultMailboxes(nsIFileSpec *path)
// todo, use a string bundle for these
// notice, no Inbox
// notice, no Inbox
rv = path->AppendRelativeUnixPath("Trash");
if (NS_FAILED(rv)) return rv;
rv = path->Exists(&exists);

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

@ -158,6 +158,69 @@ NS_IMETHODIMP nsPop3IncomingServer::PerformBiff()
}
NS_IMETHODIMP nsPop3IncomingServer::SetFlagsOnDefaultMailboxes()
{
nsresult rv;
nsCOMPtr<nsIFolder> rootFolder;
rv = GetRootFolder(getter_AddRefs(rootFolder));
if (NS_FAILED(rv)) return rv;
if (!rootFolder) return NS_ERROR_FAILURE;
nsCOMPtr <nsIFolder> folder;
nsCOMPtr<nsIMsgFolder> msgFolder;
rv = rootFolder->FindSubFolder("Inbox", getter_AddRefs(folder));
if (NS_FAILED(rv)) return rv;
if (!folder) return NS_ERROR_FAILURE;
msgFolder = do_QueryInterface(folder);
if (!msgFolder) return NS_ERROR_FAILURE;
rv = msgFolder->SetFlag(MSG_FOLDER_FLAG_INBOX);
if (NS_FAILED(rv)) return rv;
rv = rootFolder->FindSubFolder("Sent", getter_AddRefs(folder));
if (NS_FAILED(rv)) return rv;
if (!folder) return NS_ERROR_FAILURE;
msgFolder = do_QueryInterface(folder);
if (!msgFolder) return NS_ERROR_FAILURE;
rv = msgFolder->SetFlag(MSG_FOLDER_FLAG_SENTMAIL);
if (NS_FAILED(rv)) return rv;
rv = rootFolder->FindSubFolder("Drafts", getter_AddRefs(folder));
if (NS_FAILED(rv)) return rv;
if (!folder) return NS_ERROR_FAILURE;
msgFolder = do_QueryInterface(folder);
if (!msgFolder) return NS_ERROR_FAILURE;
rv = msgFolder->SetFlag(MSG_FOLDER_FLAG_DRAFTS);
if (NS_FAILED(rv)) return rv;
rv = rootFolder->FindSubFolder("Templates", getter_AddRefs(folder));
if (NS_FAILED(rv)) return rv;
if (!folder) return NS_ERROR_FAILURE;
msgFolder = do_QueryInterface(folder);
if (!msgFolder) return NS_ERROR_FAILURE;
rv = msgFolder->SetFlag(MSG_FOLDER_FLAG_TEMPLATES);
if (NS_FAILED(rv)) return rv;
rv = rootFolder->FindSubFolder("Trash", getter_AddRefs(folder));
if (NS_FAILED(rv)) return rv;
if (!folder) return NS_ERROR_FAILURE;
msgFolder = do_QueryInterface(folder);
if (!msgFolder) return NS_ERROR_FAILURE;
rv = msgFolder->SetFlag(MSG_FOLDER_FLAG_TRASH);
if (NS_FAILED(rv)) return rv;
rv = rootFolder->FindSubFolder("Unsent Messages", getter_AddRefs(folder));
if (NS_FAILED(rv)) return rv;
if (!folder) return NS_ERROR_FAILURE;
msgFolder = do_QueryInterface(folder);
if (!msgFolder) return NS_ERROR_FAILURE;
rv = msgFolder->SetFlag(MSG_FOLDER_FLAG_QUEUE);
if (NS_FAILED(rv)) return rv;
return NS_OK;
}
NS_IMETHODIMP nsPop3IncomingServer::CreateDefaultMailboxes(nsIFileSpec *path)
{
nsresult rv;

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

@ -24,12 +24,16 @@
#include "nsIMsgFolder.idl"
interface nsIMsgWindow;
interface nsINntpIncomingServer;
[scriptable, uuid(3716abe4-f6d4-11d2-86d5-004005263078)]
interface nsIMsgNewsFolder : nsISupports {
attribute string groupUsername;
attribute string groupPassword;
readonly attribute string asciiName;
readonly attribute nsINntpIncomingServer nntpServer;
string getGroupPasswordWithUI(in wstring aPromptString, in wstring aPromptTitle, in nsIMsgWindow aMsgWindow);
string getGroupUsernameWithUI(in wstring aPromptString, in wstring aPromptTitle, in nsIMsgWindow aMsgWindow);
@ -46,5 +50,5 @@ interface nsIMsgNewsFolder : nsISupports {
readonly attribute string unsubscribedNewsgroupLines;
void SetNewsrcHasChanged(in boolean newsrcHasChanged);
void updateSummaryFromNNTPInfo(in long oldest, in long youngest, in long total);
void removeMessage(in nsMsgKey key);
};

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

@ -48,6 +48,10 @@ interface nsINntpIncomingServer : nsISupports {
/* abbreviate the newsgroup names in the folder pane? */
attribute boolean abbreviate;
/* the server keeps track of all the newsgroups we are subscribed to */
void addNewsgroup(in string name);
void removeNewsgroup(in string name);
void writeNewsrcFile();
attribute boolean newsrcHasChanged;
@ -70,4 +74,5 @@ interface nsINntpIncomingServer : nsISupports {
/* used for the subscribe dialog */
void addNewsgroupToSubscribeDS(in string name);
};

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

@ -1110,9 +1110,7 @@ nsresult nsNNTPProtocol::ParseURL(nsIURI * aURL, PRBool * bValP, char ** aGroup,
Either way, there may be search data at the end.
*/
s = PL_strchr (group, '@');
if (s)
{
if (PL_strchr (group, '@') || PL_strstr(group,"%40")) {
message_id = nsUnescape(group);
group = 0;
}
@ -1133,16 +1131,10 @@ nsresult nsNNTPProtocol::ParseURL(nsIURI * aURL, PRBool * bValP, char ** aGroup,
if (message_id || group)
{
char *start;
if (message_id)
{
#ifdef DEBUG_sspitzer
/* Move past the @. */
NS_ASSERTION (s && *s == '@', "move past the @");
#endif /* DEBUG_sspitzer */
start = s;
if (message_id) {
start = PL_strchr(message_id,'@');
}
else
{
else {
start = group; /* ? group : hostAndPort; */ // mscott -- fix me...necko sloppiness on my part
}
@ -3975,21 +3967,30 @@ PRInt32 nsNNTPProtocol::DoCancel()
// XXX: todo, check rv?
}
#if defined(DEBUG_seth) || defined(DEBUG_sspitzer)
// just me for now...
// start of work for bug #8216
//
if (!m_runningURL) return NS_ERROR_FAILURE;
// delete the message from the db here.
nsMsgKey key = nsMsgKey_None;
rv = m_runningURL->GetMessageKey(&key);
NS_ASSERTION(NS_SUCCEEDED(rv), "GetMessageKey failed");
char *newsgroupname = nsnull;
rv = m_runningURL->GetNewsgroupName(&newsgroupname);
NS_ASSERTION(NS_SUCCEEDED(rv) && newsgroupname && (key != nsMsgKey_None), "need more to remove this message from the db");
if ((key != nsMsgKey_None) && (newsgroupname)) {
printf("delete %u from %s",key,newsgroupname);
if (!m_newsFolder) {
nsCAutoString folderURI = "news://";
folderURI += (const char *)m_hostName;
folderURI += "/";
nsXPIDLCString newsgroupName;
rv = m_runningURL->GetNewsgroupName(getter_Copies(newsgroupName));
if (NS_SUCCEEDED(rv) && ((const char *)newsgroupName)) {
folderURI += (const char *)newsgroupName;
rv = InitializeNewsFolderFromUri((const char *)folderURI);
}
}
NS_ASSERTION(NS_SUCCEEDED(rv) && m_newsFolder && (key != nsMsgKey_None), "need more to remove this message from the db");
if ((key != nsMsgKey_None) && (m_newsFolder)) {
rv = m_newsFolder->RemoveMessage(key);
}
#endif
}
FAIL:
@ -5030,11 +5031,20 @@ nsNNTPProtocol::SetProgressStatus(char *message)
NS_IMETHODIMP nsNNTPProtocol::GetContentType(char * *aContentType)
{
if (!aContentType) return NS_ERROR_NULL_POINTER;
if ((const char *)m_currentGroup && nsCRT::strlen((const char *)m_currentGroup)) {
*aContentType = nsCRT::strdup("x-application-newsgroup");
// if it is an article url, it has a @ or %40 in it.
if (PL_strchr((const char *)m_currentGroup,'@') || PL_strstr((const char *)m_currentGroup,"%40")) {
*aContentType = nsCRT::strdup("message/rfc822");
}
else {
*aContentType = nsCRT::strdup("x-application-newsgroup");
}
}
else {
*aContentType = nsCRT::strdup("message/rfc822");
}
if (!*aContentType) return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}

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

@ -159,16 +159,10 @@ nsMsgNewsFolder::CreateSubFolders(nsFileSpec &path)
printf("CreateSubFolders: %s = %s\n", mURI, (const char *)path);
#endif
//Are we assured this is the server for this folder?
nsCOMPtr<nsIMsgIncomingServer> server;
rv = GetServer(getter_AddRefs(server));
nsCOMPtr<nsINntpIncomingServer> nntpServer;
rv = GetNntpServer(getter_AddRefs(nntpServer));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsINntpIncomingServer> nntpServer;
rv = server->QueryInterface(NS_GET_IID(nsINntpIncomingServer),
getter_AddRefs(nntpServer));
if (NS_FAILED(rv)) return rv;
rv = nntpServer->GetNewsrcFilePath(getter_AddRefs(mNewsrcFilePath));
if (NS_FAILED(rv)) return rv;
@ -199,17 +193,26 @@ nsMsgNewsFolder::GetReadSetStr(char **setStr)
NS_IMETHODIMP
nsMsgNewsFolder::AddNewsgroup(const char *name, const char *setStr, nsIMsgFolder **child)
{
nsresult rv = NS_OK;
if (!child) return NS_ERROR_NULL_POINTER;
if (!setStr) return NS_ERROR_NULL_POINTER;
if (!name) return NS_ERROR_NULL_POINTER;
#ifdef DEBUG_NEWS
printf("AddNewsgroup(%s,??,%s)\n",name,setStr);
printf("AddNewsgroup(%s,??,%s)\n",name,setStr);
#endif
nsresult rv = NS_OK;
NS_WITH_SERVICE(nsIRDFService, rdf, kRDFServiceCID, &rv);
if(NS_FAILED(rv)) return rv;
nsCOMPtr <nsINntpIncomingServer> nntpServer;
rv = GetNntpServer(getter_AddRefs(nntpServer));
if (NS_FAILED(rv)) return rv;
rv = nntpServer->AddNewsgroup(name);
if (NS_FAILED(rv)) return rv;
nsCOMPtr <nsIRDFService> rdf = do_GetService(kRDFServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
if (!rdf) return NS_ERROR_FAILURE;
nsCString uri(mURI);
uri.Append('/');
@ -492,12 +495,8 @@ NS_IMETHODIMP nsMsgNewsFolder::SetNewsrcHasChanged(PRBool newsrcHasChanged)
{
nsresult rv;
nsCOMPtr<nsIMsgIncomingServer> server;
rv = GetServer(getter_AddRefs(server));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsINntpIncomingServer> nntpServer;
rv = server->QueryInterface(NS_GET_IID(nsINntpIncomingServer), getter_AddRefs(nntpServer));
rv = GetNntpServer(getter_AddRefs(nntpServer));
if (NS_FAILED(rv)) return rv;
return nntpServer->SetNewsrcHasChanged(newsrcHasChanged);
@ -582,6 +581,15 @@ NS_IMETHODIMP nsMsgNewsFolder::Delete()
nsNewsSummarySpec summarySpec(path);
summarySpec.Delete(PR_FALSE);
nsCOMPtr <nsINntpIncomingServer> nntpServer;
rv = GetNntpServer(getter_AddRefs(nntpServer));
if (NS_FAILED(rv)) return rv;
nsXPIDLCString name;
rv = GetAsciiName(getter_Copies(name));
rv = nntpServer->RemoveNewsgroup((const char *)name);
if (NS_FAILED(rv)) return rv;
return NS_OK;
}
@ -613,15 +621,10 @@ NS_IMETHODIMP nsMsgNewsFolder::GetAbbreviatedName(PRUnichar * *aAbbreviatedName)
if (NS_FAILED(rv)) return rv;
if (!isNewsServer) {
nsCOMPtr<nsIMsgIncomingServer> server;
rv = GetServer(getter_AddRefs(server));
nsCOMPtr<nsINntpIncomingServer> nntpServer;
rv = GetNntpServer(getter_AddRefs(nntpServer));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsINntpIncomingServer> nntpServer;
rv = server->QueryInterface(NS_GET_IID(nsINntpIncomingServer),
getter_AddRefs(nntpServer));
if (NS_FAILED(rv)) return rv;
PRBool abbreviate = PR_TRUE;
rv = nntpServer->GetAbbreviate(&abbreviate);
if (NS_FAILED(rv)) return rv;
@ -878,33 +881,8 @@ NS_IMETHODIMP nsMsgNewsFolder::GetExpungedBytesCount(PRUint32 *count)
NS_IMETHODIMP nsMsgNewsFolder::GetDeletable(PRBool *deletable)
{
#if 0
if(!deletable)
return NS_ERROR_NULL_POINTER;
// These are specified in the "Mail/News Windows" UI spec
if (mFlags & MSG_FOLDER_FLAG_TRASH)
{
PRBool moveToTrash;
GetDeleteIsMoveToTrash(&moveToTrash);
if(moveToTrash)
*deletable = PR_TRUE; // allow delete of trash if we don't use trash
}
else if (mDepth == 1)
*deletable = PR_FALSE;
else if (mFlags & MSG_FOLDER_FLAG_INBOX ||
mFlags & MSG_FOLDER_FLAG_DRAFTS ||
mFlags & MSG_FOLDER_FLAG_TRASH ||
mFlags & MSG_FOLDER_FLAG_TEMPLATES)
*deletable = PR_FALSE;
else *deletable = PR_TRUE;
return NS_OK;
#else
NS_ASSERTION(0,"GetDeletable() not implemented");
return NS_ERROR_NOT_IMPLEMENTED;
#endif
}
NS_IMETHODIMP nsMsgNewsFolder::GetRequiresCleanup(PRBool *requiresCleanup)
@ -937,15 +915,12 @@ NS_IMETHODIMP nsMsgNewsFolder::DeleteMessages(nsISupportsArray *messages,
nsXPIDLCString hostname;
rv = GetHostname(getter_Copies(hostname));
if (NS_FAILED(rv)) return rv;
nsXPIDLString newsgroupname;
rv = GetName(getter_Copies(newsgroupname));
nsCAutoString asciiName; asciiName.AssignWithConversion(newsgroupname);
if (NS_FAILED(rv)) {
return rv;
}
rv = nntpService->CancelMessages((const char *)hostname, (const char *)asciiName, messages, nsnull /* consumer */, nsnull, aMsgWindow, nsnull);
nsXPIDLCString newsgroupname;
rv = GetAsciiName(getter_Copies(newsgroupname));
if (NS_FAILED(rv)) return rv;
rv = nntpService->CancelMessages((const char *)hostname, (const char *)newsgroupname, messages, nsnull /* consumer */, nsnull, aMsgWindow, nsnull);
}
return rv;
@ -971,13 +946,8 @@ NS_IMETHODIMP nsMsgNewsFolder::GetNewMessages(nsIMsgWindow *aWindow)
NS_WITH_SERVICE(nsINntpService, nntpService, kNntpServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIMsgIncomingServer> server;
rv = GetServer(getter_AddRefs(server));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsINntpIncomingServer> nntpServer;
rv = server->QueryInterface(NS_GET_IID(nsINntpIncomingServer),
getter_AddRefs(nntpServer));
rv = GetNntpServer(getter_AddRefs(nntpServer));
if (NS_FAILED(rv)) return rv;
#ifdef DEBUG_NEWS
@ -1558,11 +1528,12 @@ nsMsgNewsFolder::GetNewsrcLine(char **newsrcLine)
if (!newsrcLine) return NS_ERROR_NULL_POINTER;
nsXPIDLString newsgroupname;
rv = GetName(getter_Copies(newsgroupname));
nsXPIDLCString newsgroupname;
rv = GetAsciiName(getter_Copies(newsgroupname));
if (NS_FAILED(rv)) return rv;
nsCAutoString newsrcLineStr; newsrcLineStr.AssignWithConversion(newsgroupname);
nsCAutoString newsrcLineStr;
newsrcLineStr = (const char *)newsgroupname;
newsrcLineStr += ":";
char *setStr = nsnull;
@ -1651,3 +1622,73 @@ nsMsgNewsFolder::OnReadChanged(nsIDBChangeListener * aInstigator)
return SetNewsrcHasChanged(PR_TRUE);
}
NS_IMETHODIMP
nsMsgNewsFolder::GetAsciiName(char **asciiName)
{
nsresult rv;
if (!asciiName) return NS_ERROR_NULL_POINTER;
nsXPIDLString name;
rv = GetName(getter_Copies(name));
if (NS_FAILED(rv)) return rv;
nsCAutoString tmpStr;
tmpStr.AssignWithConversion(name);
*asciiName = nsCRT::strdup((const char *)tmpStr);
if (!*asciiName) return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP
nsMsgNewsFolder::GetNntpServer(nsINntpIncomingServer **result)
{
nsresult rv;
if (!result) return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIMsgIncomingServer> server;
rv = GetServer(getter_AddRefs(server));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsINntpIncomingServer> nntpServer;
rv = server->QueryInterface(NS_GET_IID(nsINntpIncomingServer),
getter_AddRefs(nntpServer));
if (NS_FAILED(rv)) return rv;
*result = nntpServer;
NS_IF_ADDREF(*result);
return NS_OK;
}
// this gets called after the message actually gets cancelled
// it removes the cancelled message from the db
NS_IMETHODIMP nsMsgNewsFolder::RemoveMessage(nsMsgKey key)
{
nsresult rv;
nsCAutoString msgURI;
rv = nsBuildNewsMessageURI(mBaseMessageURI, key, msgURI);
if (NS_FAILED(rv)) return rv;
nsCOMPtr <nsIRDFService> rdfService = do_GetService(kRDFServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr <nsIRDFResource> res;
rv = rdfService->GetResource(msgURI.GetBuffer(), getter_AddRefs(res));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIDBMessage> dbMessage = do_QueryInterface(res);
if (!dbMessage) return NS_ERROR_FAILURE;
nsCOMPtr <nsIMsgDBHdr> msgDBHdr;
rv = dbMessage->GetMsgDBHdr(getter_AddRefs(msgDBHdr));
if (NS_FAILED(rv)) return rv;
rv = mDatabase->DeleteHeader(msgDBHdr, nsnull, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) return rv;
return NS_OK;
}

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

@ -234,7 +234,6 @@ nsNntpIncomingServer::WriteNewsrcFile()
nsCOMPtr<nsIEnumerator> subFolders;
nsCOMPtr<nsIFolder> rootFolder;
rv = GetRootFolder(getter_AddRefs(rootFolder));
if (NS_FAILED(rv)) return rv;
@ -687,7 +686,7 @@ writeGroupToHostInfo(nsCString &aElement, void *aData)
}
PRBool
addGroup(nsCString &aElement, void *aData)
addGroupFunction(nsCString &aElement, void *aData)
{
nsresult rv;
nsNntpIncomingServer *server;
@ -804,7 +803,7 @@ nsNntpIncomingServer::PopulateSubscribeDatasourceFromHostInfo(nsIMsgWindow *aMsg
printf("PopulateSubscribeDatasourceFromHostInfo()\n");
#endif
mGroupsOnServer.EnumerateForwards((nsCStringArrayEnumFunc)addGroup, (void *)this);
mGroupsOnServer.EnumerateForwards((nsCStringArrayEnumFunc)addGroupFunction, (void *)this);
rv = UpdateSubscribedInSubscribeDS();
if (NS_FAILED(rv)) return rv;
@ -889,12 +888,42 @@ nsNntpIncomingServer::SetAsSubscribedInSubscribeDS(const char *aURI)
return mInner->SetAsSubscribedInSubscribeDS(aURI);
}
PRBool
setAsSubscribedFunction(nsCString &aElement, void *aData)
{
nsresult rv;
nsNntpIncomingServer *server;
server = (nsNntpIncomingServer *)aData;
nsXPIDLCString serverURI;
nsCOMPtr<nsIFolder> rootFolder;
rv = server->GetRootFolder(getter_AddRefs(rootFolder));
if (NS_FAILED(rv)) return rv;
if (!rootFolder) return NS_ERROR_FAILURE;
rv = rootFolder->GetURI(getter_Copies(serverURI));
if (NS_FAILED(rv)) return rv;
nsCAutoString uriStr;
uriStr = (const char*)serverURI;
uriStr += '/';
uriStr += (const char *)aElement;
rv = server->SetAsSubscribedInSubscribeDS((const char *)uriStr);
NS_ASSERTION(NS_SUCCEEDED(rv),"SetAsSubscribedInSubscribeDS failed");
return PR_TRUE;
}
NS_IMETHODIMP
nsNntpIncomingServer::UpdateSubscribedInSubscribeDS()
{
NS_ASSERTION(mInner,"not initialized");
if (!mInner) return NS_ERROR_FAILURE;
return mInner->UpdateSubscribedInSubscribeDS();
mSubscribedNewsgroups.EnumerateForwards((nsCStringArrayEnumFunc)setAsSubscribedFunction, (void *)this);
return NS_OK;
}
NS_IMETHODIMP
@ -1062,3 +1091,20 @@ nsNntpIncomingServer::HandleLine(char* line, PRUint32 line_size)
return 0;
}
NS_IMETHODIMP
nsNntpIncomingServer::AddNewsgroup(const char *name)
{
// handle duplicates?
mSubscribedNewsgroups.AppendCString(name);
return NS_OK;
}
NS_IMETHODIMP
nsNntpIncomingServer::RemoveNewsgroup(const char *name)
{
// handle duplicates?
mSubscribedNewsgroups.RemoveCString(name);
return NS_OK;
}

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

@ -77,6 +77,8 @@ protected:
private:
nsCStringArray mGroupsOnServer;
nsCStringArray mSubscribedNewsgroups;
PRBool mHasSeenBeginGroups;
nsresult WriteHostInfoFile();
nsresult LoadHostInfoFile();

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

@ -49,6 +49,7 @@
#include "nsIFileLocator.h"
#include "nsFileLocations.h"
#include "nsIMsgAccountManager.h"
#include "nsIMessengerMigrator.h"
#include "nsINntpIncomingServer.h"
#include "nsICmdLineHandler.h"
#include "nsICategoryManager.h"
@ -69,6 +70,7 @@ static NS_DEFINE_CID(kCNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID);
static NS_DEFINE_CID(kCPrefServiceCID, NS_PREF_CID);
static NS_DEFINE_CID(kFileLocatorCID, NS_FILELOCATOR_CID);
static NS_DEFINE_CID(kMsgAccountManagerCID, NS_MSGACCOUNTMANAGER_CID);
static NS_DEFINE_CID(kMessengerMigratorCID, NS_MESSENGERMIGRATOR_CID);
static NS_DEFINE_IID(kIFileLocatorIID, NS_IFILELOCATOR_IID);
nsNntpService::nsNntpService()
@ -807,9 +809,7 @@ nsresult nsNntpService::ConstructNntpUrl(const char * urlString, const char * ne
nsCOMPtr <nsIMsgMailNewsUrl> mailnewsurl = do_QueryInterface(nntpUrl);
nsCOMPtr <nsIMsgMessageUrl> msgUrl = do_QueryInterface(nntpUrl);
msgUrl->SetUri(urlString);
// don't worry this cast is really okay...there'a bug in XPIDL compiler that is preventing
// a "const char *" in paramemter for uri SetSpec...
mailnewsurl->SetSpec((char *) urlString);
mailnewsurl->SetSpec(urlString);
if (newsgroupName != "") {
nsCOMPtr <nsINNTPNewsgroup> newsgroup;
@ -851,9 +851,6 @@ nsNntpService::CreateNewsAccount(const char *username, const char *hostname, PRB
if (NS_FAILED(rv)) return rv;
if (!accountManager) return NS_ERROR_FAILURE;
#ifdef DEBUG_sspitzer
printf("todo, for bug #36661, are there any accounts? if not, see if you can migrate. if not, popup the wizard for this server?\n");
#endif
nsCOMPtr <nsIMsgAccount> account;
rv = accountManager->CreateAccount(getter_AddRefs(account));
@ -870,18 +867,8 @@ nsNntpService::CreateNewsAccount(const char *username, const char *hostname, PRB
if (NS_FAILED(rv)) return rv;
if (!identity) return NS_ERROR_FAILURE;
// todo: eventually, copy the identity from the default news account
nsCOMPtr <nsIMsgAccount> defaultAccount;
rv = accountManager->GetDefaultAccount(getter_AddRefs(defaultAccount));
if (NS_FAILED(rv)) return rv;
if (!defaultAccount) return NS_ERROR_FAILURE;
nsCOMPtr <nsIMsgIdentity> defaultIdentity;
rv = defaultAccount->GetDefaultIdentity(getter_AddRefs(defaultIdentity));
if (NS_FAILED(rv)) return rv;
if (!defaultIdentity) return NS_ERROR_FAILURE;
rv = identity->Copy(defaultIdentity);
// the identity isn't filled in, so it is not valid.
rv = (*server)->SetValid(PR_FALSE);
if (NS_FAILED(rv)) return rv;
// hook them together
@ -909,9 +896,32 @@ nsNntpService::GetProtocolForUri(nsIURI *aUri, nsIMsgWindow *aMsgWindow, nsINNTP
if (NS_FAILED(rv)) return rv;
if (!accountManager) return NS_ERROR_FAILURE;
// find the incoming server
// find the incoming server, it if exists.
// migrate if necessary, before searching for it.
// if it doesn't exist, create it.
nsCOMPtr<nsIMsgIncomingServer> server;
nsCOMPtr<nsINntpIncomingServer> nntpServer;
#ifdef DEBUG_sspitzer
printf("for bug, #36661, see if there are any accounts, if not, try migrating. should this be pushed into FindServer()?\n");
#endif
nsCOMPtr <nsISupportsArray> accounts;
rv = accountManager->GetAccounts(getter_AddRefs(accounts));
if (NS_FAILED(rv)) return rv;
PRUint32 accountCount;
rv = accounts->Count(&accountCount);
if (NS_FAILED(rv)) return rv;
if (accountCount == 0) {
nsCOMPtr <nsIMessengerMigrator> messengerMigrator = do_GetService(kMessengerMigratorCID, &rv);
if (NS_FAILED(rv)) return rv;
if (!messengerMigrator) return NS_ERROR_FAILURE;
// migration can fail;
messengerMigrator->UpgradePrefs();
}
rv = accountManager->FindServer((const char *)userName,
(const char *)hostName,
"nntp",
@ -1147,9 +1157,7 @@ NS_IMETHODIMP nsNntpService::NewURI(const char *aSpec, nsIURI *aBaseURI, nsIURI
nntpUrl->QueryInterface(NS_GET_IID(nsIURI), (void **) _retval);
// don't worry this cast is really okay...there'a bug in XPIDL compiler that is preventing
// a "cont char *" in paramemter for uri SetSpec...
(*_retval)->SetSpec((char *) aSpec);
(*_retval)->SetSpec(aSpec);
return rv;
}

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

@ -380,8 +380,10 @@ NS_IMETHODIMP nsNntpUrl::GetNewsgroupName(char ** aNewsgroupName)
{
if (!aNewsgroupName) return NS_ERROR_NULL_POINTER;
NS_ASSERTION(m_newsgroupName, "null ptr");
if (!m_newsgroupName) return NS_ERROR_FAILURE;
if (!m_newsgroupName) {
*aNewsgroupName = nsnull;
return NS_OK;
}
*aNewsgroupName = PL_strdup(m_newsgroupName);
if (!aNewsgroupName) {