Files
Mozilla/mozilla/mailnews/compose/tests/sendlater/test.cpp
sspitzer%netscape.com 961417414a in the immortal words of sfraser: "die, appcores, die".
the next step is to remove mozilla/xpfe/AppCores from the tree, which I will
gladly do next.

r=alecf


git-svn-id: svn://10.0.0.236/trunk@59932 18797224-902f-48f8-a5cc-f745e15eee43
2000-02-06 06:54:52 +00:00

181 lines
5.5 KiB
C++

/* -*- 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>
#ifdef XP_PC
#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"
#include "nsIWebShellWindow.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_IID(kIMsgSendLaterIID, NS_IMSGSENDLATER_IID);
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_PROGID, 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_PROGID, &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, kIMsgSendLaterIID,
(void **) getter_AddRefs(pMsgSendLater));
if (NS_SUCCEEDED(rv) && pMsgSendLater)
{
printf("We succesfully obtained a nsIMsgSendLater interface....\n");
pMsgSendLater->SendUnsentMessages(identity, nsnull);
}
#ifdef XP_PC
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;
}