added nsNewsMessage, nsNewsUtils and use nsIMsgDBHdr.

This commit is contained in:
putterman%netscape.com 1999-04-24 20:47:04 +00:00
Родитель dc3d9c5de0
Коммит 14518c8ad0
9 изменённых файлов: 554 добавлений и 85 удалений

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

@ -36,6 +36,7 @@ EXPORTS = \
nsNntpService.h \
nsNewsFolder.h \
nsNntpIncomingServer.h \
nsNewsMessage.h \
$(NULL)
CPPSRCS = \
@ -49,6 +50,8 @@ CPPSRCS = \
nsNntpService.cpp \
nsNewsFolder.cpp \
nsNntpIncomingServer.cpp \
nsNewsMessage.cpp \
nsNewsUtils.cpp \
$(NULL)
EXTRA_DSO_LDOPTS = \

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

@ -35,6 +35,8 @@ CPPSRCS= nsNNTPProtocol.cpp \
nsNntpService.cpp \
nsNewsFolder.cpp \
nsNntpIncomingServer.cpp \
nsNewsMessage.cpp \
nsNewsUtils.cpp \
$(NULL)
CPP_OBJS= .\$(OBJDIR)\nsNNTPProtocol.obj \
@ -47,6 +49,8 @@ CPP_OBJS= .\$(OBJDIR)\nsNNTPProtocol.obj \
.\$(OBJDIR)\nsNntpService.obj \
.\$(OBJDIR)\nsNewsFolder.obj \
.\$(OBJDIR)\nsNntpIncomingServer.obj \
.\$(OBJDIR)\nsNewsMessage.obj \
.\$(OBJDIR)\nsNewsUtils.obj \
$(NULL)
@ -60,6 +64,7 @@ EXPORTS= nsNNTPProtocol.h \
nsNntpService.h \
nsNewsFolder.h \
nsNntpIncomingServer.h \
nsNewsMessage.h \
$(NULL)
LINCS= \

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

