зеркало из https://github.com/mozilla/gecko-dev.git
Родитель
54c583bb7a
Коммит
655c720a6c
|
@ -1,2 +0,0 @@
|
|||
TestMSGCompose
|
||||
Makefile
|
|
@ -1,48 +0,0 @@
|
|||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
PROGRAM = TestMSGCompose$(BIN_SUFFIX)
|
||||
REQUIRES = xpcom uconv msgbase msgbaseutil msgcompose editor necko pref js mailnews msgdb dom widget layout msglocal appshell mime
|
||||
|
||||
CPPSRCS = test.cpp
|
||||
|
||||
ifeq ($(USE_SHORT_LIBNAME),1)
|
||||
EXTRA_DSO_LIBS = msgbsutl
|
||||
else
|
||||
EXTRA_DSO_LIBS = msgbaseutil
|
||||
endif
|
||||
|
||||
LIBS = \
|
||||
$(EXTRA_DSO_LIBS) \
|
||||
$(XPCOM_LIBS) \
|
||||
$(NSPR_LIBS) \
|
||||
$(TK_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
@ -1,92 +0,0 @@
|
|||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
# New build system where zip dll is build indepenant of java stubs.
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
MODULE =msgcomposetest
|
||||
#EXPORTS = \
|
||||
# $(NULL)
|
||||
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Specify the depth of the current directory relative to the
|
||||
#// root of NS
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
DEPTH= ..\..\..\..
|
||||
|
||||
MAKE_OBJ_TYPE=EXE
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Define any Public Make Variables here: (ie. PDFFILE, MAPFILE, ...)
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
EXENAME=TestMSGCompose
|
||||
PDBFILE=TestMSGCompose.pdb
|
||||
MAPFILE=TestMSGCompose.map
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Define the files necessary to build the target (ie. OBJS)
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
OBJS= \
|
||||
.\$(OBJDIR)\test.obj \
|
||||
$(NULL)
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Define any Public Targets here (ie. PROGRAM, LIBRARY, DLL, ...)
|
||||
#// (these must be defined before the common makefiles are included)
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
|
||||
PROGRAM=.\$(OBJDIR)\$(EXENAME).EXE
|
||||
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Define any local options for the make tools
|
||||
#// (ie. LCFLAGS, LLFLAGS, LLIBS, LINCS)
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
LCFLAGS=-DNETSCAPE
|
||||
WIN_LIBS= ole32.lib
|
||||
LLIBS= \
|
||||
$(DIST)\lib\xpcom.lib \
|
||||
$(LIBNSPR) \
|
||||
|
||||
# clobber and clobber_all will remove the following garbage:
|
||||
GARBAGE = $(GARBAGE) _gen
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Include the common makefile rules
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
include <$(DEPTH)/config/rules.mak>
|
||||
|
||||
install:: $(PROGRAM)
|
||||
$(MAKE_INSTALL) $(PROGRAM) $(DIST)\bin\
|
||||
|
||||
clobber::
|
||||
rm -f $(EXENAME).exe
|
|
@ -1,475 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||
*/
|
||||
|
||||
#define NS_IMPL_IDS
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "msgCore.h"
|
||||
#include "nsMsgBaseCID.h"
|
||||
#include "nsMsgLocalCID.h"
|
||||
#include "nsMsgCompCID.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include "nsIIOService.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsMsgCompCID.h"
|
||||
#include "nsIMsgCompose.h"
|
||||
#include "nsIMsgCompFields.h"
|
||||
#include "nsIMsgSend.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nscore.h"
|
||||
#include "nsIMsgAccountManager.h"
|
||||
#include "nsINetSupportDialogService.h"
|
||||
#include "nsIAppShellService.h"
|
||||
#include "nsAppShellCIDs.h"
|
||||
#include "nsIMemory.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "nsISmtpService.h"
|
||||
#include "nsISmtpUrl.h"
|
||||
#include "nsIUrlListener.h"
|
||||
#include "nsIEventQueueService.h"
|
||||
#include "nsIEventQueue.h"
|
||||
#include "nsIFileLocator.h"
|
||||
#include "nsCRT.h"
|
||||
#include "prmem.h"
|
||||
#include "nsIURL.h"
|
||||
#if 0
|
||||
#include "xp.h"
|
||||
#endif
|
||||
#ifdef XP_WIN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include "nsMimeTypes.h"
|
||||
|
||||
#ifdef XP_PC
|
||||
#define XPCOM_DLL "xpcom32.dll"
|
||||
#define PREF_DLL "xppref32.dll"
|
||||
#define APPSHELL_DLL "appshell.dll"
|
||||
#define MIME_DLL "mime.dll"
|
||||
#define UNICHAR_DLL "uconv.dll"
|
||||
#else
|
||||
#ifdef XP_MAC
|
||||
#include "nsMacRepository.h"
|
||||
#else
|
||||
#define XPCOM_DLL "libxpcom"MOZ_DLL_SUFFIX
|
||||
#define PREF_DLL "libpref"MOZ_DLL_SUFFIX
|
||||
#define APPSHELL_DLL "libnsappshell"MOZ_DLL_SUFFIX
|
||||
#define MIME_DLL "libmime"MOZ_DLL_SUFFIX
|
||||
#define UNICHAR_DLL "libuconv"MOZ_DLL_SUFFIX
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// Define keys for all of the interfaces we are going to require for this test
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
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(kMsgComposeCID, NS_MSGCOMPOSE_CID);
|
||||
static NS_DEFINE_CID(kMsgCompFieldsCID, NS_MSGCOMPFIELDS_CID);
|
||||
static NS_DEFINE_CID(kMsgSendCID, NS_MSGSEND_CID);
|
||||
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
|
||||
static NS_DEFINE_CID(kNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID);
|
||||
static NS_DEFINE_CID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
|
||||
static NS_DEFINE_CID(kGenericFactoryCID, NS_GENERICFACTORY_CID);
|
||||
static NS_DEFINE_CID(kMemoryCID, NS_MEMORY_CID);
|
||||
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
|
||||
static NS_DEFINE_CID(kICharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_IID);
|
||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
|
||||
PRBool keepOnRunning = PR_TRUE;
|
||||
nsICharsetConverterManager *ccMan = nsnull;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
// This is the listener class for the send operation. We have to create this class
|
||||
// to listen for message send completion and eventually notify the caller
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
class SendOperationListener : public nsIMsgSendListener
|
||||
{
|
||||
public:
|
||||
SendOperationListener(void)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
virtual ~SendOperationListener(void) {};
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
/* void OnStartSending (in string aMsgID, in PRUint32 aMsgSize); */
|
||||
NS_IMETHOD OnStartSending(const char *aMsgID, PRUint32 aMsgSize) {return NS_OK;};
|
||||
|
||||
/* void OnProgress (in string aMsgID, in PRUint32 aProgress, in PRUint32 aProgressMax); */
|
||||
NS_IMETHOD OnProgress(const char *aMsgID, PRUint32 aProgress, PRUint32 aProgressMax) {return NS_OK;};
|
||||
|
||||
/* void OnStatus (in string aMsgID, in wstring aMsg); */
|
||||
NS_IMETHOD OnStatus(const char *aMsgID, const PRUnichar *aMsg) {return NS_OK;};
|
||||
|
||||
/* void OnStopSending (in string aMsgID, in nsresult aStatus, in wstring aMsg, in nsIFileSpec returnFileSpec); */
|
||||
NS_IMETHOD OnStopSending(const char *aMsgID, nsresult aStatus, const PRUnichar *aMsg,
|
||||
nsIFileSpec *returnFileSpec)
|
||||
{
|
||||
keepOnRunning = PR_FALSE;
|
||||
return NS_OK;
|
||||
};
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS1(SendOperationListener, nsIMsgSendListener)
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
// This is the listener class for the send operation. We have to create this class
|
||||
// to listen for message send completion and eventually notify the caller
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// Utility to create a nsIURI object...
|
||||
nsresult
|
||||
nsMsgNewURL(nsIURI** aInstancePtrResult, const char * aSpec)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (nsnull == aInstancePtrResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_WITH_SERVICE(nsIIOService, pNetService, kIOServiceCID, &rv);
|
||||
if (NS_SUCCEEDED(rv) && pNetService)
|
||||
rv = pNetService->NewURI(aSpec, nsnull, aInstancePtrResult);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsMsgAttachedFile *
|
||||
GetLocalAttachments(void)
|
||||
{
|
||||
int attachCount = 3;
|
||||
nsIURI *url = nsnull;
|
||||
nsIURI *url2 = nsnull;
|
||||
|
||||
nsMsgAttachedFile *attachments = (nsMsgAttachedFile *) PR_Malloc(sizeof(nsMsgAttachedFile) * attachCount);
|
||||
|
||||
if (!attachments)
|
||||
return NULL;
|
||||
|
||||
nsMsgNewURL(&url, "file://C:/boxster.jpg");
|
||||
nsCRT::memset(attachments, 0, sizeof(nsMsgAttachedFile) * attachCount);
|
||||
|
||||
nsMsgNewURL(&url, "file://C:/boxster.jpg");
|
||||
attachments[0].orig_url = url;
|
||||
attachments[0].file_spec = new nsFileSpec("C:\\boxster.jpg");
|
||||
attachments[0].type = PL_strdup("image/jpeg");
|
||||
attachments[0].encoding = PL_strdup(ENCODING_BINARY);
|
||||
attachments[0].description = PL_strdup("Boxster Image");
|
||||
|
||||
nsMsgNewURL(&url2, "file://C:/boxster.jpg");
|
||||
attachments[1].orig_url = url2;
|
||||
attachments[1].file_spec = new nsFileSpec("C:\\boxster.jpg");
|
||||
attachments[1].type = PL_strdup("image/jpeg");
|
||||
attachments[1].encoding = PL_strdup(ENCODING_BINARY);
|
||||
attachments[1].description = PL_strdup("Boxster Image");
|
||||
|
||||
return attachments;
|
||||
}
|
||||
|
||||
nsMsgAttachmentData *
|
||||
GetRemoteAttachments()
|
||||
{
|
||||
int attachCount = 3;
|
||||
nsMsgAttachmentData *attachments = (nsMsgAttachmentData *) PR_Malloc(sizeof(nsMsgAttachmentData) * attachCount);
|
||||
nsIURI *url;
|
||||
|
||||
if (!attachments)
|
||||
return NULL;
|
||||
|
||||
nsCRT::memset(attachments, 0, sizeof(nsMsgAttachmentData) * attachCount);
|
||||
|
||||
url = nsnull;
|
||||
nsMsgNewURL(&url, "http://people.netscape.com/rhp/sherry.html");
|
||||
NS_ADDREF(url);
|
||||
attachments[0].url = url; // The URL to attach. This should be 0 to signify "end of list".
|
||||
|
||||
(void)attachments[0].desired_type; // The type to which this document should be
|
||||
// converted. Legal values are NULL, TEXT_PLAIN
|
||||
// and APPLICATION_POSTSCRIPT (which are macros
|
||||
// defined in net.h); other values are ignored.
|
||||
|
||||
(void)attachments[0].real_type; // The type of the URL if known, otherwise NULL. For example, if
|
||||
// you were attaching a temp file which was known to contain HTML data,
|
||||
// you would pass in TEXT_HTML as the real_type, to override whatever type
|
||||
// the name of the tmp file might otherwise indicate.
|
||||
|
||||
(void)attachments[0].real_encoding; // Goes along with real_type
|
||||
|
||||
(void)attachments[0].real_name; // The original name of this document, which will eventually show up in the
|
||||
// Content-Disposition header. For example, if you had copied a document to a
|
||||
// tmp file, this would be the original, human-readable name of the document.
|
||||
|
||||
(void)attachments[0].description; // If you put a string here, it will show up as the Content-Description header.
|
||||
// This can be any explanatory text; it's not a file name.
|
||||
|
||||
url = nsnull;
|
||||
nsMsgNewURL(&url, "http://people.netscape.com/rhp/rhp-home2.gif");
|
||||
// This can be any explanatory text; it's not a file name.
|
||||
|
||||
NS_ADDREF(url);
|
||||
attachments[1].url = url; // The URL to attach. This should be 0 to signify "end of list".
|
||||
|
||||
return attachments;
|
||||
}
|
||||
|
||||
char *email = {"\
|
||||
<!doctype html public \"-//w3c//dtd html 4.0 transitional//en\">\n\
|
||||
<html>\n\
|
||||
<body text=\"#000000\" bgcolor=\"#FFFFFF\" link=\"#FF0000\" vlink=\"#800080\" alink=\"#0000FF\">\n\
|
||||
<b><font face=\"Arial,Helvetica\"><font color=\"#FF0000\">Here is some HTML\n\
|
||||
in RED!</font></font></b>\n\
|
||||
<br><b><font face=\"Arial,Helvetica\"><font color=\"#FF0000\">Now a picture:</font></font></b>\n\
|
||||
<br><img SRC=\"http://people.netscape.com/rhp/WSJPicture.GIF\">\n\
|
||||
<br>All done!\n\
|
||||
<br> \n\
|
||||
</body>\n\
|
||||
</html>"};
|
||||
|
||||
static nsresult
|
||||
SetupRegistry(void)
|
||||
{
|
||||
// i18n
|
||||
nsComponentManager::RegisterComponent(kCharsetConverterManagerCID, NULL, NULL, UNICHAR_DLL, PR_FALSE, PR_FALSE);
|
||||
nsresult res = nsServiceManager::GetService(kCharsetConverterManagerCID, NS_GET_IID(nsICharsetConverterManager), (nsISupports **)&ccMan);
|
||||
if (NS_FAILED(res))
|
||||
{
|
||||
printf("ERROR at GetService() code=0x%x.\n",res);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// xpcom
|
||||
nsComponentManager::RegisterComponent(kEventQueueServiceCID, NULL, NULL, XPCOM_DLL, PR_FALSE, PR_FALSE);
|
||||
nsComponentManager::RegisterComponent(kEventQueueCID, NULL, NULL, XPCOM_DLL, PR_FALSE, PR_FALSE);
|
||||
nsComponentManager::RegisterComponent(kGenericFactoryCID, NULL, NULL, XPCOM_DLL, PR_FALSE, PR_FALSE);
|
||||
nsComponentManager::RegisterComponent(kMemoryCID, NULL, NULL, XPCOM_DLL, PR_FALSE, PR_FALSE);
|
||||
|
||||
// prefs
|
||||
nsComponentManager::RegisterComponent(kPrefCID, NULL, NULL, PREF_DLL, PR_FALSE, PR_FALSE);
|
||||
|
||||
nsComponentManager::RegisterComponent(kFileLocatorCID, NULL, NS_FILELOCATOR_CONTRACTID, APPSHELL_DLL, PR_TRUE, PR_TRUE);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIMsgIdentity *
|
||||
GetHackIdentity()
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
NS_WITH_SERVICE(nsIMsgAccountManager, accountManager,
|
||||
NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return nsnull;
|
||||
{
|
||||
printf("Failure on AccountManager Init!\n");
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
|
||||
nsCOMPtr<nsIMsgAccount> account;
|
||||
rv = accountManager->GetDefaultAccount(getter_AddRefs(account));
|
||||
if (NS_FAILED(rv)) return nsnull;
|
||||
|
||||
nsCOMPtr<nsISupportsArray> identities;
|
||||
rv = account->GetIdentities(getter_AddRefs(identities));
|
||||
|
||||
nsCOMPtr<nsIMsgIdentity> identity = nsnull;
|
||||
rv = identities->QueryElementAt(0, NS_GET_IID(nsIMsgIdentity),
|
||||
(void **)getter_AddRefs(identity));
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
printf("Failure getting Identity!\n");
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
return identity;
|
||||
}
|
||||
|
||||
/*
|
||||
* This is a test stub for mail composition. This will be enhanced as the
|
||||
* development continues for message send functions.
|
||||
*/
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
nsIMsgCompFields *pMsgCompFields;
|
||||
nsIMsgSend *pMsgSend;
|
||||
nsresult rv = NS_OK;
|
||||
//nsIAppShellService* appShell = nsnull;
|
||||
|
||||
|
||||
nsComponentManager::RegisterComponent(kEventQueueServiceCID, NULL, NULL, XPCOM_DLL, PR_FALSE, PR_FALSE);
|
||||
nsComponentManager::RegisterComponent(kEventQueueCID, NULL, NULL, XPCOM_DLL, PR_FALSE, PR_FALSE);
|
||||
nsComponentManager::RegisterComponent(kPrefCID, nsnull, nsnull, PREF_DLL, PR_TRUE, PR_TRUE);
|
||||
nsComponentManager::RegisterComponent(kFileLocatorCID, NULL, NS_FILELOCATOR_CONTRACTID, APPSHELL_DLL, PR_TRUE, PR_TRUE);
|
||||
nsComponentManager::RegisterComponent(kNetSupportDialogCID, NULL, NULL, APPSHELL_DLL, PR_FALSE, PR_FALSE);
|
||||
nsComponentManager::RegisterComponent(kAppShellServiceCID, NULL, NULL, APPSHELL_DLL, PR_FALSE, PR_FALSE);
|
||||
|
||||
SetupRegistry();
|
||||
|
||||
// Create the Event Queue for this thread...
|
||||
NS_WITH_SERVICE(nsIEventQueueService, pEventQService, kEventQueueServiceCID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
printf("Failed to get event queue\n");
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = pEventQService->CreateThreadEventQueue();
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
printf("Failed to create event queue\n");
|
||||
return rv;
|
||||
}
|
||||
|
||||
// make sure prefs get initialized and loaded..
|
||||
// mscott - this is just a bad bad bad hack right now until prefs
|
||||
// has the ability to take nsnull as a parameter. Once that happens,
|
||||
// prefs will do the work of figuring out which prefs file to load...
|
||||
NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &rv);
|
||||
if (NS_FAILED(rv) || (prefs == nsnull))
|
||||
{
|
||||
exit(rv);
|
||||
}
|
||||
|
||||
if (NS_FAILED(prefs->StartUp()))
|
||||
{
|
||||
printf("Failed to start up prefs!\n");
|
||||
exit(rv);
|
||||
}
|
||||
if (NS_FAILED(prefs->ReadUserPrefs()))
|
||||
{
|
||||
printf("Failed on reading user prefs!\n");
|
||||
exit(rv);
|
||||
}
|
||||
|
||||
nsIMsgIdentity *identity;
|
||||
identity = GetHackIdentity();
|
||||
SendOperationListener *sendListener = nsnull;
|
||||
|
||||
rv = nsComponentManager::CreateInstance(kMsgSendCID, NULL, NS_GET_IID(nsIMsgSend), (void **) &pMsgSend);
|
||||
if (NS_SUCCEEDED(rv) && pMsgSend)
|
||||
{
|
||||
printf("We succesfully obtained a nsIMsgSend interface....\n");
|
||||
rv = nsComponentManager::CreateInstance(kMsgCompFieldsCID, NULL, NS_GET_IID(nsIMsgCompFields),
|
||||
(void **) &pMsgCompFields);
|
||||
if (NS_SUCCEEDED(rv) && pMsgCompFields)
|
||||
{
|
||||
char *aEmail = nsnull;
|
||||
PRUnichar *aFullName = nsnull;
|
||||
char addr[256];
|
||||
char subject[256];
|
||||
|
||||
identity->GetEmail(&aEmail);
|
||||
identity->GetFullName(&aFullName);
|
||||
PR_snprintf(addr, sizeof(addr), "%s <%s>", aFullName, aEmail);
|
||||
PR_FREEIF(aEmail);
|
||||
PR_FREEIF(aFullName);
|
||||
|
||||
pMsgCompFields->SetFrom(NS_ConvertASCIItoUCS2(addr).GetUnicode());
|
||||
pMsgCompFields->SetTo(NS_ConvertASCIItoUCS2("rhp@netscape.com").GetUnicode());
|
||||
PR_snprintf(subject, sizeof(subject), "Spam from: %s", addr);
|
||||
|
||||
|
||||
pMsgCompFields->SetSubject(NS_ConvertASCIItoUCS2(subject).GetUnicode());
|
||||
// pMsgCompFields->SetTheForcePlainText(PR_TRUE, &rv);
|
||||
pMsgCompFields->SetBody(NS_ConvertASCIItoUCS2(email).GetUnicode());
|
||||
pMsgCompFields->SetCharacterSet(NS_ConvertASCIItoUCS2("us-ascii").GetUnicode());
|
||||
|
||||
pMsgCompFields->SetAttachments(NS_ConvertASCIItoUCS2("http://www.netscape.com").GetUnicode());
|
||||
|
||||
PRInt32 nBodyLength;
|
||||
PRUnichar *pUnicharBody;
|
||||
char *pBody;
|
||||
|
||||
pMsgCompFields->GetBody(&pUnicharBody);
|
||||
pBody = nsAutoString(pUnicharBody).ToNewCString();
|
||||
if (pBody)
|
||||
nBodyLength = PL_strlen(pBody);
|
||||
else
|
||||
nBodyLength = 0;
|
||||
|
||||
nsMsgAttachedFile *localPtr= NULL;
|
||||
nsMsgAttachmentData *remotePtr = NULL;
|
||||
|
||||
|
||||
localPtr = GetLocalAttachments();
|
||||
remotePtr = GetRemoteAttachments();
|
||||
|
||||
sendListener = new SendOperationListener();
|
||||
if (!sendListener)
|
||||
{
|
||||
printf("Failure creating send listener!\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
NS_ADDREF(sendListener);
|
||||
pMsgSend->AddListener(sendListener);
|
||||
pMsgSend->CreateAndSendMessage( nsnull, // No MHTML from here....
|
||||
identity,
|
||||
pMsgCompFields,
|
||||
PR_FALSE, // PRBool digest_p,
|
||||
PR_FALSE, // PRBool dont_deliver_p,
|
||||
nsIMsgSend::nsMsgDeliverNow, // nsMsgDeliverMode mode,
|
||||
nsnull, // nsIMessage *msgToReplace
|
||||
TEXT_HTML, // const char *attachment1_type,
|
||||
pBody, // const char *attachment1_body,
|
||||
nBodyLength, // PRUint32 attachment1_body_length,
|
||||
remotePtr, // const struct nsMsgAttachmentData *attachments,
|
||||
localPtr, // const struct nsMsgAttachedFile *preloaded_attachments,
|
||||
NULL, // nsMsgSendPart *relatedPart,
|
||||
nsnull, 0); // listener array
|
||||
|
||||
PR_FREEIF(localPtr);
|
||||
PR_FREEIF(remotePtr);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(XP_PC) && !defined(XP_OS2)
|
||||
printf("Sitting in an event processing loop ...Hit Cntl-C to exit...");
|
||||
while (keepOnRunning)
|
||||
{
|
||||
MSG msg;
|
||||
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
NS_RELEASE(sendListener);
|
||||
printf("Releasing the interfaces now...\n");
|
||||
pMsgSend->Release();
|
||||
pMsgCompFields->Release();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
Makefile
|
||||
sendlatertest
|
|
@ -1,49 +0,0 @@
|
|||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
PROGRAM = sendlatertest$(BIN_SUFFIX)
|
||||
REQUIRES = xpcom mailnews pref js msgbase msgbaseutil msgcompose msglocal necko editor dom widget layout msgdb appshell
|
||||
|
||||
CPPSRCS = test.cpp
|
||||
|
||||
ifeq ($(USE_SHORT_LIBNAME),1)
|
||||
EXTRA_DSO_LIBS = gkgfx msgbsutl
|
||||
else
|
||||
EXTRA_DSO_LIBS = gkgfx msgbaseutil
|
||||
endif
|
||||
|
||||
LIBS = \
|
||||
$(EXTRA_DSO_LIBS) \
|
||||
$(XPCOM_LIBS) \
|
||||
$(MOZ_JS_LIBS) \
|
||||
$(NSPR_LIBS) \
|
||||
$(TK_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
@ -1,92 +0,0 @@
|
|||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
# New build system where zip dll is build indepenant of java stubs.
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
MODULE =sendlatertest
|
||||
#EXPORTS = \
|
||||
# $(NULL)
|
||||
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Specify the depth of the current directory relative to the
|
||||
#// root of NS
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
DEPTH= ..\..\..\..
|
||||
|
||||
MAKE_OBJ_TYPE=EXE
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Define any Public Make Variables here: (ie. PDFFILE, MAPFILE, ...)
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
EXENAME=TestMSGSendLater
|
||||
PDBFILE=TestMSGSendLater.pdb
|
||||
MAPFILE=TestMSGSendLater.map
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Define the files necessary to build the target (ie. OBJS)
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
OBJS= \
|
||||
.\$(OBJDIR)\test.obj \
|
||||
$(NULL)
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Define any Public Targets here (ie. PROGRAM, LIBRARY, DLL, ...)
|
||||
#// (these must be defined before the common makefiles are included)
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
|
||||
PROGRAM=.\$(OBJDIR)\$(EXENAME).EXE
|
||||
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Define any local options for the make tools
|
||||
#// (ie. LCFLAGS, LLFLAGS, LLIBS, LINCS)
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
LCFLAGS=-DNETSCAPE
|
||||
WIN_LIBS= ole32.lib
|
||||
LLIBS= \
|
||||
$(DIST)\lib\xpcom.lib \
|
||||
$(LIBNSPR) \
|
||||
|
||||
# clobber and clobber_all will remove the following garbage:
|
||||
GARBAGE = $(GARBAGE) _gen
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Include the common makefile rules
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
include <$(DEPTH)/config/rules.mak>
|
||||
|
||||
install:: $(PROGRAM)
|
||||
$(MAKE_INSTALL) $(PROGRAM) $(DIST)\bin\
|
||||
|
||||
clobber::
|
||||
rm -f $(EXENAME).exe
|
|
@ -1,177 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "msgCore.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsMsgBaseCID.h"
|
||||
#include "nsMsgLocalCID.h"
|
||||
#include "nsMsgCompCID.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#if defined(XP_PC) && !defined(XP_OS2)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsMsgCompCID.h"
|
||||
#include "nsIMsgCompose.h"
|
||||
#include "nsIMsgCompFields.h"
|
||||
#include "nsIMsgSend.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nscore.h"
|
||||
#include "nsIMsgAccountManager.h"
|
||||
#include "nsINetSupportDialogService.h"
|
||||
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "nsISmtpService.h"
|
||||
#include "nsISmtpUrl.h"
|
||||
#include "nsIUrlListener.h"
|
||||
#include "nsIEventQueueService.h"
|
||||
#include "nsIEventQueue.h"
|
||||
#include "nsIFileLocator.h"
|
||||
|
||||
#include "nsCRT.h"
|
||||
#include "prmem.h"
|
||||
|
||||
#include "nsIMsgSendLater.h"
|
||||
|
||||
#ifdef XP_PC
|
||||
#define XPCOM_DLL "xpcom32.dll"
|
||||
#define PREF_DLL "xppref32.dll"
|
||||
#define APPSHELL_DLL "appshell.dll"
|
||||
#define MIME_DLL "mime.dll"
|
||||
#else
|
||||
#ifdef XP_MAC
|
||||
#include "nsMacRepository.h"
|
||||
#else
|
||||
#define XPCOM_DLL "libxpcom"MOZ_DLL_SUFFIX
|
||||
#define PREF_DLL "libpref"MOZ_DLL_SUFFIX
|
||||
#define APPSHELL_DLL "libnsappshell"MOZ_DLL_SUFFIX
|
||||
#define MIME_DLL "libmime"MOZ_DLL_SUFFIX
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// Define keys for all of the interfaces we are going to require for this test
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
||||
static NS_DEFINE_CID(kFileLocatorCID, NS_FILELOCATOR_CID);
|
||||
static NS_DEFINE_CID(kEventQueueCID, NS_EVENTQUEUE_CID);
|
||||
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
|
||||
static NS_DEFINE_CID(kNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID);
|
||||
static NS_DEFINE_CID(kMsgSendLaterCID, NS_MSGSENDLATER_CID);
|
||||
|
||||
|
||||
/*
|
||||
* This is a test stub for mail composition. This will be enhanced as the
|
||||
* development continues for message send functions.
|
||||
*/
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsComponentManager::RegisterComponent(kEventQueueServiceCID, NULL, NULL, XPCOM_DLL, PR_FALSE, PR_FALSE);
|
||||
nsComponentManager::RegisterComponent(kEventQueueCID, NULL, NULL, XPCOM_DLL, PR_FALSE, PR_FALSE);
|
||||
nsComponentManager::RegisterComponent(kPrefCID, nsnull, nsnull, PREF_DLL, PR_TRUE, PR_TRUE);
|
||||
nsComponentManager::RegisterComponent(kFileLocatorCID, NULL, NS_FILELOCATOR_CONTRACTID, APPSHELL_DLL, PR_FALSE, PR_FALSE);
|
||||
nsComponentManager::RegisterComponent(kNetSupportDialogCID, NULL, NULL, APPSHELL_DLL, PR_FALSE, PR_FALSE);
|
||||
|
||||
// Create the Event Queue for this thread...
|
||||
NS_WITH_SERVICE(nsIEventQueueService, pEventQService, kEventQueueServiceCID, &rv);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
printf("Failed to get event queue\n");
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = pEventQService->CreateThreadEventQueue();
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
printf("Failed to create event queue\n");
|
||||
return rv;
|
||||
}
|
||||
|
||||
// make sure prefs get initialized and loaded..
|
||||
// mscott - this is just a bad bad bad hack right now until prefs
|
||||
// has the ability to take nsnull as a parameter. Once that happens,
|
||||
// prefs will do the work of figuring out which prefs file to load...
|
||||
NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &rv);
|
||||
if (NS_FAILED(rv) || (prefs == nsnull)) {
|
||||
exit(rv);
|
||||
}
|
||||
if (NS_FAILED(prefs->ReadUserPrefs()))
|
||||
{
|
||||
printf("Failed on reading user prefs!\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
||||
NS_WITH_SERVICE(nsIMsgAccountManager, accountManager, NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
printf("Failure getting Mail Session!\n");
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIMsgAccount> account;
|
||||
rv = accountManager->GetDefaultAccount(getter_AddRefs(account));
|
||||
if (NS_FAILED(rv)) return nsnull;
|
||||
|
||||
nsCOMPtr<nsISupportsArray> identities;
|
||||
rv = account->GetIdentities(getter_AddRefs(identities));
|
||||
|
||||
nsCOMPtr<nsIMsgIdentity> identity = nsnull;
|
||||
rv = identities->QueryElementAt(0, NS_GET_IID(nsIMsgIdentity),
|
||||
(void **)getter_AddRefs(identity));
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
printf("Failure getting Identity!\n");
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIMsgSendLater> pMsgSendLater;
|
||||
rv = nsComponentManager::CreateInstance(kMsgSendLaterCID, NULL, NS_GET_IID(nsIMsgSendLater),
|
||||
(void **) getter_AddRefs(pMsgSendLater));
|
||||
if (NS_SUCCEEDED(rv) && pMsgSendLater)
|
||||
{
|
||||
printf("We succesfully obtained a nsIMsgSendLater interface....\n");
|
||||
pMsgSendLater->SendUnsentMessages(identity, nsnull);
|
||||
}
|
||||
|
||||
#if defined(XP_PC) && !defined(XP_OS2)
|
||||
printf("Sitting in an event processing loop ...Hit Cntl-C to exit...");
|
||||
while (1)
|
||||
{
|
||||
MSG msg;
|
||||
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
Makefile
|
||||
smtpTest
|
|
@ -1,40 +0,0 @@
|
|||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
PROGRAM = smtpTest
|
||||
|
||||
CPPSRCS = smtpTest.cpp
|
||||
|
||||
LIBS = \
|
||||
$(XPCOM_LIBS) \
|
||||
$(NSPR_LIBS) \
|
||||
$(TK_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
|
||||
DEPTH=..\..\..\..
|
||||
|
||||
MAKE_OBJ_TYPE = EXE
|
||||
PROGRAM = .\$(OBJDIR)\smtpTest.exe
|
||||
|
||||
OBJS = \
|
||||
.\$(OBJDIR)\smtpTest.obj \
|
||||
$(NULL)
|
||||
|
||||
LLIBS= \
|
||||
$(DIST)\lib\xpcom.lib \
|
||||
$(LIBNSPR) \
|
||||
$(DIST)\lib\gkgfxwin.lib \
|
||||
$(DIST)\lib\gkwidget.lib \
|
||||
$(NULL)
|
||||
|
||||
LLFLAGS=-SUBSYSTEM:CONSOLE
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(PROGRAM)
|
||||
$(MAKE_INSTALL) $(PROGRAM) $(DIST)\bin
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\bin\Mailer.exe
|
||||
|
||||
$(PROGRAM):: $(OBJS) $(MYLIBS)
|
|
@ -1,490 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||
*/
|
||||
|
||||
#include "msgCore.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "prprf.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
#if defined(XP_PC) && !defined(XP_OS2)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "plstr.h"
|
||||
#include "plevent.h"
|
||||
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "nsISmtpService.h"
|
||||
#include "nsISmtpUrl.h"
|
||||
#include "nsIMsgMailNewsUrl.h"
|
||||
#include "nsIUrlListener.h"
|
||||
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIEventQueueService.h"
|
||||
#include "nsIEventQueue.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsIFileLocator.h"
|
||||
#include "nsFileSpec.h"
|
||||
#include "nsIFileSpec.h"
|
||||
#include "nsMsgCompCID.h"
|
||||
#include "nsIMsgIdentity.h"
|
||||
|
||||
#ifdef XP_PC
|
||||
#define XPCOM_DLL "xpcom32.dll"
|
||||
#define PREF_DLL "xppref32.dll"
|
||||
#define APPSHELL_DLL "appshell.dll"
|
||||
#else
|
||||
#ifdef XP_MAC
|
||||
#else
|
||||
#define XPCOM_DLL "libxpcom"MOZ_DLL_SUFFIX
|
||||
#define PREF_DLL "libpref"MOZ_DLL_SUFFIX
|
||||
#define APPSHELL_DLL "libnsappshell"MOZ_DLL_SUFFIX
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// Define keys for all of the interfaces we are going to require for this test
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
||||
static NS_DEFINE_CID(kSmtpServiceCID, NS_SMTPSERVICE_CID);
|
||||
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
|
||||
static NS_DEFINE_CID(kFileLocatorCID, NS_FILELOCATOR_CID);
|
||||
static NS_DEFINE_CID(kEventQueueCID, NS_EVENTQUEUE_CID);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// Define default values to be used to drive the test
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define DEFAULT_HOST "nsmail-2.mcom.com"
|
||||
#define DEFAULT_PORT 25 /* we get this value from SmtpCore.h */
|
||||
#define DEFAULT_URL_TYPE "mailto://" /* do NOT change this value until netlib re-write is done...*/
|
||||
#define DEFAULT_RECIPIENT "mscott@netscape.com"
|
||||
#define DEFAULT_FILE "message.eml"
|
||||
#define DEFAULT_SENDER "qatest03@netscape.com"
|
||||
#define DEFAULT_PASSWORD "Ne!sc-pe"
|
||||
|
||||
//extern NET_StreamClass *MIME_MessageConverter(int format_out, void *closure,
|
||||
// URL_Struct *url, MWContext *context);
|
||||
|
||||
#ifdef XP_UNIX
|
||||
extern "C" char *fe_GetConfigDir(void) {
|
||||
printf("XXX: return /tmp for fe_GetConfigDir\n");
|
||||
return PL_strdup("/tmp");
|
||||
}
|
||||
#endif /* XP_UNIX */
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// This function is used to load and prepare an smtp url which can be run by
|
||||
// a transport instance. For different protocols, you'll have different url
|
||||
// functions like this one in the test harness...
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/* strip out non-printable characters */
|
||||
static void strip_nonprintable(char *string) {
|
||||
char *dest, *src;
|
||||
|
||||
dest=src=string;
|
||||
while (*src) {
|
||||
if (isprint(*src)) {
|
||||
(*src)=(*dest);
|
||||
src++; dest++;
|
||||
} else {
|
||||
src++;
|
||||
}
|
||||
}
|
||||
(*dest)='\0';
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// The nsSmtpTestDriver is a class that I envision could be generalized to form the
|
||||
// building block of a protocol test harness. To configure it, you would list all of
|
||||
// the events you know how to handle and when one of those events is triggered, you
|
||||
// would be asked to process it....right now it is just Smtp specific....
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsSmtpTestDriver : public nsIUrlListener
|
||||
{
|
||||
public:
|
||||
nsSmtpTestDriver(nsIEventQueue *queue);
|
||||
virtual ~nsSmtpTestDriver();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIUrlListener support
|
||||
NS_IMETHOD OnStartRunningUrl(nsIURI * aUrl);
|
||||
NS_IMETHOD OnStopRunningUrl(nsIURI * aUrl, nsresult aExitCode);
|
||||
|
||||
// run driver initializes the instance, lists the commands, runs the command and when
|
||||
// the command is finished, it reads in the next command and continues...theoretically,
|
||||
// the client should only ever have to call RunDriver(). It should do the rest of the
|
||||
// work....
|
||||
nsresult RunDriver();
|
||||
|
||||
// User drive commands
|
||||
void InitializeTestDriver(); // will end up prompting the user for things like host, port, etc.
|
||||
nsresult ListCommands(); // will list all available commands to the user...i.e. "get groups, get article, etc."
|
||||
nsresult ReadAndDispatchCommand(); // reads a command number in from the user and calls the appropriate command generator
|
||||
nsresult PromptForUserDataAndBuildUrl(const char * userPrompt);
|
||||
|
||||
// The following are event generators. They convert all of the available user commands into
|
||||
// URLs and then run the urls.
|
||||
nsresult OnSendMessageInFile();
|
||||
nsresult OnExit();
|
||||
protected:
|
||||
nsIEventQueue *m_eventQueue;
|
||||
char m_urlSpec[200]; // "sockstub://hostname:port" it does not include the command specific data...
|
||||
char m_urlString[500]; // string representing the current url being run. Includes host AND command specific data.
|
||||
char m_userData[250]; // generic string buffer for storing the current user entered data...
|
||||
|
||||
// host and port info...
|
||||
PRUint32 m_port;
|
||||
char m_host[200];
|
||||
PRBool m_runningURL;
|
||||
PRBool m_runTestHarness;
|
||||
|
||||
nsISmtpService *m_smtpService;
|
||||
nsCOMPtr<nsISmtpUrl> m_smtpUrl;
|
||||
|
||||
nsresult SetupUrl(char *group);
|
||||
PRBool m_protocolInitialized;
|
||||
};
|
||||
|
||||
nsresult nsSmtpTestDriver::OnStartRunningUrl(nsIURI * aUrl)
|
||||
{
|
||||
NS_PRECONDITION(aUrl, "just a sanity check since this is a test program");
|
||||
m_runningURL = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsSmtpTestDriver::OnStopRunningUrl(nsIURI * aUrl, nsresult aExitCode)
|
||||
{
|
||||
NS_PRECONDITION(aUrl, "just a sanity check since this is a test program");
|
||||
//nsresult rv = NS_OK;
|
||||
m_runningURL = PR_FALSE;
|
||||
if (aUrl)
|
||||
{
|
||||
// query it for a mailnews interface for now....
|
||||
nsCOMPtr<nsIMsgMailNewsUrl> mailUrl = do_QueryInterface(aUrl);
|
||||
if (mailUrl)
|
||||
mailUrl->UnRegisterListener(this);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// the following strings are used by QA as part of the smoketest. DO NOT REMOVE THEM!!!!!!!
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
if (NS_SUCCEEDED(aExitCode))
|
||||
printf("\nMessage Sent: PASSED\n");
|
||||
else
|
||||
printf("\nMessage Sent: FAILED!\n");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsSmtpTestDriver::nsSmtpTestDriver(nsIEventQueue *queue)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
m_urlSpec[0] = '\0';
|
||||
m_urlString[0] = '\0';
|
||||
m_protocolInitialized = PR_FALSE;
|
||||
m_runningURL = PR_FALSE;
|
||||
m_runTestHarness = PR_TRUE;
|
||||
m_eventQueue = queue;
|
||||
NS_IF_ADDREF(m_eventQueue);
|
||||
|
||||
InitializeTestDriver(); // prompts user for initialization information...
|
||||
|
||||
m_smtpService = nsnull;
|
||||
nsServiceManager::GetService(kSmtpServiceCID, NS_GET_IID(nsISmtpService),
|
||||
(nsISupports **)&m_smtpService); // XXX probably need shutdown listener here
|
||||
}
|
||||
|
||||
|
||||
nsSmtpTestDriver::~nsSmtpTestDriver()
|
||||
{
|
||||
NS_IF_RELEASE(m_eventQueue);
|
||||
nsServiceManager::ReleaseService(kSmtpServiceCID, m_smtpService); // XXX probably need shutdown listener here
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsSmtpTestDriver, NS_GET_IID(nsIUrlListener))
|
||||
|
||||
nsresult nsSmtpTestDriver::RunDriver()
|
||||
{
|
||||
nsresult status = NS_OK;
|
||||
|
||||
while (m_runTestHarness)
|
||||
{
|
||||
if (m_runningURL == PR_FALSE) // can we run and dispatch another command?
|
||||
status = ReadAndDispatchCommand(); // run a new url
|
||||
|
||||
// if running url
|
||||
#ifdef XP_UNIX
|
||||
|
||||
m_eventQueue->ProcessPendingEvents();
|
||||
|
||||
#endif
|
||||
#if defined(XP_PC) && !defined(XP_OS2)
|
||||
|
||||
MSG msg;
|
||||
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
#endif
|
||||
|
||||
} // until the user has stopped running the url (which is really the test session.....
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
void nsSmtpTestDriver::InitializeTestDriver()
|
||||
{
|
||||
// prompt the user for port and host name
|
||||
char portString[20]; // used to read in the port string
|
||||
char hostString[200];
|
||||
portString[0] = '\0';
|
||||
hostString[0] = '\0';
|
||||
m_host[0] = '\0';
|
||||
m_port = DEFAULT_PORT;
|
||||
|
||||
// load default host name and set the start of the url
|
||||
PL_strcpy(m_host, DEFAULT_HOST);
|
||||
PL_strcpy(m_urlSpec, DEFAULT_URL_TYPE); // copy "sockstub://" part into url spec...
|
||||
|
||||
// prompt user for port...
|
||||
printf("Enter port to use [%d]: ", m_port);
|
||||
fgets(portString, sizeof(portString), stdin);
|
||||
strip_nonprintable(portString);
|
||||
if (portString && *portString)
|
||||
{
|
||||
m_port = atoi(portString);
|
||||
}
|
||||
|
||||
// now prompt for the host name....
|
||||
printf("Enter host name to use [%s]: ", m_host);
|
||||
fgets(hostString, sizeof(hostString), stdin);
|
||||
strip_nonprintable(hostString);
|
||||
if(hostString && *hostString)
|
||||
{
|
||||
PL_strcpy(m_host, hostString);
|
||||
}
|
||||
|
||||
PL_strcat(m_urlSpec, m_host);
|
||||
// we'll actually build the url (spec + user data) once the user has specified a command they want to try...
|
||||
}
|
||||
|
||||
// prints the userPrompt and then reads in the user data. Assumes urlData has already been allocated.
|
||||
// it also reconstructs the url string in m_urlString but does NOT reload it....
|
||||
nsresult nsSmtpTestDriver::PromptForUserDataAndBuildUrl(const char * userPrompt)
|
||||
{
|
||||
char tempBuffer[500];
|
||||
tempBuffer[0] = '\0';
|
||||
|
||||
if (userPrompt)
|
||||
printf(userPrompt);
|
||||
else
|
||||
printf("Enter data for command: ");
|
||||
|
||||
fgets(tempBuffer, sizeof(tempBuffer), stdin);
|
||||
strip_nonprintable(tempBuffer);
|
||||
// only replace m_userData if the user actually entered a valid line...
|
||||
// this allows the command function to set a default value on m_userData before
|
||||
// calling this routine....
|
||||
if (tempBuffer && *tempBuffer)
|
||||
PL_strcpy(m_userData, tempBuffer);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsSmtpTestDriver::ReadAndDispatchCommand()
|
||||
{
|
||||
nsresult status = NS_OK;
|
||||
PRInt32 command = 0;
|
||||
char commandString[5];
|
||||
commandString[0] = '\0';
|
||||
|
||||
printf("Enter command number: ");
|
||||
fgets(commandString, sizeof(commandString), stdin);
|
||||
strip_nonprintable(commandString);
|
||||
if (commandString && *commandString)
|
||||
{
|
||||
command = atoi(commandString);
|
||||
}
|
||||
|
||||
// now switch on command to the appropriate
|
||||
switch (command)
|
||||
{
|
||||
case 0:
|
||||
status = ListCommands();
|
||||
break;
|
||||
case 1:
|
||||
status = OnSendMessageInFile();
|
||||
break;
|
||||
default:
|
||||
status = OnExit();
|
||||
break;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
nsresult nsSmtpTestDriver::ListCommands()
|
||||
{
|
||||
printf("Commands currently available: \n");
|
||||
printf("0) List commands. \n");
|
||||
printf("1) Send a message in a file. \n");
|
||||
printf("9) Exit the test application. \n");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Begin protocol specific command url generation code...gee that's a mouthful....
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult nsSmtpTestDriver::OnExit()
|
||||
{
|
||||
printf("Terminating Smtp test harness....\n");
|
||||
m_runTestHarness = PR_FALSE; // next time through the test driver loop, we'll kick out....
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsSmtpTestDriver::OnSendMessageInFile()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
char * fileName = nsnull;
|
||||
char * userName = nsnull;
|
||||
//char * userPassword = nsnull;
|
||||
char * displayString = nsnull;
|
||||
char * recipients = nsnull;
|
||||
|
||||
PL_strcpy(m_userData, DEFAULT_FILE);
|
||||
|
||||
displayString = PR_smprintf("Location of message [%s]: ", m_userData);
|
||||
rv = PromptForUserDataAndBuildUrl(displayString);
|
||||
PR_FREEIF(displayString);
|
||||
|
||||
fileName = PL_strdup(m_userData);
|
||||
|
||||
// now ask the user who to send the message too...
|
||||
PL_strcpy(m_userData, DEFAULT_RECIPIENT);
|
||||
displayString = PR_smprintf("Recipient of message [%s]: ", m_userData);
|
||||
rv = PromptForUserDataAndBuildUrl(displayString);
|
||||
PR_FREEIF(displayString);
|
||||
|
||||
recipients = PL_strdup(m_userData);
|
||||
|
||||
// SMTP is a connectionless protocol...so we always start with a new
|
||||
// SMTP protocol instance every time we launch a mailto url...
|
||||
|
||||
nsFilePath filePath (fileName);
|
||||
nsFileSpec aFileSpec (fileName);
|
||||
nsCOMPtr<nsIFileSpec> aIFileSpec;
|
||||
NS_NewFileSpecWithSpec(aFileSpec, getter_AddRefs(aIFileSpec));
|
||||
|
||||
|
||||
nsIURI * url = nsnull;
|
||||
nsCOMPtr <nsIMsgIdentity> senderIdentity;
|
||||
senderIdentity = null_nsCOMPtr();
|
||||
|
||||
printf("passing in null for the sender identity will cause the send to fail, but at least it builds. I need to talk to rhp / mscott about this.\n");
|
||||
|
||||
m_smtpService->SendMailMessage(aIFileSpec, recipients, senderIdentity, this, nsnull, &url);
|
||||
if (url)
|
||||
m_smtpUrl = do_QueryInterface(url);
|
||||
|
||||
NS_IF_RELEASE(url);
|
||||
|
||||
|
||||
PR_FREEIF(fileName);
|
||||
PR_FREEIF(userName);
|
||||
PR_FREEIF(recipients);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// End on command handlers for news
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int main()
|
||||
{
|
||||
nsIEventQueue *queue;
|
||||
nsresult result;
|
||||
|
||||
nsComponentManager::RegisterComponent(kEventQueueServiceCID, NULL, NULL, XPCOM_DLL, PR_FALSE, PR_FALSE);
|
||||
nsComponentManager::RegisterComponent(kEventQueueCID, NULL, NULL, XPCOM_DLL, PR_FALSE, PR_FALSE);
|
||||
result = nsComponentManager::RegisterComponent(kPrefCID, nsnull, nsnull, PREF_DLL, PR_TRUE, PR_TRUE);
|
||||
nsComponentManager::RegisterComponent(kFileLocatorCID, NULL, NS_FILELOCATOR_CONTRACTID, APPSHELL_DLL, PR_FALSE, PR_FALSE);
|
||||
|
||||
result = nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup, NULL /* default */);
|
||||
|
||||
// make sure prefs get initialized and loaded..
|
||||
// mscott - this is just a bad bad bad hack right now until prefs
|
||||
// has the ability to take nsnull as a parameter. Once that happens,
|
||||
// prefs will do the work of figuring out which prefs file to load...
|
||||
NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &result);
|
||||
if (NS_FAILED(result) || (prefs == nsnull)) {
|
||||
exit(result);
|
||||
}
|
||||
prefs->StartUp();
|
||||
if (NS_FAILED(prefs->ReadUserPrefs()))
|
||||
{
|
||||
printf("Failed on reading user prefs!\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// Create the Event Queue for this thread...
|
||||
NS_WITH_SERVICE(nsIEventQueueService, pEventQService, kEventQueueServiceCID, &result);
|
||||
|
||||
if (NS_FAILED(result)) return result;
|
||||
|
||||
result = pEventQService->CreateThreadEventQueue();
|
||||
if (NS_FAILED(result)) return result;
|
||||
|
||||
result = pEventQService->GetThreadEventQueue(NS_CURRENT_THREAD,&queue);
|
||||
if (NS_FAILED(result) || !queue) {
|
||||
printf("unable to get event queue.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// okay, everything is set up, now we just need to create a test driver and run it...
|
||||
nsSmtpTestDriver * driver = new nsSmtpTestDriver(queue);
|
||||
if (driver)
|
||||
{
|
||||
NS_ADDREF(driver);
|
||||
driver->RunDriver();
|
||||
// when it kicks out...it is done....so delete it...
|
||||
NS_RELEASE(driver);
|
||||
}
|
||||
NS_IF_RELEASE(queue);
|
||||
return NS_OK;
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
Makefile
|
|
@ -1,32 +0,0 @@
|
|||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = harness
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
Makefile
|
||||
testimap
|
|
@ -1,52 +0,0 @@
|
|||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = msgimaptest
|
||||
PROGRAM = testimap$(BIN_SUFFIX)
|
||||
REQUIRES = xpcom mailnews msgimap necko msgbase msgbaseutil msglocal txmgr msgdb rdf rdfutil intl locale mork mime pref js appshell
|
||||
|
||||
CPPSRCS = imapProtocolTest.cpp
|
||||
|
||||
EXTRA_DSO_LIBS = msgimap_s rdfutil_s
|
||||
|
||||
ifeq ($(USE_SHORT_LIBNAME),1)
|
||||
EXTRA_DSO_LIBS += msgbsutl
|
||||
else
|
||||
EXTRA_DSO_LIBS += msgbaseutil
|
||||
endif
|
||||
|
||||
LIBS = \
|
||||
-L$(DIST)/bin \
|
||||
$(EXTRA_DSO_LIBS) \
|
||||
$(XPCOM_LIBS) \
|
||||
$(NSPR_LIBS) \
|
||||
$(TK_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
@ -1,711 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||
*/
|
||||
|
||||
#include "msgCore.h"
|
||||
#include "prprf.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
#if defined(XP_PC) && !defined(XP_OS2)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "plstr.h"
|
||||
#include "plevent.h"
|
||||
|
||||
#include "nsIURL.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "nsIUrlListener.h"
|
||||
|
||||
#include "nsIPref.h"
|
||||
#include "nsIFileLocator.h"
|
||||
|
||||
#include "nsIImapUrl.h"
|
||||
#include "nsIImapProtocol.h"
|
||||
#include "nsIMsgIncomingServer.h"
|
||||
#include "nsIImapIncomingServer.h"
|
||||
#include "nsIImapService.h"
|
||||
#include "nsIMsgAccountManager.h"
|
||||
#include "nsIImapMailFolderSink.h"
|
||||
#include "nsIImapMessageSink.h"
|
||||
#include "nsIImapExtensionSink.h"
|
||||
#include "nsIImapMiscellaneousSink.h"
|
||||
|
||||
#include "nsIEventQueueService.h"
|
||||
#include "nsIEventQueue.h"
|
||||
#include "nsFileSpec.h"
|
||||
#include "nsMsgDBCID.h"
|
||||
#include "nsMsgImapCID.h"
|
||||
|
||||
#include "nsMsgDatabase.h"
|
||||
#include "nsLocalFolderSummarySpec.h"
|
||||
#include "nsImapFlagAndUidState.h"
|
||||
#include "nsParseMailbox.h"
|
||||
#include "nsImapMailFolder.h"
|
||||
#include "nsIRDFResource.h"
|
||||
#include "nsIMsgMailNewsUrl.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsMsgBaseCID.h"
|
||||
|
||||
#ifdef XP_PC
|
||||
#define NETLIB_DLL "netlib.dll"
|
||||
#define XPCOM_DLL "xpcom32.dll"
|
||||
#define PREF_DLL "xppref32.dll"
|
||||
#define MSGIMAP_DLL "msgimap.dll"
|
||||
#define APPSHELL_DLL "appshell.dll"
|
||||
#else
|
||||
#ifdef XP_MAC
|
||||
#include "nsMacRepository.h"
|
||||
#else
|
||||
#define NETLIB_DLL "libnetlib"MOZ_DLL_SUFFIX
|
||||
#define XPCOM_DLL "libxpcom"MOZ_DLL_SUFFIX
|
||||
#define PREF_DLL "libpref"MOZ_DLL_SUFFIX
|
||||
#define MSGIMAP_DLL "libmsgimap"MOZ_DLL_SUFFIX
|
||||
#define APPSHELL_DLL "libnsappshell"MOZ_DLL_SUFFIX
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// this is only needed as long as our libmime hack is in place
|
||||
#include "prio.h"
|
||||
|
||||
#ifdef XP_UNIX
|
||||
#define ARTICLE_PATH "/usr/tmp/tempArticle.eml"
|
||||
#define ARTICLE_PATH_URL ARTICLE_PATH
|
||||
#endif
|
||||
|
||||
#ifdef XP_BEOS
|
||||
#define ARTICLE_PATH "/tmp/tempArticle.eml"
|
||||
#define ARTICLE_PATH_URL ARTICLE_PATH
|
||||
#endif
|
||||
|
||||
#ifdef XP_PC
|
||||
#define ARTICLE_PATH "c:\\temp\\tempArticle.eml"
|
||||
#define ARTICLE_PATH_URL "C|/temp/tempArticle.eml"
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// Define keys for all of the interfaces we are going to require for this test
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
||||
static NS_DEFINE_CID(kEventQueueCID, NS_EVENTQUEUE_CID);
|
||||
static NS_DEFINE_CID(kImapUrlCID, NS_IMAPURL_CID);
|
||||
static NS_DEFINE_CID(kImapProtocolCID, NS_IMAPPROTOCOL_CID);
|
||||
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
|
||||
static NS_DEFINE_CID(kFileLocatorCID, NS_FILELOCATOR_CID);
|
||||
|
||||
static NS_DEFINE_CID(kCImapService, NS_IMAPSERVICE_CID);
|
||||
static NS_DEFINE_CID(kCImapDB, NS_IMAPDB_CID);
|
||||
static NS_DEFINE_CID(kCImapResource, NS_IMAPRESOURCE_CID);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// Define default values to be used to drive the test
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define DEFAULT_HOST "nsmail-2.mcom.com"
|
||||
#define DEFAULT_PORT IMAP_PORT
|
||||
#define DEFAULT_URL_TYPE "imap://" /* do NOT change this value until netlib re-write is done...*/
|
||||
|
||||
class nsIMAP4TestDriver : public nsIUrlListener
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIUrlListener support
|
||||
NS_IMETHOD OnStartRunningUrl(nsIURI * aUrl);
|
||||
NS_IMETHOD OnStopRunningUrl(nsIURI * aUrl, nsresult aExitCode);
|
||||
|
||||
nsIMAP4TestDriver(nsIEventQueue *queue);
|
||||
virtual ~nsIMAP4TestDriver();
|
||||
|
||||
// run driver initializes the instance, lists the commands, runs the command and when
|
||||
// the command is finished, it reads in the next command and continues...theoretically,
|
||||
// the client should only ever have to call RunDriver(). It should do the rest of the
|
||||
// work....
|
||||
nsresult RunDriver();
|
||||
|
||||
// User drive commands
|
||||
nsresult ListCommands(); // will list all available commands to the user...i.e. "get groups, get article, etc."
|
||||
nsresult ReadAndDispatchCommand(); // reads a command number in from the user and calls the appropriate command generator
|
||||
nsresult PromptForUserData(const char * userPrompt);
|
||||
void SetupInbox();
|
||||
|
||||
// command handlers
|
||||
nsresult OnCommand(); // send a command to the imap server
|
||||
nsresult OnRunIMAPCommand();
|
||||
nsresult OnGet();
|
||||
nsresult OnIdentityCheck();
|
||||
nsresult OnTestUrlParsing();
|
||||
nsresult OnSelectFolder();
|
||||
nsresult OnFetchMessage();
|
||||
nsresult OnExit();
|
||||
protected:
|
||||
char m_command[500]; // command to run
|
||||
char m_urlString[500]; // string representing the current url being run. Includes host AND command specific data.
|
||||
char m_userData[250]; // generic string buffer for storing the current user entered data...
|
||||
char m_urlSpec[200]; // "imap://hostname:port/" it does not include the command specific data...
|
||||
|
||||
// host and port info...
|
||||
PRUint32 m_port;
|
||||
char m_host[200];
|
||||
|
||||
nsIMsgFolder* m_inbox;
|
||||
nsIImapUrl * m_url;
|
||||
nsParseMailMessageState *m_msgParser ;
|
||||
nsMsgKey m_curMsgUid;
|
||||
PRInt32 m_nextMessageByteLength;
|
||||
nsIMsgDatabase * m_mailDB ;
|
||||
PRBool m_runTestHarness;
|
||||
PRBool m_runningURL; // are we currently running a url? this flag is set to false when the url finishes...
|
||||
|
||||
// part of temporary libmime converstion trick......these should go away once MIME uses a new stream
|
||||
// converter interface...
|
||||
PRFileDesc* m_tempArticleFile;
|
||||
|
||||
|
||||
nsIEventQueue *m_eventQueue;
|
||||
};
|
||||
|
||||
nsIMAP4TestDriver::nsIMAP4TestDriver(nsIEventQueue *queue)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
m_inbox = 0;
|
||||
m_urlSpec[0] = '\0';
|
||||
m_urlString[0] = '\0';
|
||||
m_url = nsnull;
|
||||
m_runTestHarness = PR_TRUE;
|
||||
m_runningURL = PR_FALSE;
|
||||
m_eventQueue = queue;
|
||||
NS_IF_ADDREF(queue);
|
||||
|
||||
m_msgParser = nsnull;
|
||||
m_mailDB = nsnull;
|
||||
m_curMsgUid = nsMsgKey_None;
|
||||
|
||||
// until we read from the prefs, just use the default, I guess.
|
||||
strcpy(m_urlSpec, DEFAULT_URL_TYPE);
|
||||
strcat(m_urlSpec, DEFAULT_HOST);
|
||||
strcat(m_urlSpec, "/");
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsIMAP4TestDriver)
|
||||
NS_IMPL_RELEASE(nsIMAP4TestDriver)
|
||||
|
||||
nsresult
|
||||
nsIMAP4TestDriver::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
if (nsnull == aInstancePtr)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aInstancePtr = nsnull;
|
||||
|
||||
if (aIID.Equals(NS_GET_IID(nsIUrlListener)))
|
||||
{
|
||||
*aInstancePtr = (void*)(nsIUrlListener*)this;
|
||||
}
|
||||
else if (aIID.Equals(kISupportsIID))
|
||||
{
|
||||
*aInstancePtr = (void*)(nsISupports*)(nsIUrlListener*)this;
|
||||
}
|
||||
else
|
||||
return NS_NOINTERFACE;
|
||||
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsIMAP4TestDriver::~nsIMAP4TestDriver()
|
||||
{
|
||||
NS_IF_RELEASE(m_eventQueue);
|
||||
NS_IF_RELEASE(m_url);
|
||||
if (m_mailDB)
|
||||
m_mailDB->Commit(nsMsgDBCommitType::kLargeCommit);
|
||||
NS_IF_RELEASE(m_mailDB);
|
||||
NS_IF_RELEASE (m_inbox);
|
||||
}
|
||||
|
||||
nsresult nsIMAP4TestDriver::RunDriver()
|
||||
{
|
||||
nsresult status = NS_OK;
|
||||
|
||||
while (m_runTestHarness)
|
||||
{
|
||||
if (!m_runningURL) // if we aren't running the url anymore, ask ueser for another command....
|
||||
{
|
||||
status = ReadAndDispatchCommand();
|
||||
} // if running url
|
||||
#ifdef XP_UNIX
|
||||
m_eventQueue->ProcessPendingEvents();
|
||||
#endif
|
||||
#if defined(XP_PC) && !defined(XP_OS2)
|
||||
MSG msg;
|
||||
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
#endif
|
||||
|
||||
} // until the user has stopped running the url (which is really the test session.....
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
nsresult nsIMAP4TestDriver::ReadAndDispatchCommand()
|
||||
{
|
||||
nsresult status = NS_OK;
|
||||
PRInt32 command = 0;
|
||||
char commandString[5];
|
||||
commandString[0] = '\0';
|
||||
|
||||
printf("Enter command number: ");
|
||||
scanf("%[^\n]", commandString);
|
||||
if (commandString && *commandString)
|
||||
{
|
||||
command = atoi(commandString);
|
||||
}
|
||||
scanf("%c", commandString); // eat the extra CR
|
||||
|
||||
// now switch on command to the appropriate
|
||||
switch (command)
|
||||
{
|
||||
case 0:
|
||||
status = ListCommands();
|
||||
break;
|
||||
case 1:
|
||||
status = OnRunIMAPCommand();
|
||||
break;
|
||||
case 2:
|
||||
status = OnIdentityCheck();
|
||||
break;
|
||||
case 3:
|
||||
status = OnTestUrlParsing();
|
||||
break;
|
||||
case 4:
|
||||
status = OnSelectFolder();
|
||||
break;
|
||||
case 5:
|
||||
status = OnFetchMessage();
|
||||
break;
|
||||
default:
|
||||
status = OnExit();
|
||||
break;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
nsresult nsIMAP4TestDriver::ListCommands()
|
||||
{
|
||||
printf("Commands currently available: \n");
|
||||
printf("0) List available commands. \n");
|
||||
printf("1) Run IMAP Command. \n");
|
||||
printf("2) Check identity information.\n");
|
||||
printf("3) Test url parsing. \n");
|
||||
printf("4) Select Folder. \n");
|
||||
printf("5) Download a message. \n");
|
||||
printf("9) Exit the test application. \n");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Begin protocol specific command url generation code...gee that's a mouthful....
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult nsIMAP4TestDriver::OnStartRunningUrl(nsIURI * aUrl)
|
||||
{
|
||||
NS_PRECONDITION(aUrl, "just a sanity check since this is a test program");
|
||||
m_runningURL = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsIMAP4TestDriver::OnStopRunningUrl(nsIURI * aUrl, nsresult aExitCode)
|
||||
{
|
||||
NS_PRECONDITION(aUrl, "just a sanity check since this is a test program");
|
||||
nsresult rv = NS_OK;
|
||||
m_runningURL = PR_FALSE;
|
||||
if (aUrl)
|
||||
{
|
||||
// query it for a mailnews interface for now....
|
||||
nsIMsgMailNewsUrl * mailUrl = nsnull;
|
||||
rv = aUrl->QueryInterface(NS_GET_IID(nsIMsgMailNewsUrl), (void **) mailUrl);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
// our url must be done so release it...
|
||||
NS_IF_RELEASE(m_url);
|
||||
m_url = nsnull;
|
||||
mailUrl->UnRegisterListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult nsIMAP4TestDriver::OnExit()
|
||||
{
|
||||
printf("Terminating IMAP4 test harness....\n");
|
||||
m_runTestHarness = PR_FALSE; // next time through the test driver loop, we'll kick out....
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsIMAP4TestDriver::OnIdentityCheck()
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
|
||||
NS_WITH_SERVICE(nsIMsgAccountManager, accountManager,
|
||||
NS_MSGACCOUNTMANAGER_CONTRACTID, &result);
|
||||
|
||||
if (NS_SUCCEEDED(result) && accountManager)
|
||||
{
|
||||
nsCOMPtr<nsIMsgAccount> account;
|
||||
accountManager->GetDefaultAccount(getter_AddRefs(account));
|
||||
|
||||
nsCOMPtr<nsIMsgIncomingServer> server;
|
||||
result = account->GetIncomingServer(getter_AddRefs(server));
|
||||
if (NS_SUCCEEDED(result) && server)
|
||||
{
|
||||
char * value = nsnull;
|
||||
server->GetHostName(&value);
|
||||
printf("Imap Server: %s\n", value ? value : "");
|
||||
server->GetUsername(&value);
|
||||
printf("User Name: %s\n", value ? value : "");
|
||||
server->GetPassword(&value);
|
||||
printf("Imap Password: %s\n", value ? value : "");
|
||||
|
||||
}
|
||||
else
|
||||
printf("Unable to retrieve the msgIdentity....\n");
|
||||
|
||||
}
|
||||
else
|
||||
printf("Unable to retrieve the mail session service....\n");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
nsIMAP4TestDriver::SetupInbox()
|
||||
{
|
||||
if (!m_inbox)
|
||||
{
|
||||
nsresult rv = nsComponentManager::CreateInstance( kCImapResource,
|
||||
nsnull, NS_GET_IID(nsIMsgFolder), (void**)&m_inbox);
|
||||
if (NS_SUCCEEDED(rv) && m_inbox)
|
||||
{
|
||||
nsCOMPtr<nsIRDFResource>
|
||||
rdfResource(do_QueryInterface(m_inbox, &rv));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rdfResource->Init("imap:/Inbox");
|
||||
nsString inboxName; inboxName.AssignWithConversion("Inbox");
|
||||
m_inbox->SetName((PRUnichar *) inboxName.GetUnicode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsresult nsIMAP4TestDriver::OnSelectFolder()
|
||||
{
|
||||
// go get the imap service and ask it to select a folder
|
||||
// mscott - i may want to cache this in the test harness class
|
||||
// since we'll be using it for pretty much all the commands
|
||||
nsresult rv = NS_OK;
|
||||
NS_WITH_SERVICE(nsIImapService, imapService, kCImapService, &rv);
|
||||
if (NS_SUCCEEDED(rv) && imapService)
|
||||
{
|
||||
SetupInbox();
|
||||
if (NS_SUCCEEDED(rv) && m_inbox)
|
||||
rv = imapService->SelectFolder(m_eventQueue, m_inbox /* imap folder sink */, this /* url listener */, nsnull, nsnull);
|
||||
m_runningURL = PR_TRUE; // we are now running a url...
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsIMAP4TestDriver::OnFetchMessage()
|
||||
{
|
||||
// go get the imap service and ask it to load a message
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
char uidString[200];
|
||||
|
||||
PL_strcpy(uidString, "1");
|
||||
// prompt for the command to run ....
|
||||
printf("Enter UID(s) of message(s) to fetch [%s]: ", uidString);
|
||||
scanf("%[^\n]", uidString);
|
||||
|
||||
NS_WITH_SERVICE(nsIImapService, imapService, kCImapService, &rv);
|
||||
if (NS_SUCCEEDED(rv) && imapService)
|
||||
{
|
||||
SetupInbox();
|
||||
#if 0
|
||||
if (NS_SUCCEEDED(rv) && m_inbox)
|
||||
rv = imapService->FetchMessage(nsnull, nsIImapUrl::nsImapMsgFetch,
|
||||
m_inbox,/* imap folder sink */ nsnull,
|
||||
nsnull, uidString, PR_TRUE);
|
||||
#endif
|
||||
m_runningURL = PR_TRUE; // we are now running a url...
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult nsIMAP4TestDriver::OnRunIMAPCommand()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
PL_strcpy(m_command, "capability");
|
||||
// prompt for the command to run ....
|
||||
printf("Enter IMAP command to run [%s]: ", m_command);
|
||||
scanf("%[^\n]", m_command);
|
||||
|
||||
|
||||
m_urlString[0] = '\0';
|
||||
PL_strcpy(m_urlString, m_urlSpec);
|
||||
PL_strcat(m_urlString, "?");
|
||||
PL_strcat(m_urlString, m_command);
|
||||
|
||||
|
||||
// create a url to process the request.
|
||||
rv = nsComponentManager::CreateInstance(kImapUrlCID, nsnull,
|
||||
NS_GET_IID(nsIImapUrl), (void **)
|
||||
|
||||
&m_url);
|
||||
nsCOMPtr<nsIMsgMailNewsUrl> mailnewsurl = do_QueryInterface(m_url);
|
||||
if (NS_SUCCEEDED(rv) && m_url)
|
||||
{
|
||||
rv = mailnewsurl->SetSpec(m_urlString); // reset spec
|
||||
mailnewsurl->RegisterListener(this);
|
||||
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsCOMPtr<nsIMsgIncomingServer> aServer;
|
||||
rv = mailnewsurl->GetServer(getter_AddRefs(aServer));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsCOMPtr<nsIImapIncomingServer>
|
||||
aImapServer(do_QueryInterface(aServer, &rv));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
|
||||
rv = aImapServer->GetImapConnectionAndLoadUrl(m_eventQueue,
|
||||
m_url, nsnull);
|
||||
m_runningURL = PR_TRUE; // we are now running a url...
|
||||
}
|
||||
} // if user provided the data...
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsIMAP4TestDriver::OnGet()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
m_urlString[0] = '\0';
|
||||
PL_strcpy(m_urlString, m_urlSpec);
|
||||
#if 0
|
||||
|
||||
if (m_protocolInitialized == PR_FALSE)
|
||||
InitializeProtocol(m_urlString);
|
||||
else
|
||||
rv = m_url->SetSpec(m_urlString); // reset spec
|
||||
|
||||
// load the correct newsgroup interface as an event sink...
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
// before we re-load, assume it is a group command and configure our IMAP4URL correctly...
|
||||
|
||||
rv = m_IMAP4Protocol->Load(m_url);
|
||||
} // if user provided the data...
|
||||
#endif
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
/* strip out non-printable characters */
|
||||
static void strip_nonprintable(char *string) {
|
||||
char *dest, *src;
|
||||
|
||||
dest=src=string;
|
||||
while (*src) {
|
||||
if (isprint(*src)) {
|
||||
(*src)=(*dest);
|
||||
src++; dest++;
|
||||
} else {
|
||||
src++;
|
||||
}
|
||||
}
|
||||
(*dest)='\0';
|
||||
}
|
||||
|
||||
|
||||
// prints the userPrompt and then reads in the user data. Assumes urlData has already been allocated.
|
||||
// it also reconstructs the url string in m_urlString but does NOT reload it....
|
||||
nsresult nsIMAP4TestDriver::PromptForUserData(const char * userPrompt)
|
||||
{
|
||||
char tempBuffer[500];
|
||||
tempBuffer[0] = '\0';
|
||||
|
||||
if (userPrompt)
|
||||
printf(userPrompt);
|
||||
else
|
||||
printf("Enter data for command: ");
|
||||
|
||||
fgets(tempBuffer, sizeof(tempBuffer), stdin);
|
||||
strip_nonprintable(tempBuffer);
|
||||
// only replace m_userData if the user actually entered a valid line...
|
||||
// this allows the command function to set a default value on m_userData before
|
||||
// calling this routine....
|
||||
if (tempBuffer && *tempBuffer)
|
||||
PL_strcpy(m_userData, tempBuffer);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult nsIMAP4TestDriver::OnTestUrlParsing()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
char * hostName = nsnull;
|
||||
PRUint32 port = IMAP_PORT;
|
||||
|
||||
char * displayString = nsnull;
|
||||
|
||||
PL_strcpy(m_userData, DEFAULT_HOST);
|
||||
|
||||
displayString = PR_smprintf("Enter a host name for the imap url [%s]: ", m_userData);
|
||||
rv = PromptForUserData(displayString);
|
||||
PR_FREEIF(displayString);
|
||||
|
||||
hostName = PL_strdup(m_userData);
|
||||
|
||||
PL_strcpy(m_userData, "143");
|
||||
displayString = PR_smprintf("Enter port number if any for the imap url [%d] (use 0 to skip port field): ", IMAP_PORT);
|
||||
rv = PromptForUserData(displayString);
|
||||
PR_FREEIF(displayString);
|
||||
|
||||
port = atol(m_userData);
|
||||
|
||||
// as we had more functionality to the imap url, we'll probably need to ask for more information than just
|
||||
// the host and the port...
|
||||
|
||||
nsIImapUrl * imapUrl = nsnull;
|
||||
|
||||
nsComponentManager::CreateInstance(kImapUrlCID, nsnull /* contractID */, NS_GET_IID(nsIImapUrl), (void **) &imapUrl);
|
||||
if (imapUrl)
|
||||
{
|
||||
char * urlSpec = nsnull;
|
||||
if (m_port > 0) // did the user specify a port?
|
||||
urlSpec = PR_smprintf("imap://%s:%d", hostName, port);
|
||||
else
|
||||
urlSpec = PR_smprintf("imap://%s", hostName);
|
||||
|
||||
nsCOMPtr<nsIMsgMailNewsUrl> mailnewsurl = do_QueryInterface(imapUrl);
|
||||
mailnewsurl->SetSpec("imap://nsmail-2.mcom.com:143/test");
|
||||
|
||||
char * urlHost = nsnull;
|
||||
PRInt32 urlPort = 0;
|
||||
|
||||
mailnewsurl->GetHost(&urlHost);
|
||||
mailnewsurl->GetPort(&urlPort);
|
||||
|
||||
printf("Host name test: %s\n", PL_strcmp(urlHost, hostName) == 0 ? "PASSED." : "FAILED!");
|
||||
if (port > 0) // did the user try to test the port?
|
||||
printf("Port test: %s\n", port == (PRUint32)urlPort ? "PASSED." : "FAILED!");
|
||||
|
||||
NS_IF_RELEASE(imapUrl);
|
||||
}
|
||||
else
|
||||
printf("Failure!! Unable to create an imap url. Registration problem? \n");
|
||||
|
||||
PR_FREEIF(hostName);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
nsCOMPtr<nsIEventQueue> queue;
|
||||
nsresult result;
|
||||
|
||||
// register all the components we might need - what's the imap service going to be called?
|
||||
nsComponentManager::RegisterComponent(kEventQueueServiceCID, NULL, NULL, XPCOM_DLL, PR_FALSE, PR_FALSE);
|
||||
nsComponentManager::RegisterComponent(kPrefCID, nsnull, nsnull, PREF_DLL, PR_TRUE, PR_TRUE);
|
||||
nsComponentManager::RegisterComponent(kEventQueueCID, NULL, NULL, XPCOM_DLL, PR_FALSE, PR_FALSE);
|
||||
nsComponentManager::RegisterComponent(kFileLocatorCID, NULL, NS_FILELOCATOR_CONTRACTID, APPSHELL_DLL, PR_FALSE, PR_FALSE);
|
||||
|
||||
result = nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup, NULL /* default */);
|
||||
|
||||
// make sure prefs get initialized and loaded..
|
||||
// mscott - this is just a bad bad bad hack right now until prefs
|
||||
// has the ability to take nsnull as a parameter. Once that happens,
|
||||
// prefs will do the work of figuring out which prefs file to load...
|
||||
NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &result);
|
||||
if (NS_FAILED(result) || (prefs == nsnull)) {
|
||||
exit(result);
|
||||
}
|
||||
prefs->StartUp();
|
||||
if (NS_FAILED(prefs->ReadUserPrefs()))
|
||||
{
|
||||
printf("Failed on reading user prefs!\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// Create the Event Queue for the test app thread...a standin for the ui thread
|
||||
NS_WITH_SERVICE(nsIEventQueueService, pEventQService, kEventQueueServiceCID, &result);
|
||||
|
||||
if (NS_FAILED(result)) return result;
|
||||
|
||||
result = pEventQService->CreateThreadEventQueue();
|
||||
|
||||
if (NS_FAILED(result)) return result;
|
||||
|
||||
pEventQService->GetThreadEventQueue(NS_CURRENT_THREAD,getter_AddRefs(queue));
|
||||
if (NS_FAILED(result) || !queue)
|
||||
{
|
||||
printf("unable to get event queue.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// okay, everything is set up, now we just need to create a test driver and run it...
|
||||
nsIMAP4TestDriver * driver = new nsIMAP4TestDriver(queue);
|
||||
if (driver)
|
||||
{
|
||||
NS_ADDREF(driver);
|
||||
driver->RunDriver();
|
||||
// when it kicks out...it is done....so delete it...
|
||||
NS_RELEASE(driver);
|
||||
}
|
||||
|
||||
// shut down:
|
||||
return 0;
|
||||
|
||||
}
|
|
@ -1,94 +0,0 @@
|
|||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
# New build system where zip dll is build indepenant of java stubs.
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
MODULE =msgimaptest
|
||||
#EXPORTS = \
|
||||
# $(NULL)
|
||||
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Specify the depth of the current directory relative to the
|
||||
#// root of NS
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
DEPTH= ..\..\..\..
|
||||
|
||||
MAKE_OBJ_TYPE=EXE
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Define any Public Make Variables here: (ie. PDFFILE, MAPFILE, ...)
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
EXENAME=IMAPTest
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Define the files necessary to build the target (ie. OBJS)
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
OBJS= \
|
||||
.\$(OBJDIR)\imapProtocolTest.obj \
|
||||
$(NULL)
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Define any Public Targets here (ie. PROGRAM, LIBRARY, DLL, ...)
|
||||
#// (these must be defined before the common makefiles are included)
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
|
||||
PROGRAM=.\$(OBJDIR)\$(EXENAME).EXE
|
||||
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Define any local options for the make tools
|
||||
#// (ie. LCFLAGS, LLFLAGS, LLIBS, LINCS)
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
LCFLAGS=-DNETSCAPE
|
||||
WIN_LIBS= ole32.lib
|
||||
|
||||
LLIBS = \
|
||||
$(LIBNSPR)\
|
||||
$(DIST)\lib\msgbsutl.lib \
|
||||
$(DIST)\lib\msglocal_s.lib \
|
||||
$(DIST)\lib\xpcom.lib
|
||||
|
||||
|
||||
# clobber and clobber_all will remove the following garbage:
|
||||
GARBAGE = $(GARBAGE) _gen
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Include the common makefile rules
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
include <$(DEPTH)/config/rules.mak>
|
||||
|
||||
install:: $(PROGRAM)
|
||||
$(MAKE_INSTALL) $(PROGRAM) $(DIST)\bin\
|
||||
|
||||
clobber::
|
||||
rm -f $(EXENAME).exe
|
|
@ -1,26 +0,0 @@
|
|||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
|
||||
DEPTH=..\..\..
|
||||
|
||||
DIRS=harness
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
Загрузка…
Ссылка в новой задаче