Hi,

I'm trying to expose the Mailnews objects to CORBA. Since there's no 
XPCOM<->CORBA mapping yet, I'm doing that manually.

Technically, I'm creating a server (the front-end will be the client), 
so there's no UI at all wanted. So, I needed a minimal Mailnews app, not 
a bootstrap via chrome and JS.

After a few hours of trying, I finally succeeded. Much luck involved :-) 
(I was about to give up and just post for help). Looked into the 
embedding (mozilla/embedding/) examples and also apprunner (woa, there's 
a lot of cruft in the latter), since using only NS_InitEmbedding made 
nsIAccountManager::GetDefaultAccount fail. I guessed that the profile 
wasn't read, and I was right.

Anyways, the result is attached for your pleasure and guidiance, should 
you want to implement something similar (e.g. embed Mailnews in another 
app or implement a GTK frontend).

I intend contribute the resulting CORBA server to mozilla.org (under the 
BSD license), assuming general applicability.

I'm happy to have won that fight! :)

P.S. mozilla/build/autoconf/make-makefiles creates the Makefile from 
Makefile.in.
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsEmbedAPI.h"
#include "nsICmdLineService.h"
#include "nsIProfileInternal.h"

#include "nsMsgBaseCID.h"
#include "nsIMsgAccountManager.h"

static NS_DEFINE_CID(kCmdLineServiceCID,    NS_COMMANDLINE_SERVICE_CID);

int
main(int argc, char** argv)
{
	nsresult rv;

	// Init
  rv = NS_InitEmbedding(nsnull,nsnull);
	printf("%x ", rv);
  NS_ENSURE_SUCCESS(rv, rv);
	printf("Inited\n");

	//  Prefs
  nsCOMPtr<nsICmdLineService> cmdLineArgs(do_GetService(kCmdLineServiceCID, &rv));
  NS_ASSERTION(NS_SUCCEEDED(rv), "failed to get command line service");

  if (NS_FAILED(rv)) {
    NS_ASSERTION(PR_FALSE, "Could not obtain CmdLine processing service\n");
    return rv;
  }
  rv = cmdLineArgs->Initialize(argc, argv);
  NS_ASSERTION(NS_SUCCEEDED(rv), "failed to initialize command line args");

        nsCOMPtr<nsIProfileInternal> profileMgr(do_GetService(NS_PROFILE_CONTRACTID, &rv));
        NS_ASSERTION(NS_SUCCEEDED(rv), "failed to get profile manager");
        if (NS_FAILED(rv)) return rv;

        rv = profileMgr->StartupWithArgs(cmdLineArgs);
				//XXX this fails horribly, if there's more than one profile
				// and no "-P" commandline arg.
        if (NS_FAILED(rv)) return rv;
	printf("got profile\n");



  NS_WITH_SERVICE(nsIMsgAccountManager, accountManager,
									NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
	printf("%x ", rv);
  NS_ENSURE_SUCCESS(rv, rv);
	printf("Got account manager\n");

  nsCOMPtr<nsIMsgAccount> account;
	rv = accountManager->GetDefaultAccount(getter_AddRefs(account));
	printf("%x ", rv);
  NS_ENSURE_SUCCESS(rv, rv);
	printf("Got def account\n");

  nsCOMPtr<nsIMsgIncomingServer> server;
	rv = account->GetIncomingServer(getter_AddRefs(server));
	printf("%x ", rv);
  NS_ENSURE_SUCCESS(rv, rv);
	printf("Got def server\n");

	PRUnichar* name;
  nsString str;
  rv = server->GetPrettyName(&name);
	printf("%x ", rv);
	printf("Name: ");
  str = name;
	printf(str.ToNewCString()); // leak
	printf("\n");


	printf("Bye\n");
  return NS_OK;
}
#
# 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         = mailnews4corba
CPPSRCS         = init.cpp

LIBS    = \
                -L$(DIST)/bin \
                $(MOZ_JS_LIBS) \
                $(XPCOM_LIBS) \
                $(NSPR_LIBS) \
                $(TK_LIBS) \
                $(MOZ_COMPONENT_LIBS) \
                $(PROFILE_LIBS) \
                $(DIST)/lib/libembed_base_s.$(LIB_SUFFIX) \
                $(NULL)

include $(topsrcdir)/config/rules.mk

Reply via email to