@ -24,6 +24,7 @@
#include "nsNewsFolder.h"
#include "nsMsgFolderFlags.h"
#include "prprf.h"
#include "prsystem.h"
#include "nsISupportsArray.h"
#include "nsIServiceManager.h"
#include "nsIEnumerator.h"
@ -35,6 +36,9 @@
#include "nsRDFCID.h"
#include "nsFileStream.h"
#include "nsMsgDBCID.h"
#include "nsNewsMessage.h"
#include "nsNewsUtils.h"
// we need this because of an egcs 1.0 (and possibly gcc) compiler bug
// that doesn't allow you to call ::nsISupports::GetIID() inside of a class
@ -59,30 +63,6 @@ nsMsgNewsFolder::nsMsgNewsFolder(void)
printf("nsMsgNewsFolder::nsMsgNewsFolder\n");
#endif
//XXXX This is a hack for the moment. I'm assuming the only listener is our rdf:mailnews datasource.
//In reality anyone should be able to listen to folder changes.
nsIRDFService* rdfService = nsnull;
nsIRDFDataSource* datasource = nsnull;
nsresult rv = nsServiceManager::GetService(kRDFServiceCID,
nsIRDFService::GetIID(),
(nsISupports**) &rdfService);
if(NS_SUCCEEDED(rv))
{
if(NS_SUCCEEDED(rv = rdfService->GetDataSource("rdf:mailnewsfolders", &datasource)))
{
nsIFolderListener *folderListener;
if(NS_SUCCEEDED(datasource->QueryInterface(nsIFolderListener::GetIID(), (void**)&folderListener)))
{
AddFolderListener(folderListener);
NS_RELEASE(folderListener);
}
NS_RELEASE(datasource);
}
nsServiceManager::ReleaseService(kRDFServiceCID, rdfService);
}
// NS_INIT_REFCNT(); done by superclass
}
@ -399,9 +379,17 @@ nsMsgNewsFolder::GetMessages(nsIEnumerator* *result)
nsresult rv = GetDatabase();
if(NS_SUCCEEDED(rv))
return mNewsDatabase->EnumerateMessages(result);
else
return rv;
{
nsIEnumerator *msgHdrEnumerator = nsnull;
nsMessageFromMsgHdrEnumerator *messageEnumerator = nsnull;
rv = mNewsDatabase->EnumerateMessages(&msgHdrEnumerator);
if(NS_SUCCEEDED(rv))
rv = NS_NewMessageFromMsgHdrEnumerator(msgHdrEnumerator,
this, &messageEnumerator);
*result = messageEnumerator;
NS_IF_RELEASE(msgHdrEnumerator);
}
return rv;
#endif
return NS_ERROR_NULL_POINTER;
}
@ -427,9 +415,19 @@ nsMsgNewsFolder::GetThreadForMessage(nsIMessage *message, nsIMsgThread **thread)
{
nsresult rv = GetDatabase();
if(NS_SUCCEEDED(rv))
return mNewsDatabase->GetThreadContainingMsgHdr(message, thread);
else
return rv;
{
nsIMsgDBHdr *msgDBHdr = nsnull;
//We know from our factory that mailbox message resources are going to be
//nsNewsMessages.
nsNewsMessage *newsMessage = NS_STATIC_CAST(nsNewsMessage*, message);
rv = newsMessage->GetMsgDBHdr(&msgDBHdr);
if(NS_SUCCEEDED(rv))
{
rv = mNewsDatabase->GetThreadContainingMsgHdr(msgDBHdr, thread);
NS_IF_RELEASE(msgDBHdr);
}
}
return rv;
}
@ -659,7 +657,7 @@ NS_IMETHODIMP nsMsgNewsFolder::GetName(char **name)
}
}
nsAutoString folderName;
nsURI2Name(kNewsRootURI, mURI, folderName);
nsNewsURI2Name(kNewsRootURI, mURI, folderName);
*name = folderName.ToNewCString();
return NS_OK;
@ -859,7 +857,7 @@ NS_IMETHODIMP nsMsgNewsFolder::GetPath(nsFileSpec& aPathName)
#endif
nsFileSpec nopath("");
if (mPath == nopath) {
nsresult rv = nsURI2Path(kNewsRootURI, mURI, mPath);
nsresult rv = nsNewsURI2Path(kNewsRootURI, mURI, mPath);
if (NS_FAILED(rv)) return rv;
}
aPathName = mPath;
@ -868,44 +866,27 @@ NS_IMETHODIMP nsMsgNewsFolder::GetPath(nsFileSpec& aPathName)
NS_IMETHODIMP nsMsgNewsFolder::DeleteMessage(nsIMessage *message)
{
if(mNewsDatabase)
return(mNewsDatabase->DeleteHeader(message, nsnull, PR_TRUE, PR_TRUE));
return NS_OK;
}
nsresult nsMsgNewsFolder::NotifyPropertyChanged(char *property, char *oldValue, char* newValue)
{
nsISupports *supports;
if(NS_SUCCEEDED(QueryInterface(kISupportsIID, (void**)&supports)))
nsresult rv = GetDatabase();
if(NS_SUCCEEDED(rv))
{
PRUint32 i;
for(i = 0; i < mListeners->Count(); i++)
nsIMsgDBHdr *msgDBHdr = nsnull;
//We know from our factory that news message resources are going to be
//nsNewsMessages.
nsNewsMessage *newsMessage = NS_STATIC_CAST(nsNewsMessage*, message);
rv = newsMessage->GetMsgDBHdr(&msgDBHdr);
if(NS_SUCCEEDED(rv))
{
nsIFolderListener *listener = (nsIFolderListener*)mListeners->ElementAt(i);
listener->OnItemPropertyChanged(supports, property, oldValue, newValue);
NS_RELEASE(listener);
rv =mNewsDatabase->DeleteHeader(msgDBHdr, nsnull, PR_TRUE, PR_TRUE);
NS_IF_RELEASE(msgDBHdr);
}
NS_RELEASE(supports);
}
return rv;}
return NS_OK;
}
nsresult nsMsgNewsFolder::NotifyItemAdded(nsISupports *item)
NS_IMETHODIMP nsMsgNewsFolder::CreateMessageFromMsgDBHdr(nsIMsgDBHdr *msgDBHdr, nsIMessage **message)
{
PRUint32 i;
for(i = 0; i < mListeners->Count(); i++)
{
nsIFolderListener *listener = (nsIFolderListener*)mListeners->ElementAt(i);
listener->OnItemAdded(this, item);
NS_RELEASE(listener);
}
return NS_OK;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsMsgNewsFolder::OnKeyChange(nsMsgKey aKeyChanged, int32 aFlags,
@ -917,22 +898,31 @@ NS_IMETHODIMP nsMsgNewsFolder::OnKeyChange(nsMsgKey aKeyChanged, int32 aFlags,
NS_IMETHODIMP nsMsgNewsFolder::OnKeyDeleted(nsMsgKey aKeyChanged, int32 aFlags,
nsIDBChangeListener * aInstigator)
{
nsIMessage *pMessage;
mNewsDatabase->GetMsgHdrForKey(aKeyChanged, &pMessage);
nsString author, subject;
nsISupports *msgSupports;
if(NS_SUCCEEDED(pMessage->QueryInterface(kISupportsIID, (void**)&msgSupports)))
nsIMsgDBHdr *pMsgDBHdr;
nsresult rv = mNewsDatabase->GetMsgHdrForKey(aKeyChanged, &pMsgDBHdr);
if(NS_SUCCEEDED(rv))
{
PRUint32 i;
for(i = 0; i < mListeners->Count(); i++)
nsIMessage *message = nsnull;
rv = CreateMessageFromMsgDBHdr(pMsgDBHdr, &message);
if(NS_SUCCEEDED(rv))
{
nsIFolderListener *listener = (nsIFolderListener*)mListeners->ElementAt(i);
listener->OnItemRemoved(this, msgSupports);
NS_RELEASE(listener);
nsISupports *msgSupports;
if(NS_SUCCEEDED(message->QueryInterface(kISupportsIID, (void**)&msgSupports)))
{
PRUint32 i;
for(i = 0; i < mListeners->Count(); i++)
{
nsIFolderListener *listener = (nsIFolderListener*)mListeners->ElementAt(i);
listener->OnItemRemoved(this, msgSupports);
NS_RELEASE(listener);
}
NS_IF_RELEASE(msgSupports);
}
NS_IF_RELEASE(message);
UpdateSummaryTotals();
}
NS_IF_RELEASE(pMsgDBHdr);
}
UpdateSummaryTotals();
NS_RELEASE(msgSupports);
return NS_OK;
}
@ -940,16 +930,26 @@ NS_IMETHODIMP nsMsgNewsFolder::OnKeyDeleted(nsMsgKey aKeyChanged, int32 aFlags,
NS_IMETHODIMP nsMsgNewsFolder::OnKeyAdded(nsMsgKey aKeyChanged, int32 aFlags,
nsIDBChangeListener * aInstigator)
{
nsIMessage *pMessage;
mNewsDatabase->GetMsgHdrForKey(aKeyChanged, &pMessage);
nsString author, subject;
nsISupports *msgSupports;
if(pMessage && NS_SUCCEEDED(pMessage->QueryInterface(kISupportsIID, (void**)&msgSupports)))
nsIMsgDBHdr *pMsgDBHdr;
nsresult rv = mNewsDatabase->GetMsgHdrForKey(aKeyChanged, &pMsgDBHdr);
if(NS_SUCCEEDED(rv))
{
NotifyItemAdded(msgSupports);
nsIMessage *message;
rv = CreateMessageFromMsgDBHdr(pMsgDBHdr, &message);
if(NS_SUCCEEDED(rv))
{
nsISupports *msgSupports;
if(message && NS_SUCCEEDED(message->QueryInterface(kISupportsIID, (void**)&msgSupports)))
{
NotifyItemAdded(msgSupports);
NS_IF_RELEASE(msgSupports);
}
UpdateSummaryTotals();
NS_IF_RELEASE(message);
}
NS_IF_RELEASE(pMsgDBHdr);
}
UpdateSummaryTotals();
NS_RELEASE(msgSupports);
return NS_OK;
return NS_OK;
}
@ -958,3 +958,4 @@ NS_IMETHODIMP nsMsgNewsFolder::OnAnnouncerGoingAway(nsIDBChangeAnnouncer * insti
{
return NS_OK;
}

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

@ -88,6 +88,7 @@ public:
virtual nsresult GetDBFolderInfoAndDB(nsIDBFolderInfo **folderInfo, nsIMsgDatabase **db);
NS_IMETHOD DeleteMessage(nsIMessage *message);
NS_IMETHOD CreateMessageFromMsgDBHdr(nsIMsgDBHdr *msgDBHdr, nsIMessage **message);
// nsIMsgNewsFolder
NS_IMETHOD GetPath(nsNativeFileSpec& aPathName);
@ -106,8 +107,6 @@ protected:
nsresult CreateSubFolders(nsFileSpec &path);
nsresult AddDirectorySeparator(nsFileSpec &path);
nsresult GetDatabase();
nsresult NotifyPropertyChanged(char *property, char* oldValue, char* newValue);
nsresult NotifyItemAdded(nsISupports *item);
/* Finds the directory associated with this folder. That is if the path is
c:\Inbox, it will return c:\Inbox.sbd if it succeeds. If that path doesn't

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

@ -0,0 +1,103 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "msgCore.h" // precompiled header...
#include "nsNewsMessage.h"
#include "nsIRDFService.h"
#include "nsIServiceManager.h"
#include "nsRDFCID.h"
#include "nsXPIDLString.h"
#include "nsNewsUtils.h"
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
nsNewsMessage::nsNewsMessage(void)
{
// NS_INIT_REFCNT(); done by superclass
}
nsNewsMessage::~nsNewsMessage(void)
{
}
NS_IMPL_ISUPPORTS_INHERITED(nsNewsMessage, nsMessage, nsIMessage)
NS_IMETHODIMP nsNewsMessage::GetMsgFolder(nsIMsgFolder **folder)
{
nsresult rv;
if(mFolder)
{
*folder = mFolder;
NS_ADDREF(mFolder);
rv = NS_OK;
}
else
{
rv = GetFolderFromURI(folder);
}
return rv;
}
//Note this is the same as the function in LocalMessage except for news uri specific stuff.
//I'm not convinced that parsing the url is going to be different so I'm setting this up as a
//separate function. If it turns out this isn't the case we could write a utility function that
//both message classes can use.
nsresult nsNewsMessage::GetFolderFromURI(nsIMsgFolder **folder)
{
nsresult rv;
nsXPIDLCString uri;
nsIRDFResource *resource;
if(NS_SUCCEEDED( rv = QueryInterface(nsIRDFResource::GetIID(), (void**)&resource)))
{
resource->GetValue( getter_Copies(uri) );
nsString messageFolderURIStr;
nsMsgKey key;
nsParseNewsMessageURI(uri, messageFolderURIStr, &key);
nsString folderOnly, folderURIStr;
if (messageFolderURIStr.Find(kNewsMessageRootURI) != ((PRInt32)-1)) {
messageFolderURIStr.Right(folderOnly, messageFolderURIStr.Length() -nsCRT::strlen(kNewsMessageRootURI));
folderURIStr = kNewsRootURI;
folderURIStr+= folderOnly;
nsIRDFResource *folderResource;
char *folderURI = folderURIStr.ToNewCString();
NS_WITH_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, &rv);
if (NS_SUCCEEDED(rv)) // always check this before proceeding
{
rv = rdfService->GetResource(folderURI, &folderResource);
if(NS_SUCCEEDED(rv))
{
rv = NS_SUCCEEDED(folderResource->QueryInterface(nsIMsgFolder::GetIID(), (void**)folder));
NS_RELEASE(folderResource);
}
}
delete[] folderURI;
}
NS_RELEASE(resource);
}
return rv;
}

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

@ -0,0 +1,44 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/********************************************************************************************************
Interface for representing Local Mail folders.
*********************************************************************************************************/
#ifndef nsNewsMessage_h__
#define nsNewsMessage_h__
#include "nsMessage.h" /* include the interface we are going to support */
class nsNewsMessage : public nsMessage
{
public:
nsNewsMessage(void);
virtual ~nsNewsMessage(void);
NS_DECL_ISUPPORTS_INHERITED
NS_IMETHOD GetMsgFolder(nsIMsgFolder **folder);
protected:
nsresult GetFolderFromURI(nsIMsgFolder **folder);
};
#endif //nsNewsMessage_h__

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

@ -0,0 +1,266 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "msgCore.h"
#include "nsNewsUtils.h"
#include "nsIServiceManager.h"
#include "prsystem.h"
// stuff for temporary root folder hack
#include "nsIMsgMailSession.h"
#include "nsIMsgIncomingServer.h"
#include "nsINntpIncomingServer.h"
static NS_DEFINE_CID(kMsgMailSessionCID, NS_MSGMAILSESSION_CID);
//Utilities
static char *gNewsRoot = nsnull;
nsresult
nsGetNewsRoot(nsFileSpec &result)
{
nsresult rv = NS_OK;
if (gNewsRoot == nsnull) {
nsIMsgMailSession *session;
rv = nsServiceManager::GetService(kMsgMailSessionCID,
nsIMsgMailSession::GetIID(),
(nsISupports **)&session);
if (NS_SUCCEEDED(rv)) {
nsIMsgIncomingServer *server;
rv = session->GetCurrentServer(&server);
if (NS_FAILED(rv)) printf("nsGetNewsRoot: Couldn't get current server\n");
if (NS_SUCCEEDED(rv)) {
nsINntpIncomingServer *nntpServer;
rv = server->QueryInterface(nsINntpIncomingServer::GetIID(),
(void **)&nntpServer);
if (NS_FAILED(rv)) printf("nsGetNewsRoot: Couldn't get nntp server\n");
if (NS_SUCCEEDED(rv)) {
rv = nntpServer->GetRootFolderPath(&gNewsRoot);
if (NS_FAILED(rv)) printf("nsGetNewsRoot: Couldn't get root\n");
NS_RELEASE(nntpServer);
}
NS_RELEASE(server);
}
nsServiceManager::ReleaseService(kMsgMailSessionCID, session);
}
} /* if (gNewsRoot == nsnull) .. */
result = gNewsRoot;
return rv;
}
nsresult
nsNewsURI2Path(const char* rootURI, const char* uriStr, nsFileSpec& pathResult)
{
nsresult rv;
nsAutoString sep;
sep += PR_GetDirectorySeparator();
nsAutoString sbdSep;
/* sspitzer: is this ok for mail and news? */
rv = nsGetMailFolderSeparator(sbdSep);
if (NS_FAILED(rv)) return rv;
nsAutoString uri = uriStr;
if (uri.Find(rootURI) != 0) // if doesn't start with rootURI
return NS_ERROR_FAILURE;
if ((strcmp(rootURI, kNewsRootURI) == 0) ||
(strcmp(rootURI, kNewsMessageRootURI) == 0)) {
rv = nsGetNewsRoot(pathResult);
}
else {
rv = NS_ERROR_FAILURE;
}
if (NS_FAILED(rv)) {
pathResult = nsnull;
return rv;
}
nsAutoString path="";
uri.Cut(0, nsCRT::strlen(rootURI));
PRInt32 uriLen = uri.Length();
PRInt32 pos;
while(uriLen > 0) {
nsAutoString folderName;
PRInt32 leadingPos;
// if it's the first character then remove it.
while ((leadingPos = uri.Find('/')) == 0) {
uri.Cut(0, 1);
uriLen--;
}
if (uriLen == 0)
break;
pos = uri.Find('/');
if (pos < 0)
pos = uriLen;
PRInt32 leftRes = uri.Left(folderName, pos);
NS_ASSERTION(leftRes == pos,
"something wrong with nsString");
//We only want to add this after the first time around.
if(path.Length() > 0)
{
path += sep;
path += PR_GetDirectorySeparator();
}
// the first time around the separator is special because
// the root mail folder doesn't end with .sbd
sep = sbdSep;
path += folderName;
uri.Cut(0, pos);
uriLen -= pos;
}
if(path.Length() > 0)
pathResult +=path;
return NS_OK;
}
nsresult
nsPath2NewsURI(const char* rootURI, const nsFileSpec& spec, char **uri)
{
nsresult rv;
nsAutoString sep;
/* sspitzer: is this ok for mail and news? */
rv = nsGetMailFolderSeparator(sep);
if (NS_FAILED(rv)) return rv;
PRUint32 sepLen = sep.Length();
nsFileSpec root;
rv = nsGetNewsRoot(root);
if (NS_FAILED(rv)) return rv;
const char *path = spec;
nsAutoString pathStr(path);
path = root;
nsAutoString rootStr(path);
PRInt32 pos = pathStr.Find(rootStr);
if (pos != 0) // if doesn't start with root path
return NS_ERROR_FAILURE;
nsAutoString uriStr(rootURI);
PRUint32 rootStrLen = rootStr.Length();
pathStr.Cut(0, rootStrLen);
PRInt32 pathStrLen = pathStr.Length();
char dirSep = PR_GetDirectorySeparator();
while (pathStrLen > 0) {
nsAutoString folderName;
PRInt32 leadingPos;
// if it's the first character then remove it.
while ((leadingPos = pathStr.Find(dirSep)) == 0) {
pathStr.Cut(0, 1);
pathStrLen--;
}
if (pathStrLen == 0)
break;
pos = pathStr.Find(sep);
if (pos < 0)
pos = pathStrLen;
PRInt32 leftRes = pathStr.Left(folderName, pos);
NS_ASSERTION(leftRes == pos,
"something wrong with nsString");
pathStr.Cut(0, pos + sepLen);
pathStrLen -= pos + sepLen;
uriStr += '/';
uriStr += folderName;
}
*uri = uriStr.ToNewCString();
return NS_OK;
}
nsresult
nsNewsURI2Name(const char* rootURI, char* uriStr, nsString& name)
{
nsAutoString uri = uriStr;
if (uri.Find(rootURI) != 0) // if doesn't start with rootURI
return NS_ERROR_FAILURE;
PRInt32 pos = uri.RFind("/");
PRInt32 length = uri.Length();
PRInt32 count = length - (pos + 1);
return uri.Right(name, count);
}
/* parses NewsMessageURI */
nsresult nsParseNewsMessageURI(const char* uri, nsString& folderURI, PRUint32 *key)
{
if(!key)
return NS_ERROR_NULL_POINTER;
nsAutoString uriStr = uri;
PRInt32 keySeparator = uriStr.Find('#');
if(keySeparator != -1)
{
nsAutoString folderPath;
uriStr.Left(folderURI, keySeparator);
nsAutoString keyStr;
uriStr.Right(keyStr, uriStr.Length() - (keySeparator + 1));
PRInt32 errorCode;
*key = keyStr.ToInteger(&errorCode);
return errorCode;
}
return NS_ERROR_FAILURE;
}
nsresult nsBuildNewsMessageURI(const nsFileSpec& path, PRUint32 key, char** uri)
{
if(!uri)
return NS_ERROR_NULL_POINTER;
char *folderURI;
nsPath2NewsURI(kNewsMessageRootURI, path, &folderURI);
*uri = PR_smprintf("%s#%d", folderURI, key);
delete[] folderURI;
return NS_OK;
}

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

@ -0,0 +1,47 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef NS_NEWSUTILS_H
#define NS_NEWSUTILS_H
#include "nsFileSpec.h"
#include "nsString.h"
static const char kNewsRootURI[] = "news:/";
static const char kNewsMessageRootURI[] = "news_message:/";
extern nsresult
nsGetNewsRoot(nsFileSpec &result);
extern nsresult
nsNewsURI2Path(const char* rootURI, const char* uriStr, nsFileSpec& pathResult);
extern nsresult
nsPath2NewsURI(const char* rootURI, const nsFileSpec& path, char* *uri);
extern nsresult
nsNewsURI2Name(const char* rootURI, char* uriStr, nsString& name);
extern nsresult
nsParseNewsMessageURI(const char* uri, nsString& folderURI, PRUint32 *key);
extern nsresult
nsBuildNewsMessageURI(const nsFileSpec& path, PRUint32 key, char **uri);
#endif //NS_NEWSUTILS_H

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

@ -32,6 +32,7 @@
#include "plstr.h"
#include "prprf.h"
#include "nsCRT.h"
#include "nsNewsUtils.h"
// we need this because of an egcs 1.0 (and possibly gcc) compiler bug
// that doesn't allow you to call ::nsISupports::GetIID() inside of a class