Added text import module and new UI

This commit is contained in:
tonyr%fbdesigns.com 1999-12-27 21:24:00 +00:00
Родитель 1622a83b57
Коммит b1de7cbf3c
46 изменённых файлов: 4821 добавлений и 56 удалений

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

@ -21,7 +21,7 @@
DEPTH=..\.. DEPTH=..\..
LocalDirs=public src resources eudora LocalDirs=public src resources eudora text
!if "$(_MSC_VER)" == "1200" !if "$(_MSC_VER)" == "1200"

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

@ -116,6 +116,8 @@ nsresult nsEudoraAddress::ImportAddresses( PRBool *pAbort, const PRUnichar *pNam
rv = pSrc->CloseStream(); rv = pSrc->CloseStream();
delete [] pLine;
if (!eof) { if (!eof) {
IMPORT_LOG0( "*** Error reading the address book, didn't reach the end\n"); IMPORT_LOG0( "*** Error reading the address book, didn't reach the end\n");
return( NS_ERROR_FAILURE); return( NS_ERROR_FAILURE);

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

@ -228,8 +228,10 @@ nsresult nsEudoraCompose::CreateComponents( void)
if (NS_SUCCEEDED(rv) && m_pMsgSend) { if (NS_SUCCEEDED(rv) && m_pMsgSend) {
rv = nsComponentManager::CreateInstance( kMsgCompFieldsCID, nsnull, nsCOMTypeInfo<nsIMsgCompFields>::GetIID(), (void **) &m_pMsgFields); rv = nsComponentManager::CreateInstance( kMsgCompFieldsCID, nsnull, nsCOMTypeInfo<nsIMsgCompFields>::GetIID(), (void **) &m_pMsgFields);
if (NS_SUCCEEDED(rv) && m_pMsgFields) if (NS_SUCCEEDED(rv) && m_pMsgFields) {
IMPORT_LOG0( "nsEudoraCompose - CreateComponents succeeded\n");
return( NS_OK); return( NS_OK);
}
} }
return( NS_ERROR_FAILURE); return( NS_ERROR_FAILURE);
@ -459,7 +461,7 @@ nsresult nsEudoraCompose::SendMessage( nsIFileSpec *pMsg)
if (bodyType.Length()) if (bodyType.Length())
pMimeType = bodyType.ToNewCString(); pMimeType = bodyType.ToNewCString();
// IMPORT_LOG0( "Eudora compose calling CreateAndSendMessage\n"); IMPORT_LOG0( "Eudora compose calling CreateAndSendMessage\n");
nsMsgAttachedFile *pAttach = GetLocalAttachments(); nsMsgAttachedFile *pAttach = GetLocalAttachments();
rv = m_pMsgSend->CreateAndSendMessage( nsnull, // no editor shell rv = m_pMsgSend->CreateAndSendMessage( nsnull, // no editor shell
@ -478,6 +480,8 @@ nsresult nsEudoraCompose::SendMessage( nsIFileSpec *pMsg)
nsnull); // listener array nsnull); // listener array
IMPORT_LOG0( "Returned from CreateAndSendMessage\n");
if (pAttach) if (pAttach)
delete [] pAttach; delete [] pAttach;

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

@ -37,6 +37,7 @@
#include "nsIImportAddressBooks.h" #include "nsIImportAddressBooks.h"
#include "nsIImportABDescriptor.h" #include "nsIImportABDescriptor.h"
#include "nsIImportSettings.h" #include "nsIImportSettings.h"
#include "nsIImportFieldMap.h"
#include "nsIOutputStream.h" #include "nsIOutputStream.h"
#include "nsIAddrDatabase.h" #include "nsIAddrDatabase.h"
#include "nsTextFormater.h" #include "nsTextFormater.h"
@ -123,8 +124,8 @@ public:
/* PRBool GetAutoFind (out wstring description); */ /* PRBool GetAutoFind (out wstring description); */
NS_IMETHOD GetAutoFind(PRUnichar **description, PRBool *_retval); NS_IMETHOD GetAutoFind(PRUnichar **description, PRBool *_retval);
/* PRBool GetNeedsFieldMap (); */ /* PRBool GetNeedsFieldMap (nsIFileSpec location); */
NS_IMETHOD GetNeedsFieldMap(PRBool *_retval) { *_retval = PR_FALSE; return( NS_OK);} NS_IMETHOD GetNeedsFieldMap(nsIFileSpec *location, PRBool *_retval) { *_retval = PR_FALSE; return( NS_OK);}
/* void GetDefaultLocation (out nsIFileSpec location, out boolean found, out boolean userVerify); */ /* void GetDefaultLocation (out nsIFileSpec location, out boolean found, out boolean userVerify); */
NS_IMETHOD GetDefaultLocation(nsIFileSpec **location, PRBool *found, PRBool *userVerify); NS_IMETHOD GetDefaultLocation(nsIFileSpec **location, PRBool *found, PRBool *userVerify);
@ -133,13 +134,13 @@ public:
NS_IMETHOD FindAddressBooks(nsIFileSpec *location, nsISupportsArray **_retval); NS_IMETHOD FindAddressBooks(nsIFileSpec *location, nsISupportsArray **_retval);
/* nsISupports GetFieldMap (in nsIImportABDescriptor source); */ /* nsISupports GetFieldMap (in nsIImportABDescriptor source); */
NS_IMETHOD GetFieldMap(nsIImportABDescriptor *source, nsISupports **_retval) NS_IMETHOD InitFieldMap(nsIFileSpec *location, nsIImportFieldMap *fieldMap)
{ return( NS_ERROR_FAILURE); } { return( NS_ERROR_FAILURE); }
/* void ImportAddressBook (in nsIImportABDescriptor source, in nsISupports destination, in nsISupports fieldMap, out boolean fatalError); */ /* void ImportAddressBook (in nsIImportABDescriptor source, in nsISupports destination, in nsISupports fieldMap, out boolean fatalError); */
NS_IMETHOD ImportAddressBook( nsIImportABDescriptor *source, NS_IMETHOD ImportAddressBook( nsIImportABDescriptor *source,
nsIAddrDatabase * destination, nsIAddrDatabase * destination,
nsISupports * fieldMap, nsIImportFieldMap * fieldMap,
PRUnichar ** errorLog, PRUnichar ** errorLog,
PRUnichar ** successLog, PRUnichar ** successLog,
PRBool * fatalError); PRBool * fatalError);
@ -638,7 +639,7 @@ void ImportAddressImpl::ReportSuccess( nsString& name, nsString *pStream)
NS_IMETHODIMP ImportAddressImpl::ImportAddressBook( nsIImportABDescriptor *pSource, NS_IMETHODIMP ImportAddressImpl::ImportAddressBook( nsIImportABDescriptor *pSource,
nsIAddrDatabase * pDestination, nsIAddrDatabase * pDestination,
nsISupports * fieldMap, nsIImportFieldMap * fieldMap,
PRUnichar ** pErrorLog, PRUnichar ** pErrorLog,
PRUnichar ** pSuccessLog, PRUnichar ** pSuccessLog,
PRBool * fatalError) PRBool * fatalError)

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

@ -355,7 +355,7 @@ nsresult nsEudoraWin32::ScanDescmap( nsIFileSpec *pFolder, nsISupportsArray *pAr
pData++; pData++;
pStart = pData; pStart = pData;
fieldLen = 0; fieldLen = 0;
while ((pos < len) && (*pData != ',')) { while ((pos < len) && (*pData != 0x0D) && (*pData != 0x0A) && (*pData != ',')) {
pos++; pos++;
pData++; pData++;
fieldLen++; fieldLen++;
@ -364,6 +364,12 @@ nsresult nsEudoraWin32::ScanDescmap( nsIFileSpec *pFolder, nsISupportsArray *pAr
if (fieldLen) if (fieldLen)
flag.Append( pStart, fieldLen); flag.Append( pStart, fieldLen);
flag.Trim( kWhitespace); flag.Trim( kWhitespace);
while ((pos < len) && ((*pData == 0x0D) || (*pData == 0x0A))) {
pos++;
pData++;
}
IMPORT_LOG2( "name: %s, fName: %s\n", (const char *)name, (const char *)fName);
if (fName.Length() && name.Length() && (type.Length() == 1)) { if (fName.Length() && name.Length() && (type.Length() == 1)) {
entry->FromFileSpec( pFolder); entry->FromFileSpec( pFolder);

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

@ -23,9 +23,11 @@
#ifndef OEDebugLog_h___ #ifndef OEDebugLog_h___
#define OEDebugLog_h___ #define OEDebugLog_h___
/*
#ifdef NS_DEBUG #ifdef NS_DEBUG
#define IMPORT_DEBUG 1 #define IMPORT_DEBUG 1
#endif #endif
*/
#ifdef IMPORT_DEBUG #ifdef IMPORT_DEBUG
#include "stdio.h" #include "stdio.h"

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

@ -378,22 +378,24 @@ nsresult nsOE5File::WriteMessageBuffer( nsIFileSpec *stream, char *pBuffer, PRUi
// examine the rest of the buffer for from problems! // examine the rest of the buffer for from problems!
PRUint32 cnt = 0; PRUint32 cnt = 0;
char * pChar = pBuffer; char * pChar = pBuffer;
while (cnt < (size - 6)) { if (size > 6) {
if ((*pChar == 0x0D) && (*(pChar + 1) == 0x0A) && ISFROMLINE( pChar, 2)) { while (cnt < (size - 6)) {
rv = stream->Write( pBuffer, cnt + 2, &written); if ((*pChar == 0x0D) && (*(pChar + 1) == 0x0A) && ISFROMLINE( pChar, 2)) {
pBuffer += (cnt + 2); rv = stream->Write( pBuffer, cnt + 2, &written);
size -= (cnt + 2); pBuffer += (cnt + 2);
pChar += 2; size -= (cnt + 2);
cnt = 0; pChar += 2;
if (NS_SUCCEEDED( rv)) { cnt = 0;
rv = stream->Write( ">", 1, &written); if (NS_SUCCEEDED( rv)) {
rv = stream->Write( ">", 1, &written);
}
if (NS_FAILED( rv))
return( rv);
}
else {
cnt++;
pChar++;
} }
if (NS_FAILED( rv))
return( rv);
}
else {
cnt++;
pChar++;
} }
} }

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

@ -41,6 +41,7 @@
#include "nsOEMailbox.h" #include "nsOEMailbox.h"
#include "nsIImportAddressBooks.h" #include "nsIImportAddressBooks.h"
#include "nsIImportABDescriptor.h" #include "nsIImportABDescriptor.h"
#include "nsIImportFieldMap.h"
#include "WabObject.h" #include "WabObject.h"
#include "nsOEAddressIterator.h" #include "nsOEAddressIterator.h"
#include "nsIOutputStream.h" #include "nsIOutputStream.h"
@ -110,8 +111,8 @@ public:
/* PRBool GetAutoFind (out wstring description); */ /* PRBool GetAutoFind (out wstring description); */
NS_IMETHOD GetAutoFind(PRUnichar **description, PRBool *_retval); NS_IMETHOD GetAutoFind(PRUnichar **description, PRBool *_retval);
/* PRBool GetNeedsFieldMap (); */ /* PRBool GetNeedsFieldMap ( nsIFileSpec *location); */
NS_IMETHOD GetNeedsFieldMap(PRBool *_retval) { *_retval = PR_FALSE; return( NS_OK);} NS_IMETHOD GetNeedsFieldMap(nsIFileSpec *pLoc, PRBool *_retval) { *_retval = PR_FALSE; return( NS_OK);}
/* void GetDefaultLocation (out nsIFileSpec location, out boolean found, out boolean userVerify); */ /* void GetDefaultLocation (out nsIFileSpec location, out boolean found, out boolean userVerify); */
NS_IMETHOD GetDefaultLocation(nsIFileSpec **location, PRBool *found, PRBool *userVerify) NS_IMETHOD GetDefaultLocation(nsIFileSpec **location, PRBool *found, PRBool *userVerify)
@ -120,14 +121,14 @@ public:
/* nsISupportsArray FindAddressBooks (in nsIFileSpec location); */ /* nsISupportsArray FindAddressBooks (in nsIFileSpec location); */
NS_IMETHOD FindAddressBooks(nsIFileSpec *location, nsISupportsArray **_retval); NS_IMETHOD FindAddressBooks(nsIFileSpec *location, nsISupportsArray **_retval);
/* nsISupports GetFieldMap (in nsIImportABDescriptor source); */ /* nsISupports InitFieldMap(nsIFileSpec *location, nsIImportFieldMap *fieldMap); */
NS_IMETHOD GetFieldMap(nsIImportABDescriptor *source, nsISupports **_retval) NS_IMETHOD InitFieldMap(nsIFileSpec *location, nsIImportFieldMap *fieldMap)
{ return( NS_ERROR_FAILURE); } { return( NS_ERROR_FAILURE); }
/* void ImportAddressBook (in nsIImportABDescriptor source, in nsISupports destination, in nsISupports fieldMap, out boolean fatalError); */ /* void ImportAddressBook (in nsIImportABDescriptor source, in nsISupports destination, in nsISupports fieldMap, out boolean fatalError); */
NS_IMETHOD ImportAddressBook( nsIImportABDescriptor *source, NS_IMETHOD ImportAddressBook( nsIImportABDescriptor *source,
nsIAddrDatabase * destination, nsIAddrDatabase * destination,
nsISupports * fieldMap, nsIImportFieldMap * fieldMap,
PRUnichar ** errorLog, PRUnichar ** errorLog,
PRUnichar ** successLog, PRUnichar ** successLog,
PRBool * fatalError); PRBool * fatalError);
@ -606,7 +607,7 @@ NS_IMETHODIMP ImportAddressImpl::FindAddressBooks(nsIFileSpec *location, nsISupp
NS_IMETHODIMP ImportAddressImpl::ImportAddressBook( nsIImportABDescriptor *source, NS_IMETHODIMP ImportAddressImpl::ImportAddressBook( nsIImportABDescriptor *source,
nsIAddrDatabase * destination, nsIAddrDatabase * destination,
nsISupports * fieldMap, nsIImportFieldMap * fieldMap,
PRUnichar ** errorLog, PRUnichar ** errorLog,
PRUnichar ** successLog, PRUnichar ** successLog,
PRBool * fatalError) PRBool * fatalError)

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

@ -40,6 +40,7 @@
#include "nsIImportGeneric.h" #include "nsIImportGeneric.h"
#include "nsIImportAddressBooks.h" #include "nsIImportAddressBooks.h"
#include "nsIImportABDescriptor.h" #include "nsIImportABDescriptor.h"
#include "nsIImportFieldMap.h"
#include "nsIOutputStream.h" #include "nsIOutputStream.h"
#include "nsIAddrDatabase.h" #include "nsIAddrDatabase.h"
#include "nsOutlookSettings.h" #include "nsOutlookSettings.h"
@ -50,6 +51,8 @@
#include "nsOutlookMail.h" #include "nsOutlookMail.h"
#include "MapiApi.h"
static NS_DEFINE_CID(kImportServiceCID, NS_IMPORTSERVICE_CID); static NS_DEFINE_CID(kImportServiceCID, NS_IMPORTSERVICE_CID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
@ -111,8 +114,8 @@ public:
/* PRBool GetAutoFind (out wstring description); */ /* PRBool GetAutoFind (out wstring description); */
NS_IMETHOD GetAutoFind(PRUnichar **description, PRBool *_retval); NS_IMETHOD GetAutoFind(PRUnichar **description, PRBool *_retval);
/* PRBool GetNeedsFieldMap (); */ /* PRBool GetNeedsFieldMap ( nsIFileSpec location); */
NS_IMETHOD GetNeedsFieldMap(PRBool *_retval) { *_retval = PR_FALSE; return( NS_OK);} NS_IMETHOD GetNeedsFieldMap(nsIFileSpec *location, PRBool *_retval) { *_retval = PR_FALSE; return( NS_OK);}
/* void GetDefaultLocation (out nsIFileSpec location, out boolean found, out boolean userVerify); */ /* void GetDefaultLocation (out nsIFileSpec location, out boolean found, out boolean userVerify); */
NS_IMETHOD GetDefaultLocation(nsIFileSpec **location, PRBool *found, PRBool *userVerify) NS_IMETHOD GetDefaultLocation(nsIFileSpec **location, PRBool *found, PRBool *userVerify)
@ -122,13 +125,13 @@ public:
NS_IMETHOD FindAddressBooks(nsIFileSpec *location, nsISupportsArray **_retval); NS_IMETHOD FindAddressBooks(nsIFileSpec *location, nsISupportsArray **_retval);
/* nsISupports GetFieldMap (in nsIImportABDescriptor source); */ /* nsISupports GetFieldMap (in nsIImportABDescriptor source); */
NS_IMETHOD GetFieldMap(nsIImportABDescriptor *source, nsISupports **_retval) NS_IMETHOD InitFieldMap(nsIFileSpec *location, nsIImportFieldMap *fieldMap)
{ return( NS_ERROR_FAILURE); } { return( NS_ERROR_FAILURE); }
/* void ImportAddressBook (in nsIImportABDescriptor source, in nsISupports destination, in nsISupports fieldMap, out boolean fatalError); */ /* void ImportAddressBook (in nsIImportABDescriptor source, in nsISupports destination, in nsISupports fieldMap, out boolean fatalError); */
NS_IMETHOD ImportAddressBook( nsIImportABDescriptor *source, NS_IMETHOD ImportAddressBook( nsIImportABDescriptor *source,
nsIAddrDatabase * destination, nsIAddrDatabase * destination,
nsISupports * fieldMap, nsIImportFieldMap * fieldMap,
PRUnichar ** errorLog, PRUnichar ** errorLog,
PRUnichar ** successLog, PRUnichar ** successLog,
PRBool * fatalError); PRBool * fatalError);
@ -333,11 +336,25 @@ NS_IMETHODIMP ImportMailImpl::GetDefaultLocation( nsIFileSpec **ppLoc, PRBool *f
if (!ppLoc || !found || !userVerify) if (!ppLoc || !found || !userVerify)
return NS_ERROR_NULL_POINTER; return NS_ERROR_NULL_POINTER;
// Bizarro, there really isn't a "default" location, the mail
// is in the MAPI store and we just open it via API
// We'll just use an "empty" file spec for now since we *found = PR_FALSE;
// don't really care where the mail is. *ppLoc = nsnull;
*userVerify = PR_FALSE;
// We need to verify here that we can get the mail, if true then
// return a dummy location, otherwise return no location
CMapiApi mapi;
if (!mapi.Initialize())
return( NS_OK);
if (!mapi.LogOn())
return( NS_OK);
CMapiFolderList store;
if (!mapi.IterateStores( store))
return( NS_OK);
if (store.GetSize() == 0)
return( NS_OK);
nsresult rv; nsresult rv;
nsIFileSpec * spec; nsIFileSpec * spec;
@ -557,7 +574,7 @@ NS_IMETHODIMP ImportAddressImpl::FindAddressBooks(nsIFileSpec *location, nsISupp
NS_IMETHODIMP ImportAddressImpl::ImportAddressBook( nsIImportABDescriptor *source, NS_IMETHODIMP ImportAddressImpl::ImportAddressBook( nsIImportABDescriptor *source,
nsIAddrDatabase * destination, nsIAddrDatabase * destination,
nsISupports * fieldMap, nsIImportFieldMap * fieldMap,
PRUnichar ** errorLog, PRUnichar ** errorLog,
PRUnichar ** successLog, PRUnichar ** successLog,
PRBool * fatalError) PRBool * fatalError)

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

@ -31,6 +31,7 @@ XPIDLSRCS= .\nsIImportService.idl \
.\nsIImportABDescriptor.idl \ .\nsIImportABDescriptor.idl \
.\nsIImportSettings.idl \ .\nsIImportSettings.idl \
.\nsIImportMimeEncode.idl \ .\nsIImportMimeEncode.idl \
.\nsIImportFieldMap.idl \
$(NULL) $(NULL)
MODULE= import MODULE= import

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

@ -65,6 +65,7 @@ interface nsISupportsArray;
interface nsIImportABDescriptor; interface nsIImportABDescriptor;
interface nsIOutputStream; interface nsIOutputStream;
interface nsIAddrDatabase; interface nsIAddrDatabase;
interface nsIImportFieldMap;
[scriptable, uuid(3fe29be0-3539-11d3-a206-00a0cc26da63)] [scriptable, uuid(3fe29be0-3539-11d3-a206-00a0cc26da63)]
interface nsIImportAddressBooks : nsISupports interface nsIImportAddressBooks : nsISupports
@ -93,7 +94,7 @@ interface nsIImportAddressBooks : nsISupports
Returns true if the address book needs the user to specify a field map Returns true if the address book needs the user to specify a field map
for address books imported from this format. for address books imported from this format.
*/ */
PRBool GetNeedsFieldMap(); PRBool GetNeedsFieldMap( in nsIFileSpec location);
/* /*
If found and userVerify BOTH return false, then it is assumed that this If found and userVerify BOTH return false, then it is assumed that this
@ -112,9 +113,10 @@ interface nsIImportAddressBooks : nsISupports
nsISupportsArray FindAddressBooks( in nsIFileSpec location); nsISupportsArray FindAddressBooks( in nsIFileSpec location);
/* /*
Get a field map for a given address book. Fill in defaults (if any) for a field map for importing address
books from this location.
*/ */
nsISupports GetFieldMap( in nsIImportABDescriptor source); void InitFieldMap( in nsIFileSpec location, in nsIImportFieldMap fieldMap);
/* /*
Import a specific mailbox into the destination file supplied. If an error Import a specific mailbox into the destination file supplied. If an error
@ -124,7 +126,7 @@ interface nsIImportAddressBooks : nsISupports
*/ */
void ImportAddressBook( in nsIImportABDescriptor source, void ImportAddressBook( in nsIImportABDescriptor source,
in nsIAddrDatabase destination, in nsIAddrDatabase destination,
in nsISupports fieldMap, in nsIImportFieldMap fieldMap,
out wstring errorLog, out wstring errorLog,
out wstring successLog, out wstring successLog,
out boolean fatalError); out boolean fatalError);

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

@ -0,0 +1,100 @@
/* -*- 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):
*/
/*
Field map interface for importing address books
A field map is an arbitrary sized list of mozilla address book fields.
The field map is used by import to map fields from the import format
to mozilla fields.
For export, the map contains the ordered list of mozilla fields to
export!
*/
#include "nsISupports.idl"
interface nsIAddrDatabase;
interface nsIMdbRow;
interface nsIAbCard;
[scriptable, uuid(1CEB9241-ADC1-11d3-A9C2-00A0CC26DA63)]
interface nsIImportFieldMap : nsISupports
{
readonly attribute long numMozFields;
readonly attribute long mapSize;
wstring GetFieldDescription( in long index);
/*
Set the size of the field map, all unpopulated entries
will default to -1
*/
void SetFieldMapSize( in long size);
/*
Initialize the field map to a given size with default values
*/
void DefaultFieldMap( in long size);
/*
Return the field number that this index maps to, -1 for no field
*/
long GetFieldMap( in long index);
/*
Set the field that this index maps to, -1 for no field
*/
void SetFieldMap( in long index, in long fieldNum);
/*
Set the field that this index maps to, -1 for no field
*/
void SetFieldMapByDescription( in long index, in wstring fieldDesc);
/*
Set the value of the given field in the database row
*/
void SetFieldValue( in nsIAddrDatabase database, in nsIMdbRow row, in long fieldNum, in wstring value);
/*
Set the value of the given field in the database row
*/
void SetFieldValueByDescription( in nsIAddrDatabase database, in nsIMdbRow row, in wstring fieldDesc, in wstring value);
/*
Get the value of the given field from the address card
*/
wstring GetFieldValue( in nsIAbCard card, in long fieldNum);
/*
Get the value of the given field from the address card
*/
wstring GetFieldValueByDescription( in nsIAbCard card, in wstring fieldDesc);
};
%{ C++
%}

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

@ -28,7 +28,6 @@
#include "nsISupports.idl" #include "nsISupports.idl"
interface nsIImportDriver;
interface nsIDOMWindow; interface nsIDOMWindow;
interface nsISupportsWString; interface nsISupportsWString;

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

@ -32,6 +32,7 @@ interface nsIImportModule;
interface nsIImportMailboxDescriptor; interface nsIImportMailboxDescriptor;
interface nsIImportABDescriptor; interface nsIImportABDescriptor;
interface nsIImportGeneric; interface nsIImportGeneric;
interface nsIImportFieldMap;
[scriptable, uuid(50d7ea80-1726-11d3-a206-00a0cc26da63)] [scriptable, uuid(50d7ea80-1726-11d3-a206-00a0cc26da63)]
interface nsIImportService : nsISupports interface nsIImportService : nsISupports
@ -45,10 +46,11 @@ interface nsIImportService : nsISupports
nsIImportModule GetModule( in string filter, in long index); nsIImportModule GetModule( in string filter, in long index);
nsIImportModule GetModuleWithCID( in nsCIDRef cid); nsIImportModule GetModuleWithCID( in nsCIDRef cid);
nsIImportMailboxDescriptor CreateNewMailboxDescriptor(); nsIImportFieldMap CreateNewFieldMap();
nsIImportABDescriptor CreateNewABDescriptor(); nsIImportMailboxDescriptor CreateNewMailboxDescriptor();
nsIImportGeneric CreateNewGenericMail(); nsIImportABDescriptor CreateNewABDescriptor();
nsIImportGeneric CreateNewGenericAddressBooks(); nsIImportGeneric CreateNewGenericMail();
nsIImportGeneric CreateNewGenericAddressBooks();
}; };

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

@ -241,6 +241,10 @@ function ImportAddresses( module) {
addInterface.SetData( "addressLocation", file); addInterface.SetData( "addressLocation", file);
} }
var map = addInterface.GetData( "fieldMap");
if (map != null) {
// FIXME: Show modal UI to handle the field map!
}
if (addInterface.WantsProgress()) { if (addInterface.WantsProgress()) {
dump( "Beginning address import with progress\n"); dump( "Beginning address import with progress\n");
@ -270,7 +274,7 @@ function ImportAddresses( module) {
} }
function ImportSettings( module) { function ImportSettings( module, newAccount) {
var setIntf = module.GetImportInterface( "settings"); var setIntf = module.GetImportInterface( "settings");
if (setIntf != null) if (setIntf != null)
setIntf = setIntf.QueryInterface( Components.interfaces.nsIImportSettings); setIntf = setIntf.QueryInterface( Components.interfaces.nsIImportSettings);
@ -323,7 +327,6 @@ function ImportSettings( module) {
// interesting, we need to return the account that new // interesting, we need to return the account that new
// mail should be imported into? // mail should be imported into?
// that's really only useful for "Upgrade" // that's really only useful for "Upgrade"
var newAccount = new Object();
return( setIntf.Import( newAccount)); return( setIntf.Import( newAccount));
} }
@ -370,6 +373,14 @@ function eudoraAddress() {
ImportAddresses( module); ImportAddresses( module);
} }
function importTextAddress() {
dump( "Loading text import component\n");
var module = Components.classes["component://mozilla/import/import-text"].createInstance();
module = module.QueryInterface( Components.interfaces.nsIImportModule);
dump( "Loaded text import module\n");
ImportAddresses( module);
}
function importOESettings() { function importOESettings() {
dump( "Loading outlook express component\n"); dump( "Loading outlook express component\n");
@ -450,6 +461,7 @@ function trySettings( index) {
<input type="button" value="Import Eudora Settings" onclick="eudoraSettings();"><br> <input type="button" value="Import Eudora Settings" onclick="eudoraSettings();"><br>
<input type="button" value="Test Listings" onclick="testLists();"><br> <input type="button" value="Test Listings" onclick="testLists();"><br>
<input type="button" value="Import Settings from module #2" onclick="trySettings( 2);"><br> <input type="button" value="Import Settings from module #2" onclick="trySettings( 2);"><br>
<input type="button" value="Import Text Address Book" onclick="importTextAddress();"><br>
<form> <form>
</body> </body>

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

@ -0,0 +1,557 @@
var importType = 0;
var bundle = 0;
var importService = 0;
var successStr = null;
var errorStr = null;
var progressInfo = null;
function OnLoadImportDialog()
{
top.bundle = srGetStrBundle("chrome://messenger/locale/importMsgs.properties");
top.importService = Components.classes["component://mozilla/import/import-service"].createInstance();
top.importService = top.importService.QueryInterface(Components.interfaces.nsIImportService);
top.progressInfo = new Object();
top.progressInfo.progressWindow = null;
top.progressInfo.importInterface = null;
top.progressInfo.mainWindow = top.window;
top.progressInfo.intervalState = 0;
top.progressInfo.importSuccess = false;
top.progressInfo.importType = null;
doSetOKCancel(ImportDialogOKButton, 0);
// look in arguments[0] for parameters
if (window.arguments && window.arguments[0])
{
// keep parameters in global for later
if ( window.arguments[0].importType )
top.importType = window.arguments[0].importType;
top.progressInfo.importType = top.importType;
// set dialog title
switch ( top.importType )
{
case "mail":
top.window.title = top.bundle.GetStringFromName('ImportMailDialogTitle');
SetDivText('listLabel', top.bundle.GetStringFromName('ImportMailListLabel'));
break;
case "addressbook":
top.window.title = top.bundle.GetStringFromName('ImportAddressBooksDialogTitle');
SetDivText('listLabel', top.bundle.GetStringFromName('ImportAddressBooksListLabel'));
break;
case "settings":
top.window.title = top.bundle.GetStringFromName('ImportSettingsDialogTitle');
SetDivText('listLabel', top.bundle.GetStringFromName('ImportSettingsListLabel'));
break;
}
ListModules();
// add module names to tree
}
}
function SetDivText(id, text)
{
var div = document.getElementById(id);
if ( div )
{
if ( div.childNodes.length == 0 )
{
var textNode = document.createTextNode(text);
div.appendChild(textNode);
}
else if ( div.childNodes.length == 1 )
div.childNodes[0].nodeValue = text;
}
}
function ImportDialogOKButton()
{
var tree = document.getElementById('moduleList');
if ( tree && tree.selectedItems && (tree.selectedItems.length == 1) )
{
var index = tree.selectedItems[0].getAttribute('list-index');
var module = top.importService.GetModule( top.importType, index);
var name = top.importService.GetModuleName( top.importType, index);
if (module != null)
{
switch( top.importType )
{
case "mail":
top.successStr = Components.classes["component://netscape/supports-wstring"].createInstance();
if (top.successStr != null) {
top.successStr = top.successStr.QueryInterface( Components.interfaces.nsISupportsWString);
}
top.errorStr = Components.classes["component://netscape/supports-wstring"].createInstance();
if (top.errorStr != null)
top.errorStr = top.errorStr.QueryInterface( Components.interfaces.nsISupportsWString);
if (ImportMail( module, top.successStr, top.errorStr) == true)
{
// We think it was a success, either, we need to
// wait for the import to finish
// or we are done!
if (top.progressInfo.importInterface == null) {
ShowMailComplete( true);
return( true);
}
else {
// show the progress window...
top.window.openDialog(
"chrome://messenger/content/importProgress.xul",
"",
"chrome,modal",
{windowTitle:"My Progress Window Title",
progressTitle: "Importing some crap",
progressStatus: "Now importing specific crap",
progressInfo: top.progressInfo});
dump( "*** Returned from progress window\n");
return( true);
}
}
else
{
ShowMailComplete( false);
return( false);
}
break;
case "addressbook":
top.successStr = Components.classes["component://netscape/supports-wstring"].createInstance();
if (top.successStr != null) {
top.successStr = top.successStr.QueryInterface( Components.interfaces.nsISupportsWString);
}
top.errorStr = Components.classes["component://netscape/supports-wstring"].createInstance();
if (top.errorStr != null)
top.errorStr = top.errorStr.QueryInterface( Components.interfaces.nsISupportsWString);
if (ImportAddress( module, top.successStr, top.errorStr) == true)
{
// We think it was a success, either, we need to
// wait for the import to finish
// or we are done!
if (top.progressInfo.importInterface == null) {
ShowAddressComplete( true);
return( true);
}
else {
// show the progress window...
top.window.openDialog(
"chrome://messenger/content/importProgress.xul",
"",
"chrome,modal",
{windowTitle:"My Address Window Title",
progressTitle: "Importing some address",
progressStatus: "Now importing specific crap",
progressInfo: top.progressInfo});
return( true);
}
}
else
{
ShowAddressComplete( false);
return( false);
}
break;
case "settings":
var error = new Object();
error.value = null;
var newAccount = new Object();
if (!ImportSettings( module, newAccount, error))
{
if (error.value != null)
{
// Show error alert with error
// information
alert( top.bundle.GetStringFromName( 'ImportSettingsError') + name + ":\n" + error.value);
}
// the user canceled the operation, shoud we dismiss
// this dialog or not?
return false;
}
else
{
// Alert to show success
alert( top.bundle.GetStringFromName( 'ImportSettingsSuccess') + name);
}
break;
}
}
}
return true;
}
function ImportSelectionChanged()
{
var tree = document.getElementById('moduleList');
if ( tree && tree.selectedItems && (tree.selectedItems.length == 1) )
{
var index = tree.selectedItems[0].getAttribute('list-index');
SetDivText('description', top.importService.GetModuleDescription(top.importType, index));
}
}
function ListModules() {
if (top.importService == null)
return;
var count = top.importService.GetModuleCount( top.importType);
for (i = 0; i < count; i++) {
AddModuleToList( top.importService.GetModuleName( top.importType, i), i);
}
}
function AddModuleToList(moduleName, index)
{
var body = document.getElementById("bucketBody");
var item = document.createElement('treeitem');
var row = document.createElement('treerow');
var cell = document.createElement('treecell');
cell.setAttribute('value', moduleName);
item.setAttribute('list-index', index);
row.appendChild(cell);
item.appendChild(row);
body.appendChild(item);
}
function ContinueImport( info) {
var isMail = false;
dump( "*** ContinueImport\n");
if (info.importType == 'mail')
isMail = true;
else
isMail = false;
var clear = true;
if (info.importInterface) {
if (!info.importInterface.ContinueImport()) {
info.importSuccess = false;
clearInterval( info.intervalState);
if (info.progressWindow != null) {
info.progressWindow.close();
info.progressWindow = null;
}
if (isMail == true)
ShowMailComplete( false);
else
ShowAddressComplete( false);
}
else if ((pcnt = info.importInterface.GetProgress()) < 100) {
clear = false;
if (info.progressWindow != null) {
info.progressWindow.SetProgress( pcnt);
}
}
else {
clearInterval( info.intervalState);
info.importSuccess = true;
if (info.progressWindow != null) {
info.progressWindow.close();
info.progressWindow = null;
}
if (isMail == true)
ShowMailComplete( true);
else
ShowAddressComplete( true);
}
}
else {
dump( "*** ERROR: info.importInterface is null\n");
}
if (clear == true) {
info.intervalState = null;
info.importInterface = null;
}
}
function ShowMailComplete( good)
{
var str;
if (good == true) {
str = top.bundle.GetStringFromName( 'ImportMailSuccess');
str += "\nsuccess: " + top.successStr.data + "\nerror:" + top.errorStr.data;
}
else {
str = top.bundle.GetStringFromName( 'ImportMailFailed');
str += "\nerror: " + top.errorStr.data;
}
alert( str);
}
function ShowAddressComplete( good)
{
var str;
if (good == true) {
str = top.bundle.GetStringFromName( 'ImportAddressSuccess');
str += "\nsuccess: " + top.successStr.data + "\nerror:" + top.errorStr.data;
}
else {
str = top.bundle.GetStringFromName( 'ImportAddressFailed');
str += "\nerror: " + top.errorStr.data;
}
alert( str);
}
/*
Import Settings from a specific module, returns false if it failed
and true if successful. A "local mail" account is returned in newAccount.
This is only useful in upgrading - import the settings first, then
import mail into the account returned from ImportSettings, then
import address books.
An error string is returned as error.value
*/
function ImportSettings( module, newAccount, error) {
var setIntf = module.GetImportInterface( "settings");
if (setIntf != null)
setIntf = setIntf.QueryInterface( Components.interfaces.nsIImportSettings);
if (setIntf == null) {
error.value = top.bundle.GetStringFromName( 'ImportSettingsBadModule');
return( false);
}
// determine if we can auto find the settings or if we need to ask the user
var location = new Object();
var description = new Object();
var result = setIntf.AutoLocate( description, location);
if (result == false) {
// In this case, we couldn't not find the settings
if (location.value != null) {
// Settings were not found, however, they are specified
// in a file, so ask the user for the settings file.
var filePicker = Components.classes["component://netscape/filespecwithui"].createInstance();
if (filePicker != null) {
filePicker = filePicker.QueryInterface( Components.interfaces.nsIFileSpecWithUI);
if (filePicker != null) {
// filePicker.create( window.top, "Select settings file", filePicker.modeLoad);
try {
filePicker.chooseInputFile( "Select settings file", filePicker.eAllFiles, null, null);
setIntf.SetLocation( filePicker.QueryInterface( Components.interfaces.nsIFileSpec));
} catch( ex) {
error.value = null;
return( false);
}
}
else {
error.value = top.bundle.GetStringFromName( 'ImportSettingsNotFound');
return( false);
}
}
else {
error.value = top.bundle.GetStringFromName( 'ImportSettingsNotFound');
return( false);
}
}
else {
error.value = top.bundle.GetStringFromName( 'ImportSettingsNotFound');
return( false);
}
}
// interesting, we need to return the account that new
// mail should be imported into?
// that's really only useful for "Upgrade"
var result = setIntf.Import( newAccount);
if (result == false) {
error.value = top.bundle.GetStringFromName( 'ImportSettingsFailed');
}
return( result);
}
function ImportMail( module, success, error) {
if (top.progressInfo.importInterface || top.progressInfo.intervalState) {
error.data = top.bundle.GetStringFromName( 'ImportAlreadyInProgress');
return( false);
}
top.progressInfo.importSuccess = false;
var mailInterface = module.GetImportInterface( "mail");
if (mailInterface != null)
mailInterface = mailInterface.QueryInterface( Components.interfaces.nsIImportGeneric);
if (mailInterface == null) {
error.data = top.bundle.GetStringFromName( 'ImportMailBadModule');
return( false);
}
var loc = mailInterface.GetData( "mailLocation");
if (loc == null) {
// No location found, check to see if we can ask the user.
if (mailInterface.GetStatus( "canUserSetLocation") != 0) {
var filePicker = Components.classes["component://netscape/filespecwithui"].createInstance();
if (filePicker != null) {
filePicker = filePicker.QueryInterface( Components.interfaces.nsIFileSpecWithUI);
if (filePicker != null) {
try {
filePicker.chooseDirectory( "Select mail directory");
mailInterface.SetLocation( filePicker.QueryInterface( Components.interfaces.nsIFileSpec));
} catch( ex) {
// don't show an error when we return!
return( false);
}
}
else {
error.data = top.bundle.GetStringFromName( 'ImportMailNotFound');
return( false);
}
}
else {
error.data = top.bundle.GetStringFromName( 'ImportMailNotFound');
return( false);
}
}
else {
error.data = top.bundle.GetStringFromName( 'ImportMailNotFound');
return( false);
}
}
if (mailInterface.WantsProgress()) {
if (mailInterface.BeginImport( success, error)) {
top.progressInfo.importInterface = mailInterface;
// top.intervalState = setInterval( "ContinueImport()", 100);
return( true);
}
else {
return( false);
}
}
else {
dump( "*** WantsProgress returned false\n");
if (mailInterface.BeginImport( success, error)) {
return( true);
}
else {
return( false);
}
}
}
// The address import! A little more complicated than the mail import
// due to field maps...
function ImportAddress( module, success, error) {
if (top.progressInfo.importInterface || top.progressInfo.intervalState) {
error.data = top.bundle.GetStringFromName( 'ImportAlreadyInProgress');
return( false);
}
top.progressInfo.importSuccess = false;
var addInterface = module.GetImportInterface( "addressbook");
if (addInterface != null)
addInterface = addInterface.QueryInterface( Components.interfaces.nsIImportGeneric);
if (addInterface == null) {
error.data = top.bundle.GetStringFromName( 'ImportAddressBadModule');
return( false);
}
var loc = addInterface.GetStatus( "autoFind");
if (loc == false) {
loc = addInterface.GetData( "addressLocation");
if (loc != null) {
if (!loc.exists)
loc = null;
}
}
if (loc == null) {
// Couldn't find the address book, see if we can
// as the user for the location or not?
if (addInterface.GetStatus( "canUserSetLocation") == 0) {
// an autofind address book that could not be found!
error.data = top.bundle.GetStringFromName( 'ImportAddressNotFound');
return( false);
}
var filePicker = Components.classes["component://netscape/filespecwithui"].createInstance();
if (filePicker != null) {
filePicker = filePicker.QueryInterface( Components.interfaces.nsIFileSpecWithUI);
if (filePicker == null) {
error.data = top.bundle.GetStringFromName( 'ImportAddressNotFound');
return( false);
}
}
else {
error.data = top.bundle.GetStringFromName( 'ImportAddressNotFound');
return( false);
}
// The address book location was not found.
// Determine if we need to ask for a directory
// or a single file.
var file = null;
if (addInterface.GetStatus( "supportsMultiple") != 0) {
// ask for dir
try {
filePicker.chooseDirectory( "Select address book directory");
file = filePicker.QueryInterface( Components.interfaces.nsIFileSpec);
} catch( ex) {
file = null;
}
}
else {
// ask for file
try {
filePicker.chooseInputFile( "Select address book file", filePicker.eAllFiles, null, null);
file = filePicker.QueryInterface( Components.interfaces.nsIFileSpec);
} catch( ex) {
file = null;
}
}
if (file == null) {
return( false);
}
addInterface.SetData( "addressLocation", file);
}
var map = addInterface.GetData( "fieldMap");
if (map != null) {
// FIXME: Show modal UI to handle the field map!
}
if (addInterface.WantsProgress()) {
if (addInterface.BeginImport( success, error)) {
top.progressInfo.importInterface = addInterface;
// top.intervalState = setInterval( "ContinueImport()", 100);
return( true);
}
else {
return( false);
}
}
else {
if (addInterface.BeginImport( success, error)) {
return( true);
}
else {
return( false);
}
}
}

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

@ -0,0 +1,78 @@
<?xml version="1.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 Communicator client code, released
March 31, 1998.
The Initial Developer of the Original Code is Netscape
Communications Corporation. Portions created by Netscape are
Copyright (C) 1998-1999 Netscape Communications Corporation. All
Rights Reserved.
-->
<?xml-stylesheet href="chrome://messenger/skin/" type="text/css"?>
<?xul-overlay href="chrome://global/content/dialogOverlay.xul"?>
<!DOCTYPE window SYSTEM "chrome://messenger/locale/importDialog.dtd">
<window xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
class="dialog"
style="padding:0px"
onload="OnLoadImportDialog()"
align="vertical">
<html:script src="chrome://global/content/strres.js"/>
<html:script src="chrome://messenger/content/importDialog.js"/>
<!--html:script language="JavaScript" src="resource:/res/samples/DumpDOM.js"/-->
<keyset id="keyset"/>
<box align="horizontal">
<spring style="width:3em"/>
<!-- module list -->
<box align="vertical" style="height:170px">
<spring style="height:1em"/>
<html:div id="listLabel">*</html:div>
<spring style="height:.5em"/>
<box align="vertical" style="border: 1px inset white">
<html:div style="width:20em; height:100px" flex="1">
<tree id="moduleList" style="width:100%; height:100%" onselect="ImportSelectionChanged()">
<treecol style="width:100%"/>
<treechildren id="bucketBody"/>
</tree>
</html:div>
</box>
<spring style="height:1.5em"/>
<box align="vertical" style="height: 3em; background-color:white; border:1px inset white;">
<html:div id="description" flex="1"></html:div>
</box>
<spring style="height:2em"/>
</box>
<spring style="width:3em"/>
</box>
<!-- OK & Cancel buttons -->
<box id="okCancelButtons"/>
</window>

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

@ -0,0 +1,59 @@
var progressMeter = 0;
var progressInfo = null;
function OnLoadProgressDialog()
{
dump( "*** Loaded progress window\n");
top.progressMeter = document.getElementById( 'progressMeter');
// look in arguments[0] for parameters
if (window.arguments && window.arguments[0])
{
// keep parameters in global for later
if ( window.arguments[0].windowTitle )
top.window.title = window.arguments[0].windowTitle;
if ( window.arguments[0].progressTitle )
SetDivText( 'ProgressTitle', window.arguments[0].progressTitle );
if ( window.arguments[0].progressStatus )
SetDivText( 'ProgressStatus', window.arguments[0].progressStatus );
top.progressInfo = window.arguments[0].progressInfo;
}
top.progressInfo.progressWindow = top.window;
top.progressInfo.intervalState = setInterval( "Continue()", 500);
}
function SetProgress( val)
{
top.progressMeter.setAttribute( "value", val);
}
function SetDivText(id, text)
{
var div = document.getElementById(id);
if ( div )
{
if ( div.childNodes.length == 0 )
{
var textNode = document.createTextNode(text);
div.appendChild(textNode);
}
else if ( div.childNodes.length == 1 )
div.childNodes[0].nodeValue = text;
}
}
function Continue()
{
top.progressInfo.mainWindow.ContinueImport( top.progressInfo);
}

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

@ -0,0 +1,63 @@
<?xml version="1.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 Communicator client code, released
March 31, 1998.
The Initial Developer of the Original Code is Netscape
Communications Corporation. Portions created by Netscape are
Copyright (C) 1998-1999 Netscape Communications Corporation. All
Rights Reserved.
-->
<?xml-stylesheet href="chrome://messenger/skin/" type="text/css"?>
<?xul-overlay href="chrome://global/content/dialogOverlay.xul"?>
<!DOCTYPE window SYSTEM "chrome://messenger/locale/importDialog.dtd">
<window xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
class="dialog"
style="padding:0px"
onload="OnLoadProgressDialog()"
align="vertical">
<html:script src="chrome://global/content/strres.js"/>
<html:script src="chrome://messenger/content/importProgress.js"/>
<!--html:script language="JavaScript" src="resource:/res/samples/DumpDOM.js"/-->
<keyset id="keyset"/>
<box align="vertical" flex="100%">
<html:div id="progressTitle">Title</html:div>
<spring style="height:1em"/>
<html:div id="progressStatus" flex="100%">Processing</html:div>
<spring style="height:1em"/>
<box align="horizontal">
<progressmeter id="progressMeter" mode="normal" value="0" flex="100%"/>
<spring style="width: 2em"/>
</box>
<spring style="height: 1em"/>
</box>
</window>

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

@ -25,9 +25,17 @@ include <$(DEPTH)\config\rules.mak>
install:: install::
$(MAKE_INSTALL) import-test.html $(DIST)\bin\res\samples $(MAKE_INSTALL) import-test.html $(DIST)\bin\res\samples
$(MAKE_INSTALL) importDialog.js $(DIST)\bin\chrome\messenger\content\default
$(MAKE_INSTALL) importDialog.xul $(DIST)\bin\chrome\messenger\content\default
$(MAKE_INSTALL) importProgress.xul $(DIST)\bin\chrome\messenger\content\default
$(MAKE_INSTALL) importProgress.js $(DIST)\bin\chrome\messenger\content\default
clobber:: clobber::
rm -f $(DIST)\bin\res\samples\import-test.html rm -f $(DIST)\bin\res\samples\import-test.html
rm -f $(DIST)\bin\chrome\messenger\content\default\importDialog.js
rm -f $(DIST)\bin\chrome\messenger\content\default\importDialog.xul
rm -f $(DIST)\bin\chrome\messenger\content\default\importProgress.js
rm -f $(DIST)\bin\chrome\messenger\content\default\importProgress.xul

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

@ -78,10 +78,213 @@
## @loc None ## @loc None
2010=Unable to create an account to import mail into 2010=Unable to create an account to import mail into
# Description: Address book field name
## @name IMPORT_FIELD_DESC_START
## @loc None
2100=First Name
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2101=Last Name
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2102=Display Name
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2103=Nickname
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2104=Primary Email
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2105=Secondary Email
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2106=Work Phone
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2107=Home Phone
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2108=Fax Number
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2109=Pager Number
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2110=Cellular Number
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2111=Home Address
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2112=Home Address 2
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2113=Home City
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2114=Home State
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2115=Home ZipCode
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2116=Home Country
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2117=Work Address
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2118=Work Address 2
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2119=Work City
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2120=Work State
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2121=Work ZipCode
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2122=Work Country
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2123=Job Title
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2124=Department
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2125=Company
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2126=Web Page 1
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2127=Web Page 2
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2128=Birth Year
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2129=Birth Month
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2130=Birth Day
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2131=Custom 1
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2132=Custom 2
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2133=Custom 3
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2134=Custom 4
# Description: Address book field name
## @name IMPORT_FIELD_DESC_END
## @loc None
2135=Notes
# Description: Strings for the import dialog
ImportMailDialogTitle=Import Mail
ImportAddressBooksDialogTitle=Import Address Books
ImportSettingsDialogTitle=Import Settings
ImportMailListLabel=Select application to import mail from:
ImportAddressBooksListLabel=Select address book format:
ImportSettingsListLabel=Select application to import settings from:
#Error strings
ImportAlreadyInProgress=An import operation is currently in progress, try again when the current import has finished.
#Error strings for settings import
ImportSettingsBadModule=Unable to load settings module
ImportSettingsNotFound=Unable to find settings. Check to make sure the application is installed on this machine.
ImportSettingsFailed=An error occurred while importing settings. Some, or all, of the settings may not have been imported.
ImportSettingsSuccess=Settings were imported from
#Error string for mail import
ImportMailBadModule=Unable to load mail import module
ImportMailNotFound=Unable to find mail to import. Check to make sure the mail application is correctly installed on this machine.
ImportMailFailed=An error occurred importing mail from
ImportMailSuccess=Mail was successfully imported from
#Error string for address import
ImportAddressBadModule=Unable to load address book import module
ImportAddressNotFound=Unable to find any address books to import. Check to make sure the selected application or format is correctly installed on this machine.
ImportAddressFailed=An error occurred importing addresses from
ImportAddressSuccess=Addresses were successfully imported from

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

@ -42,6 +42,7 @@ CPP_OBJS=\
.\$(OBJDIR)\nsImportScanFile.obj \ .\$(OBJDIR)\nsImportScanFile.obj \
.\$(OBJDIR)\nsImportEncodeScan.obj \ .\$(OBJDIR)\nsImportEncodeScan.obj \
.\$(OBJDIR)\nsImportMimeEncode.obj \ .\$(OBJDIR)\nsImportMimeEncode.obj \
.\$(OBJDIR)\nsImportFieldMap.obj \
$(NULL) $(NULL)
LLIBS=\ LLIBS=\

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

@ -24,11 +24,13 @@
#include "prprf.h" #include "prprf.h"
#include "nscore.h" #include "nscore.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsIImportService.h"
#include "nsISupportsArray.h" #include "nsISupportsArray.h"
#include "nsIImportAddressBooks.h" #include "nsIImportAddressBooks.h"
#include "nsIImportGeneric.h" #include "nsIImportGeneric.h"
#include "nsISupportsPrimitives.h" #include "nsISupportsPrimitives.h"
#include "nsIImportABDescriptor.h" #include "nsIImportABDescriptor.h"
#include "nsIImportFieldMap.h"
#include "nsCRT.h" #include "nsCRT.h"
#include "nsString.h" #include "nsString.h"
#include "nsIURL.h" #include "nsIURL.h"
@ -47,6 +49,7 @@
#include "nsTextFormater.h" #include "nsTextFormater.h"
#include "ImportDebug.h" #include "ImportDebug.h"
static NS_DEFINE_CID(kImportServiceCID, NS_IMPORTSERVICE_CID);
static NS_DEFINE_CID(kAddressBookDBCID, NS_ADDRDATABASE_CID); static NS_DEFINE_CID(kAddressBookDBCID, NS_ADDRDATABASE_CID);
static NS_DEFINE_CID(kProfileCID, NS_PROFILE_CID); static NS_DEFINE_CID(kProfileCID, NS_PROFILE_CID);
static NS_DEFINE_CID(kAbDirectoryCID, NS_ABDIRECTORY_CID); static NS_DEFINE_CID(kAbDirectoryCID, NS_ABDIRECTORY_CID);
@ -54,6 +57,7 @@ static NS_DEFINE_CID(kStandardUrlCID, NS_STANDARDURL_CID);
static NS_DEFINE_IID(kIStandardUrlIID, NS_IURL_IID); static NS_DEFINE_IID(kIStandardUrlIID, NS_IURL_IID);
static NS_DEFINE_CID(kAddrBookSessionCID, NS_ADDRBOOKSESSION_CID); static NS_DEFINE_CID(kAddrBookSessionCID, NS_ADDRBOOKSESSION_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_IID(kIImportFieldMapIID, NS_IIMPORTFIELDMAP_IID);
static const char *kDirectoryDataSourceRoot = "abdirectory://"; static const char *kDirectoryDataSourceRoot = "abdirectory://";
static const char *kCardDataSourceRoot = "abcard://"; static const char *kCardDataSourceRoot = "abcard://";
@ -99,6 +103,7 @@ public:
private: private:
void GetDefaultLocation( void); void GetDefaultLocation( void);
void GetDefaultBooks( void); void GetDefaultBooks( void);
void GetDefaultFieldMap( void);
public: public:
static void SetLogs( nsString& success, nsString& error, nsISupportsWString *pSuccess, nsISupportsWString *pError); static void SetLogs( nsString& success, nsString& error, nsISupportsWString *pSuccess, nsISupportsWString *pError);
@ -108,6 +113,7 @@ private:
nsIImportAddressBooks * m_pInterface; nsIImportAddressBooks * m_pInterface;
nsISupportsArray * m_pBooks; nsISupportsArray * m_pBooks;
nsIFileSpec * m_pLocation; nsIFileSpec * m_pLocation;
nsIImportFieldMap * m_pFieldMap;
PRBool m_autoFind; PRBool m_autoFind;
PRUnichar * m_description; PRUnichar * m_description;
PRBool m_gotLocation; PRBool m_gotLocation;
@ -131,6 +137,7 @@ public:
PRUint32 currentSize; PRUint32 currentSize;
nsISupportsArray * books; nsISupportsArray * books;
nsIImportAddressBooks * addressImport; nsIImportAddressBooks * addressImport;
nsIImportFieldMap * fieldMap;
nsISupportsWString * successLog; nsISupportsWString * successLog;
nsISupportsWString * errorLog; nsISupportsWString * errorLog;
char * pDestinationUri; char * pDestinationUri;
@ -172,6 +179,7 @@ nsImportGenericAddressBooks::nsImportGenericAddressBooks()
m_doImport = PR_FALSE; m_doImport = PR_FALSE;
m_pThreadData = nsnull; m_pThreadData = nsnull;
m_pDestinationUri = nsnull; m_pDestinationUri = nsnull;
m_pFieldMap = nsnull;
m_pLocation = nsnull; m_pLocation = nsnull;
m_autoFind = PR_FALSE; m_autoFind = PR_FALSE;
@ -195,6 +203,7 @@ nsImportGenericAddressBooks::~nsImportGenericAddressBooks()
if (m_description) if (m_description)
nsCRT::free( m_description); nsCRT::free( m_description);
NS_IF_RELEASE( m_pFieldMap);
NS_IF_RELEASE( m_pLocation); NS_IF_RELEASE( m_pLocation);
NS_IF_RELEASE( m_pInterface); NS_IF_RELEASE( m_pInterface);
NS_IF_RELEASE( m_pBooks); NS_IF_RELEASE( m_pBooks);
@ -248,10 +257,30 @@ NS_IMETHODIMP nsImportGenericAddressBooks::GetData(const char *dataId, nsISuppor
} }
} }
if (!nsCRT::strcasecmp( dataId, "fieldMap")) {
if (m_pFieldMap) {
*_retval = m_pFieldMap;
m_pFieldMap->AddRef();
}
else {
if (m_pInterface && m_pLocation) {
PRBool needsIt = PR_FALSE;
m_pInterface->GetNeedsFieldMap( m_pLocation, &needsIt);
if (needsIt) {
GetDefaultFieldMap();
if (m_pFieldMap) {
*_retval = m_pFieldMap;
m_pFieldMap->AddRef();
}
}
}
}
}
return( NS_OK); return( NS_OK);
} }
NS_IMETHODIMP nsImportGenericAddressBooks::SetData( const char *dataId, nsISupports *item) NS_IMETHODIMP nsImportGenericAddressBooks::SetData( const char *dataId, nsISupports *item)
{ {
NS_PRECONDITION(dataId != nsnull, "null ptr"); NS_PRECONDITION(dataId != nsnull, "null ptr");
@ -288,6 +317,11 @@ NS_IMETHODIMP nsImportGenericAddressBooks::SetData( const char *dataId, nsISuppo
} }
} }
if (!nsCRT::strcasecmp( dataId, "fieldMap")) {
NS_IF_RELEASE( m_pFieldMap);
if (item)
item->QueryInterface( nsIImportFieldMap::GetIID(), (void **) &m_pFieldMap);
}
return( NS_OK); return( NS_OK);
} }
@ -323,6 +357,12 @@ NS_IMETHODIMP nsImportGenericAddressBooks::GetStatus( const char *statusKind, PR
*_retval = (PRInt32) multi; *_retval = (PRInt32) multi;
} }
if (!nsCRT::strcasecmp( statusKind, "needsFieldMap")) {
PRBool needs = PR_FALSE;
if (m_pInterface && m_pLocation)
m_pInterface->GetNeedsFieldMap( m_pLocation, &needs);
*_retval = (PRInt32) needs;
}
return( NS_OK); return( NS_OK);
} }
@ -366,6 +406,36 @@ void nsImportGenericAddressBooks::GetDefaultBooks( void)
nsresult rv = m_pInterface->FindAddressBooks( m_pLocation, &m_pBooks); nsresult rv = m_pInterface->FindAddressBooks( m_pLocation, &m_pBooks);
} }
void nsImportGenericAddressBooks::GetDefaultFieldMap( void)
{
if (!m_pInterface || !m_pLocation)
return;
NS_IF_RELEASE( m_pFieldMap);
nsresult rv;
NS_WITH_SERVICE(nsIImportService, impSvc, kImportServiceCID, &rv);
if (NS_FAILED(rv)) {
IMPORT_LOG0( "*** Unable to get nsIImportService.\n");
return;
}
rv = impSvc->CreateNewFieldMap( &m_pFieldMap);
if (NS_FAILED( rv))
return;
PRInt32 sz = 0;
rv = m_pFieldMap->GetNumMozFields( &sz);
if (NS_SUCCEEDED( rv))
rv = m_pFieldMap->DefaultFieldMap( sz);
if (NS_SUCCEEDED( rv))
rv = m_pInterface->InitFieldMap( m_pLocation, m_pFieldMap);
if (NS_FAILED( rv)) {
IMPORT_LOG0( "*** Error: Unable to initialize field map\n");
NS_IF_RELEASE( m_pFieldMap);
}
}
NS_IMETHODIMP nsImportGenericAddressBooks::WantsProgress(PRBool *_retval) NS_IMETHODIMP nsImportGenericAddressBooks::WantsProgress(PRBool *_retval)
{ {
@ -493,6 +563,8 @@ NS_IMETHODIMP nsImportGenericAddressBooks::BeginImport(nsISupportsWString *succe
NS_ADDREF( m_pBooks); NS_ADDREF( m_pBooks);
m_pThreadData->addressImport = m_pInterface; m_pThreadData->addressImport = m_pInterface;
NS_ADDREF( m_pInterface); NS_ADDREF( m_pInterface);
m_pThreadData->fieldMap = m_pFieldMap;
NS_IF_ADDREF( m_pFieldMap);
m_pThreadData->errorLog = m_pErrorLog; m_pThreadData->errorLog = m_pErrorLog;
NS_IF_ADDREF( m_pErrorLog); NS_IF_ADDREF( m_pErrorLog);
m_pThreadData->successLog = m_pSuccessLog; m_pThreadData->successLog = m_pSuccessLog;
@ -590,6 +662,7 @@ AddressThreadData::AddressThreadData()
successLog = nsnull; successLog = nsnull;
errorLog = nsnull; errorLog = nsnull;
pDestinationUri = nsnull; pDestinationUri = nsnull;
fieldMap = nsnull;
} }
AddressThreadData::~AddressThreadData() AddressThreadData::~AddressThreadData()
@ -601,6 +674,7 @@ AddressThreadData::~AddressThreadData()
NS_IF_RELEASE( addressImport); NS_IF_RELEASE( addressImport);
NS_IF_RELEASE( errorLog); NS_IF_RELEASE( errorLog);
NS_IF_RELEASE( successLog); NS_IF_RELEASE( successLog);
NS_IF_RELEASE( fieldMap);
} }
void AddressThreadData::DriverDelete( void) void AddressThreadData::DriverDelete( void)
@ -826,7 +900,7 @@ PR_STATIC_CALLBACK( void) ImportAddressThread( void *stuff)
PRUnichar *pError = nsnull; PRUnichar *pError = nsnull;
rv = pData->addressImport->ImportAddressBook( book, rv = pData->addressImport->ImportAddressBook( book,
pDestDB, // destination pDestDB, // destination
nsnull, // fieldmap pData->fieldMap, // fieldmap
&pError, &pError,
&pSuccess, &pSuccess,
&fatalError); &fatalError);

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

@ -0,0 +1,537 @@
/* -*- 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 "nscore.h"
#include "nsIStringBundle.h"
#include "nsImportFieldMap.h"
#include "nsImportStringBundle.h"
////////////////////////////////////////////////////////////////////////
NS_METHOD nsImportFieldMap::Create( nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
if (aOuter)
return NS_ERROR_NO_AGGREGATION;
nsImportFieldMap *it = new nsImportFieldMap();
if (it == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF( it);
nsresult rv = it->QueryInterface( aIID, aResult);
NS_RELEASE( it);
return rv;
}
NS_IMPL_ISUPPORTS(nsImportFieldMap, nsIImportFieldMap::GetIID());
nsImportFieldMap::nsImportFieldMap()
{
NS_INIT_ISUPPORTS();
m_numFields = 0;
m_pFields = nsnull;
m_allocated = 0;
// need to init the description array
m_mozFieldCount = 0;
nsIStringBundle *pBundle = nsImportStringBundle::GetStringBundle();
nsString *pStr;
for (PRInt32 i = IMPORT_FIELD_DESC_START; i <= IMPORT_FIELD_DESC_END; i++, m_mozFieldCount++) {
pStr = new nsString();
nsImportStringBundle::GetStringByID( i, *pStr, pBundle);
m_descriptions.AppendElement( (void *)pStr);
}
NS_IF_RELEASE( pBundle);
}
nsImportFieldMap::~nsImportFieldMap()
{
if (m_pFields)
delete [] m_pFields;
nsString * pStr;
for (PRInt32 i = 0; i < m_mozFieldCount; i++) {
pStr = (nsString *) m_descriptions.ElementAt( i);
delete pStr;
}
m_descriptions.Clear();
}
NS_IMETHODIMP nsImportFieldMap::GetNumMozFields(PRInt32 *aNumFields)
{
NS_PRECONDITION(aNumFields != nsnull, "null ptr");
if (!aNumFields)
return NS_ERROR_NULL_POINTER;
*aNumFields = m_mozFieldCount;
return( NS_OK);
}
NS_IMETHODIMP nsImportFieldMap::GetMapSize(PRInt32 *aNumFields)
{
NS_PRECONDITION(aNumFields != nsnull, "null ptr");
if (!aNumFields)
return NS_ERROR_NULL_POINTER;
*aNumFields = m_numFields;
return( NS_OK);
}
NS_IMETHODIMP nsImportFieldMap::GetFieldDescription(PRInt32 index, PRUnichar **_retval)
{
NS_PRECONDITION(_retval != nsnull, "null ptr");
if (!_retval)
return NS_ERROR_NULL_POINTER;
*_retval = nsnull;
if ((index < 0) || (index >= m_descriptions.Count()))
return( NS_ERROR_FAILURE);
*_retval = ((nsString *)m_descriptions.ElementAt( index))->ToNewUnicode();
return( NS_OK);
}
NS_IMETHODIMP nsImportFieldMap::SetFieldMapSize(PRInt32 size)
{
nsresult rv = Allocate( size);
if (NS_FAILED( rv))
return( rv);
m_numFields = size;
return( NS_OK);
}
NS_IMETHODIMP nsImportFieldMap::DefaultFieldMap(PRInt32 size)
{
nsresult rv = SetFieldMapSize( size);
if (NS_FAILED( rv))
return( rv);
for (PRInt32 i = 0; i < size; i++)
m_pFields[i] = i;
return( NS_OK);
}
NS_IMETHODIMP nsImportFieldMap::GetFieldMap(PRInt32 index, PRInt32 *_retval)
{
NS_PRECONDITION(_retval != nsnull, "null ptr");
if (!_retval)
return NS_ERROR_NULL_POINTER;
if ((index < 0) || (index >= m_numFields))
return( NS_ERROR_FAILURE);
*_retval = m_pFields[index];
return( NS_OK);
}
NS_IMETHODIMP nsImportFieldMap::SetFieldMap(PRInt32 index, PRInt32 fieldNum)
{
if (index == -1) {
nsresult rv = Allocate( m_numFields + 1);
if (NS_FAILED( rv))
return( rv);
index = m_numFields;
m_numFields++;
}
else {
if ((index < 0) || (index >= m_numFields))
return( NS_ERROR_FAILURE);
}
if ((fieldNum != -1) && ((fieldNum < 0) || (fieldNum >= m_mozFieldCount)))
return( NS_ERROR_FAILURE);
m_pFields[index] = fieldNum;
return( NS_OK);
}
NS_IMETHODIMP nsImportFieldMap::SetFieldMapByDescription(PRInt32 index, const PRUnichar *fieldDesc)
{
NS_PRECONDITION(fieldDesc != nsnull, "null ptr");
if (!fieldDesc)
return NS_ERROR_NULL_POINTER;
PRInt32 i = FindFieldNum( fieldDesc);
if (i == -1)
return( NS_ERROR_FAILURE);
return( SetFieldMap( index, i));
}
NS_IMETHODIMP nsImportFieldMap::SetFieldValue(nsIAddrDatabase *database, nsIMdbRow *row, PRInt32 fieldNum, const PRUnichar *value)
{
NS_PRECONDITION(database != nsnull, "null ptr");
NS_PRECONDITION(row != nsnull, "null ptr");
NS_PRECONDITION(value != nsnull, "null ptr");
if (!database || !row || !value)
return NS_ERROR_NULL_POINTER;
// Allow the special value for a null field
if (fieldNum == -1)
return( NS_OK);
if ((fieldNum < 0) || (fieldNum >= m_mozFieldCount))
return( NS_ERROR_FAILURE);
// UGGG!!!!! lot's of typing here!
nsresult rv;
nsString str = value;
char *pVal = str.ToNewCString();
switch( fieldNum) {
case 0:
rv = database->AddFirstName( row, pVal);
break;
case 1:
rv = database->AddLastName( row, pVal);
break;
case 2:
rv = database->AddDisplayName( row, pVal);
break;
case 3:
rv = database->AddNickName( row, pVal);
break;
case 4:
rv = database->AddPrimaryEmail( row, pVal);
break;
case 5:
rv = database->Add2ndEmail( row, pVal);
break;
case 6:
rv = database->AddWorkPhone( row, pVal);
break;
case 7:
rv = database->AddHomePhone( row, pVal);
break;
case 8:
rv = database->AddFaxNumber( row, pVal);
break;
case 9:
rv = database->AddPagerNumber( row, pVal);
break;
case 10:
rv = database->AddCellularNumber( row, pVal);
break;
case 11:
rv = database->AddHomeAddress( row, pVal);
break;
case 12:
rv = database->AddHomeAddress2( row, pVal);
break;
case 13:
rv = database->AddHomeCity( row, pVal);
break;
case 14:
rv = database->AddHomeState( row, pVal);
break;
case 15:
rv = database->AddHomeZipCode( row, pVal);
break;
case 16:
rv = database->AddHomeCountry( row, pVal);
break;
case 17:
rv = database->AddWorkAddress( row, pVal);
break;
case 18:
rv = database->AddWorkAddress2( row, pVal);
break;
case 19:
rv = database->AddWorkCity( row, pVal);
break;
case 20:
rv = database->AddWorkState( row, pVal);
break;
case 21:
rv = database->AddWorkZipCode( row, pVal);
break;
case 22:
rv = database->AddWorkCountry( row, pVal);
break;
case 23:
rv = database->AddJobTitle(row, pVal);
break;
case 24:
rv = database->AddDepartment(row, pVal);
break;
case 25:
rv = database->AddCompany(row, pVal);
break;
case 26:
rv = database->AddWebPage1(row, pVal);
break;
case 27:
rv = database->AddWebPage2(row, pVal);
break;
case 28:
rv = database->AddBirthYear(row, pVal);
break;
case 29:
rv = database->AddBirthMonth(row, pVal);
break;
case 30:
rv = database->AddBirthDay(row, pVal);
break;
case 31:
rv = database->AddCustom1(row, pVal);
break;
case 32:
rv = database->AddCustom2(row, pVal);
break;
case 33:
rv = database->AddCustom3(row, pVal);
break;
case 34:
rv = database->AddCustom4(row, pVal);
break;
case 35:
rv = database->AddNotes(row, pVal);
break;
default:
/* Get the field description, and add it as an anonymous attr? */
/* OR WHAT???? */
{
rv = NS_ERROR_FAILURE;
}
}
nsCRT::free( pVal);
return( rv);
}
NS_IMETHODIMP nsImportFieldMap::SetFieldValueByDescription(nsIAddrDatabase *database, nsIMdbRow *row, const PRUnichar *fieldDesc, const PRUnichar *value)
{
NS_PRECONDITION(fieldDesc != nsnull, "null ptr");
if (!fieldDesc)
return NS_ERROR_NULL_POINTER;
PRInt32 i = FindFieldNum( fieldDesc);
if (i == -1)
return( NS_ERROR_FAILURE);
return( SetFieldValue( database, row, i, value));
}
NS_IMETHODIMP nsImportFieldMap::GetFieldValue(nsIAbCard *card, PRInt32 fieldNum, PRUnichar **_retval)
{
NS_PRECONDITION(_retval != nsnull, "null ptr");
NS_PRECONDITION(card != nsnull, "null ptr");
if (!_retval || !card)
return NS_ERROR_NULL_POINTER;
if (fieldNum == -1) {
PRUnichar c = 0;
*_retval = nsCRT::strdup( &c);
return( NS_OK);
}
if ((fieldNum < 0) || (fieldNum >= m_mozFieldCount))
return( NS_ERROR_FAILURE);
// ARRGGG!!! Lots of typing again
// get the field from the card
nsresult rv;
PRUnichar * pVal = nsnull;
switch (fieldNum) {
case 0:
rv = card->GetFirstName( &pVal);
break;
case 1:
rv = card->GetLastName( &pVal);
break;
case 2:
rv = card->GetDisplayName( &pVal);
break;
case 3:
rv = card->GetNickName( &pVal);
break;
case 4:
rv = card->GetPrimaryEmail( &pVal);
break;
case 5:
rv = card->GetSecondEmail( &pVal);
break;
case 6:
rv = card->GetWorkPhone( &pVal);
break;
case 7:
rv = card->GetHomePhone( &pVal);
break;
case 8:
rv = card->GetFaxNumber( &pVal);
break;
case 9:
rv = card->GetPagerNumber( &pVal);
break;
case 10:
rv = card->GetCellularNumber( &pVal);
break;
case 11:
rv = card->GetHomeAddress( &pVal);
break;
case 12:
rv = card->GetHomeAddress2( &pVal);
break;
case 13:
rv = card->GetHomeCity( &pVal);
break;
case 14:
rv = card->GetHomeState( &pVal);
break;
case 15:
rv = card->GetHomeZipCode( &pVal);
break;
case 16:
rv = card->GetHomeCountry( &pVal);
break;
case 17:
rv = card->GetWorkAddress( &pVal);
break;
case 18:
rv = card->GetWorkAddress2( &pVal);
break;
case 19:
rv = card->GetWorkCity( &pVal);
break;
case 20:
rv = card->GetWorkState( &pVal);
break;
case 21:
rv = card->GetWorkZipCode( &pVal);
break;
case 22:
rv = card->GetWorkCountry( &pVal);
break;
case 23:
rv = card->GetJobTitle( &pVal);
break;
case 24:
rv = card->GetDepartment( &pVal);
break;
case 25:
rv = card->GetCompany( &pVal);
break;
case 26:
rv = card->GetWebPage1( &pVal);
break;
case 27:
rv = card->GetWebPage2( &pVal);
break;
case 28:
rv = card->GetBirthYear( &pVal);
break;
case 29:
rv = card->GetBirthMonth( &pVal);
break;
case 30:
rv = card->GetBirthDay( &pVal);
break;
case 31:
rv = card->GetCustom1( &pVal);
break;
case 32:
rv = card->GetCustom2( &pVal);
break;
case 33:
rv = card->GetCustom3( &pVal);
break;
case 34:
rv = card->GetCustom4( &pVal);
break;
case 35:
rv = card->GetNotes( &pVal);
break;
default:
/* Get the field description, and add it as an anonymous attr? */
/* OR WHAT???? */
{
rv = NS_ERROR_FAILURE;
}
}
*_retval = pVal;
return( rv);
}
NS_IMETHODIMP nsImportFieldMap::GetFieldValueByDescription(nsIAbCard *card, const PRUnichar *fieldDesc, PRUnichar **_retval)
{
NS_PRECONDITION(fieldDesc != nsnull, "null ptr");
if (!fieldDesc)
return NS_ERROR_NULL_POINTER;
PRInt32 i = FindFieldNum( fieldDesc);
if (i == -1)
return( NS_ERROR_FAILURE);
return( GetFieldValue( card, i, _retval));
}
nsresult nsImportFieldMap::Allocate( PRInt32 newSize)
{
if (newSize <= m_allocated)
return( NS_OK);
PRInt32 sz = m_allocated;
while (sz < newSize)
sz += 30;
PRInt32 *pData = new PRInt32[ sz];
if (!pData)
return( NS_ERROR_FAILURE);
PRInt32 i;
for (i = 0; i < sz; i++)
pData[i] = -1;
if (m_numFields) {
for (i = 0; i < m_numFields; i++)
pData[i] = m_pFields[i];
delete [] m_pFields;
}
m_allocated = sz;
m_pFields = pData;
return( NS_OK);
}
PRInt32 nsImportFieldMap::FindFieldNum( const PRUnichar *pDesc)
{
nsString * pStr;
for (PRInt32 i = 0; i < m_mozFieldCount; i++) {
pStr = (nsString *)m_descriptions.ElementAt( i);
if (!pStr->Compare( pDesc))
return( i);
}
return( -1);
}

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

@ -0,0 +1,62 @@
/* -*- 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):
*/
#ifndef nsImportFieldMap_h___
#define nsImportFieldMap_h___
#include "nscore.h"
#include "nsString.h"
#include "nsIImportFieldMap.h"
#include "nsIAddrDatabase.h"
#include "nsVoidArray.h"
////////////////////////////////////////////////////////////////////////
class nsImportFieldMap : public nsIImportFieldMap
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIIMPORTFIELDMAP
nsImportFieldMap();
virtual ~nsImportFieldMap();
static NS_METHOD Create( nsISupports *aOuter, REFNSIID aIID, void **aResult);
private:
nsresult Allocate( PRInt32 newSize);
PRInt32 FindFieldNum( const PRUnichar *pDesc);
private:
PRInt32 m_numFields;
PRInt32 * m_pFields;
PRInt32 m_allocated;
nsVoidArray m_descriptions;
PRInt32 m_mozFieldCount;
};
#endif

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

@ -34,6 +34,7 @@
#include "nsImportMailboxDescriptor.h" #include "nsImportMailboxDescriptor.h"
#include "nsImportABDescriptor.h" #include "nsImportABDescriptor.h"
#include "nsIImportGeneric.h" #include "nsIImportGeneric.h"
#include "nsImportFieldMap.h"
#include "plstr.h" #include "plstr.h"
#include "prmem.h" #include "prmem.h"
#include "ImportDebug.h" #include "ImportDebug.h"
@ -82,6 +83,8 @@ public:
/* nsIImportModule GetModuleWithCID (in nsCIDRef cid); */ /* nsIImportModule GetModuleWithCID (in nsCIDRef cid); */
NS_IMETHOD GetModuleWithCID(const nsCID & cid, nsIImportModule **_retval); NS_IMETHOD GetModuleWithCID(const nsCID & cid, nsIImportModule **_retval);
/* nsIImportFieldMap CreateNewFieldMap (); */
NS_IMETHOD CreateNewFieldMap(nsIImportFieldMap **_retval);
/* nsIImportMailboxDescriptor CreateNewMailboxDescriptor (); */ /* nsIImportMailboxDescriptor CreateNewMailboxDescriptor (); */
NS_IMETHOD CreateNewMailboxDescriptor(nsIImportMailboxDescriptor **_retval); NS_IMETHOD CreateNewMailboxDescriptor(nsIImportMailboxDescriptor **_retval);
@ -196,6 +199,8 @@ nsImportService::nsImportService() : m_pModules( nsnull)
nsImportService::~nsImportService() nsImportService::~nsImportService()
{ {
gImportService = nsnull;
if (m_pModules != nsnull) if (m_pModules != nsnull)
delete m_pModules; delete m_pModules;
@ -214,6 +219,13 @@ NS_IMETHODIMP nsImportService::DiscoverModules( void)
return( DoDiscover()); return( DoDiscover());
} }
NS_IMETHODIMP nsImportService::CreateNewFieldMap( nsIImportFieldMap **_retval)
{
nsresult rv;
rv = nsImportFieldMap::Create( nsnull, nsIImportFieldMap::GetIID(), (void**)_retval);
return rv;
}
NS_IMETHODIMP nsImportService::CreateNewMailboxDescriptor( nsIImportMailboxDescriptor **_retval) NS_IMETHODIMP nsImportService::CreateNewMailboxDescriptor( nsIImportMailboxDescriptor **_retval)
{ {
nsresult rv; nsresult rv;

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

@ -50,5 +50,8 @@ public:
#define IMPORT_ERROR_MB_CREATE 2009 #define IMPORT_ERROR_MB_CREATE 2009
#define IMPORT_ERROR_MB_NODESTFOLDER 2010 #define IMPORT_ERROR_MB_NODESTFOLDER 2010
#define IMPORT_FIELD_DESC_START 2100
#define IMPORT_FIELD_DESC_END 2135
#endif /* _nsImportStringBundle_H__ */ #endif /* _nsImportStringBundle_H__ */

Двоичные данные
mailnews/import/text/macbuild/msgImportText.mcp Normal file

Двоичный файл не отображается.

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

@ -0,0 +1,21 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "MacPrefix.h"

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

@ -0,0 +1,21 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "MacPrefix_debug.h"

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

@ -0,0 +1,25 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..
DIRS=resources src
include <$(DEPTH)\config\rules.mak>

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

@ -0,0 +1,28 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1999 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..\..\..\..
include <$(DEPTH)\config\rules.mak>
install::
$(MAKE_INSTALL) textImportMsgs.properties $(DIST)\bin\chrome\messenger\locale\en-US
clobber::
rm -f $(DIST)bin\chrome\messenger\locale\en-US\textImportMsgs.properties

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

@ -0,0 +1,58 @@
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
#
# The following are used by the outlook express import code to display status/error
# and informational messages
#
# Short name of import module
## @name TEXTIMPORT_NAME
## @loc None
2000=Text
# Description of import module
## @name TEXTIMPORT_DESCRIPTION
## @loc None
2001=Address books in text format, comma or tab delimitted
# Description of import module
## @name TEXTIMPORT_ADDRESS_NAME
## @loc None
2002=Text Address Book
# Description
## @name TEXTIMPORT_ADDRESS_SUCCESS
## @loc None
2003=Imported address book %S
# Error message
## @name TEXTIMPORT_ADDRESS_BADPARAM
## @loc None
2004=Bad parameter passed to import address book.
# Error message
## @name TEXTIMPORT_ADDRESS_BADSOURCEFILE
## @loc None
2005=Error accessing file for address book %S.
# Error message
## @name TEXTIMPORT_ADDRESS_CONVERTERROR
## @loc None
2006=Error importing address book %S, all addresses may not have been imported.

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

@ -0,0 +1,22 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1999 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..\..\..
DIRS= en-US
include <$(DEPTH)\config\rules.mak>

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

@ -0,0 +1,22 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1999 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..\..
DIRS= locale
include <$(DEPTH)\config\rules.mak>

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

@ -0,0 +1,45 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef TextDebugLog_h___
#define TextDebugLog_h___
#ifdef NS_DEBUG
#define IMPORT_DEBUG 1
#endif
#ifdef IMPORT_DEBUG
#include "stdio.h"
#define IMPORT_LOG0( x) printf( x)
#define IMPORT_LOG1( x, y) printf( x, y)
#define IMPORT_LOG2( x, y, z) printf( x, y, z)
#define IMPORT_LOG3( a, b, c, d) printf( a, b, c, d)
#else
#define IMPORT_LOG0( x)
#define IMPORT_LOG1( x, y)
#define IMPORT_LOG2( x, y, z)
#define IMPORT_LOG3( a, b, c, d)
#endif
#endif /* TextDebugLog_h___ */

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

@ -0,0 +1,44 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..\..
MODULE=impText
MAKE_OBJ_TYPE=DLL
DLLNAME=$(MODULE)
DLL=.\$(OBJDIR)\$(DLLNAME).dll
CPP_OBJS=\
.\$(OBJDIR)\nsTextFactory.obj \
.\$(OBJDIR)\nsTextStringBundle.obj \
.\$(OBJDIR)\nsTextImport.obj \
.\$(OBJDIR)\nsTextAddress.obj \
$(NULL)
LLIBS=\
$(DIST)\lib\xpcom.lib \
$(DIST)\lib\plc3.lib \
$(LIBNSPR) \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) $(DLL) $(DIST)\bin\components

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -0,0 +1,79 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsTextAddress_h__
#define nsTextAddress_h__
#include "nscore.h"
#include "nsString.h"
#include "nsVoidArray.h"
#include "nsIFileSpec.h"
#include "nsISupportsArray.h"
#include "nsIImportFieldMap.h"
class nsIAddrDatabase;
class nsIMdbRow;
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
class nsTextAddress {
public:
nsTextAddress();
virtual ~nsTextAddress();
nsresult ImportAddresses( PRBool *pAbort, const PRUnichar *pName, nsIFileSpec *pSrc, nsIAddrDatabase *pDb, nsIImportFieldMap *fieldMap, nsString& errors);
nsresult ImportLDIF( PRBool *pAbort, const PRUnichar *pName, nsIFileSpec *pSrc, nsIAddrDatabase *pDb, nsString& errors);
nsresult DetermineDelim( nsIFileSpec *pSrc);
static nsresult IsLDIFFile( nsIFileSpec *pSrc, PRBool *pIsLDIF);
static nsresult ReadRecordNumber( nsIFileSpec *pSrc, char *pLine, PRInt32 bufferSz, char delim, PRInt32 *pLineLen, PRInt32 rNum);
static nsresult ReadRecord( nsIFileSpec *pSrc, char *pLine, PRInt32 bufferSz, char delim, PRInt32 *pLineLen);
static PRBool GetField( const char *pLine, PRInt32 maxLen, PRInt32 index, nsCString& field, char delim);
private:
nsresult ProcessLine( const char *pLine, PRInt32 len, nsString& errors);
static PRBool IsLineComplete( const char *pLine, PRInt32 len, char delim);
static PRInt32 CountFields( const char *pLine, PRInt32 maxLen, char delim);
static void SanitizeSingleLine( nsCString& val);
private:
// LDIF stuff, this wasn't originally written by me!
nsresult str_parse_line( char *line, char **type, char **value, int *vlen);
char * str_getline( char **next);
nsresult GetLdifStringRecord(char* buf, PRInt32 len, PRInt32& stopPos);
nsresult ParseLdifFile( nsIFileSpec *pSrc);
void AddLdifRowToDatabase( void);
void AddLdifColToDatabase(nsIMdbRow* newRow, char* typeSlot, char* valueSlot);
private:
nsCString m_ldifLine;
char m_delim;
nsIAddrDatabase * m_database;
nsIImportFieldMap * m_fieldMap;
};
#endif /* nsTextAddress_h__ */

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

@ -0,0 +1,365 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
Text import module
*/
#include "nsCOMPtr.h"
#include "nsIModule.h"
#include "nsIGenericFactory.h"
#include "nsIServiceManager.h"
#include "nsIRegistry.h"
#include "nsIImportService.h"
#include "nsTextImport.h"
#include "TextDebugLog.h"
static NS_DEFINE_CID(kTextImportCID, NS_TEXTIMPORT_CID);
static NS_DEFINE_CID(kImportServiceCID, NS_IMPORTSERVICE_CID);
static NS_DEFINE_CID(kRegistryCID, NS_REGISTRY_CID);
/*
This doesn't work for me because I need to do some
additional work in RegisterSelf.
However, I should be able to delegate to the generic implementation
and just do the extra work I need?
NS_GENERIC_FACTORY_CONSTRUCTOR(nsEudoraImport)
static nsModuleComponentInfo components[] = {
{ "Eudora Import Component",
NS_EUDORAIMPORT_CID,
"component://mozilla/import/import-eudora",
nsEudoraImportConstructor}
};
NS_IMPL_NSGETMODULE("nsEudoraImportModule", components)
*/
// Module implementation for the Eudora import library
class nsTextImportModule : public nsIModule
{
public:
nsTextImportModule();
virtual ~nsTextImportModule();
NS_DECL_ISUPPORTS
NS_DECL_NSIMODULE
protected:
nsresult Initialize();
void Shutdown();
PRBool mInitialized;
nsCOMPtr<nsIGenericFactory> mFactory;
};
//----------------------------------------------------------------------
// Functions used to create new instances of a given object by the
// generic factory.
#define MAKE_CTOR(_iface, _name) \
static NS_IMETHODIMP \
CreateNew##_name(nsISupports* aOuter, REFNSIID aIID, void **aResult) \
{ \
if (!aResult) { \
return NS_ERROR_INVALID_POINTER; \
} \
if (aOuter) { \
*aResult = nsnull; \
return NS_ERROR_NO_AGGREGATION; \
} \
nsI##_iface* inst; \
nsresult rv = NS_New##_name(&inst); \
if (NS_FAILED(rv)) { \
*aResult = nsnull; \
return rv; \
} \
rv = inst->QueryInterface(aIID, aResult); \
if (NS_FAILED(rv)) { \
*aResult = nsnull; \
} \
NS_RELEASE(inst); /* get rid of extra refcnt */ \
return rv; \
}
MAKE_CTOR(ImportModule, TextImport)
//----------------------------------------------------------------------
static NS_DEFINE_IID(kIModuleIID, NS_IMODULE_IID);
nsTextImportModule::nsTextImportModule()
: mInitialized(PR_FALSE)
{
NS_INIT_ISUPPORTS();
}
nsTextImportModule::~nsTextImportModule()
{
Shutdown();
}
NS_IMPL_ISUPPORTS(nsTextImportModule, kIModuleIID)
// Perform our one-time intialization for this module
nsresult nsTextImportModule::Initialize()
{
if (mInitialized) {
return NS_OK;
}
mInitialized = PR_TRUE;
return NS_OK;
}
// Shutdown this module, releasing all of the module resources
void nsTextImportModule::Shutdown()
{
// Release the factory object
mFactory = nsnull;
}
// Create a factory object for creating instances of aClass.
NS_IMETHODIMP nsTextImportModule::GetClassObject(nsIComponentManager *aCompMgr,
const nsCID& aClass,
const nsIID& aIID,
void** r_classObj)
{
nsresult rv;
// Defensive programming: Initialize *r_classObj in case of error below
if (!r_classObj) {
return NS_ERROR_INVALID_POINTER;
}
*r_classObj = NULL;
// Do one-time-only initialization if necessary
if (!mInitialized) {
rv = Initialize();
if (NS_FAILED(rv)) {
// Initialization failed! yikes!
return rv;
}
}
// Choose the appropriate factory, based on the desired instance
// class type (aClass).
nsCOMPtr<nsIGenericFactory> fact;
if (aClass.Equals(kTextImportCID)) {
if (!mFactory) {
// Create and save away the factory object for creating
// new instances of Sample. This way if we are called
// again for the factory, we won't need to create a new
// one.
rv = NS_NewGenericFactory(getter_AddRefs(mFactory),
CreateNewTextImport);
}
fact = mFactory;
}
else {
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
#ifdef DEBUG
char* cs = aClass.ToString();
printf("+++ nsTextImportModule: unable to create factory for %s\n", cs);
nsCRT::free(cs);
#endif
}
if (fact) {
rv = fact->QueryInterface(aIID, r_classObj);
}
return rv;
}
//----------------------------------------
struct Components {
const char* mDescription;
const nsID* mCID;
const char* mProgID;
};
// The list of components we register
static Components gComponents[] = {
{ "Text Import Component", &kTextImportCID,
"component://mozilla/import/import-text", },
};
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
nsresult GetImportModulesRegKey( nsIRegistry *reg, nsRegistryKey *pKey)
{
nsRegistryKey nScapeKey;
nsresult rv = reg->GetSubtree( nsIRegistry::Common, "Netscape", &nScapeKey);
if (NS_FAILED(rv)) {
rv = reg->AddSubtree( nsIRegistry::Common, "Netscape", &nScapeKey);
}
if (NS_FAILED( rv))
return( rv);
nsRegistryKey iKey;
rv = reg->GetSubtree( nScapeKey, "Import", &iKey);
if (NS_FAILED( rv)) {
rv = reg->AddSubtree( nScapeKey, "Import", &iKey);
}
if (NS_FAILED( rv))
return( rv);
rv = reg->GetSubtree( iKey, "Modules", pKey);
if (NS_FAILED( rv)) {
rv = reg->AddSubtree( iKey, "Modules", pKey);
}
return( rv);
}
NS_IMETHODIMP nsTextImportModule::RegisterSelf(nsIComponentManager *aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation,
const char* componentType)
{
nsresult rv = NS_OK;
#ifdef DEBUG
printf("*** Registering Text import components\n");
#endif
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription,
cp->mProgID, aPath, PR_TRUE,
PR_TRUE);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsTextImportModule: unable to register %s component => %x\n",
cp->mDescription, rv);
#endif
break;
}
cp++;
}
{
NS_WITH_SERVICE( nsIRegistry, reg, kRegistryCID, &rv);
if (NS_FAILED(rv)) {
IMPORT_LOG0( "*** Import Text, ERROR GETTING THE Registry\n");
return rv;
}
rv = reg->OpenDefault();
if (NS_FAILED(rv)) {
IMPORT_LOG0( "*** Import Text, ERROR OPENING THE REGISTRY\n");
return( rv);
}
nsRegistryKey importKey;
rv = GetImportModulesRegKey( reg, &importKey);
if (NS_FAILED( rv)) {
IMPORT_LOG0( "*** Import Text, ERROR getting Netscape/Import registry key\n");
return( rv);
}
nsRegistryKey key;
rv = reg->AddSubtree( importKey, "Text", &key);
if (NS_FAILED(rv)) return( rv);
rv = reg->SetString( key, "Supports", kTextSupportsString);
if (NS_FAILED(rv)) return( rv);
char *myCID = kTextImportCID.ToString();
rv = reg->SetString( key, "CLSID", myCID);
delete [] myCID;
if (NS_FAILED(rv)) return( rv);
}
return rv;
}
NS_IMETHODIMP
nsTextImportModule::UnregisterSelf(nsIComponentManager* aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation)
{
#ifdef DEBUG
printf("*** Unregistering Text import components\n");
#endif
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsTextImportModule: unable to unregister %s component => %x\n",
cp->mDescription, rv);
#endif
}
cp++;
}
return NS_OK;
}
NS_IMETHODIMP
nsTextImportModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
{
if (!okToUnload) {
return NS_ERROR_INVALID_POINTER;
}
*okToUnload = PR_FALSE;
return NS_ERROR_FAILURE;
}
//----------------------------------------------------------------------
static nsTextImportModule *gModule = nsnull;
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
nsIFileSpec* location,
nsIModule** return_cobj)
{
nsresult rv = NS_OK;
NS_ASSERTION(return_cobj, "Null argument");
NS_ASSERTION(gModule == nsnull, "nsTextImportModule: Module already created.");
// Create an initialize the layout module instance
nsTextImportModule *m = new nsTextImportModule();
if (!m) {
return NS_ERROR_OUT_OF_MEMORY;
}
// Increase refcnt and store away nsIModule interface to m in return_cobj
rv = m->QueryInterface(nsIModule::GetIID(), (void**)return_cobj);
if (NS_FAILED(rv)) {
delete m;
m = nsnull;
}
gModule = m; // WARNING: Weak Reference
return rv;
}

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

@ -0,0 +1,535 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
Text import addressbook interfaces
*/
#include "nscore.h"
#include "nsCRT.h"
#include "nsString.h"
#include "nsIServiceManager.h"
#include "nsIImportService.h"
#include "nsComponentManagerUtils.h"
#include "nsTextImport.h"
#include "nsIAllocator.h"
#include "nsIImportGeneric.h"
#include "nsIImportAddressBooks.h"
#include "nsIImportABDescriptor.h"
#include "nsIImportFieldMap.h"
#include "nsIOutputStream.h"
#include "nsIAddrDatabase.h"
#include "nsTextFormater.h"
#include "nsTextStringBundle.h"
#include "nsTextAddress.h"
#include "TextDebugLog.h"
static NS_DEFINE_CID(kImportServiceCID, NS_IMPORTSERVICE_CID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kISupportsArrayIID, NS_ISUPPORTSARRAY_IID);
class ImportAddressImpl : public nsIImportAddressBooks
{
public:
ImportAddressImpl();
virtual ~ImportAddressImpl();
static nsresult Create(nsIImportAddressBooks** aImport);
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIImportAddressBooks interface
/* PRBool GetSupportsMultiple (); */
NS_IMETHOD GetSupportsMultiple(PRBool *_retval) { *_retval = PR_FALSE; return( NS_OK);}
/* PRBool GetAutoFind (out wstring description); */
NS_IMETHOD GetAutoFind(PRUnichar **description, PRBool *_retval);
/* PRBool GetNeedsFieldMap (nsIFileSpec *location); */
NS_IMETHOD GetNeedsFieldMap(nsIFileSpec *location, PRBool *_retval);
/* void GetDefaultLocation (out nsIFileSpec location, out boolean found, out boolean userVerify); */
NS_IMETHOD GetDefaultLocation(nsIFileSpec **location, PRBool *found, PRBool *userVerify);
/* nsISupportsArray FindAddressBooks (in nsIFileSpec location); */
NS_IMETHOD FindAddressBooks(nsIFileSpec *location, nsISupportsArray **_retval);
/* nsISupports InitFieldMap(nsIFileSpec location, nsIImportFieldMap fieldMap); */
NS_IMETHOD InitFieldMap(nsIFileSpec *location, nsIImportFieldMap *fieldMap)
{ return( NS_OK); }
/* void ImportAddressBook (in nsIImportABDescriptor source, in nsISupports destination, in nsISupports fieldMap, out boolean fatalError); */
NS_IMETHOD ImportAddressBook( nsIImportABDescriptor *source,
nsIAddrDatabase * destination,
nsIImportFieldMap * fieldMap,
PRUnichar ** errorLog,
PRUnichar ** successLog,
PRBool * fatalError);
/* unsigned long GetImportProgress (); */
NS_IMETHOD GetImportProgress(PRUint32 *_retval);
private:
static void ReportSuccess( nsString& name, nsString *pStream);
static void SetLogs( nsString& success, nsString& error, PRUnichar **pError, PRUnichar **pSuccess);
static void ReportError( PRInt32 errorNum, nsString& name, nsString *pStream);
private:
nsTextAddress m_text;
};
////////////////////////////////////////////////////////////////////////
nsresult NS_NewTextImport(nsIImportModule** aImport)
{
NS_PRECONDITION(aImport != nsnull, "null ptr");
if (! aImport)
return NS_ERROR_NULL_POINTER;
*aImport = new nsTextImport();
if (! *aImport)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*aImport);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
nsTextImport::nsTextImport()
{
NS_INIT_REFCNT();
IMPORT_LOG0( "nsTextImport Module Created\n");
}
nsTextImport::~nsTextImport()
{
IMPORT_LOG0( "nsTextImport Module Deleted\n");
}
NS_IMPL_ISUPPORTS(nsTextImport, nsIImportModule::GetIID());
NS_IMETHODIMP nsTextImport::GetName( PRUnichar **name)
{
NS_PRECONDITION(name != nsnull, "null ptr");
if (! name)
return NS_ERROR_NULL_POINTER;
*name = nsTextStringBundle::GetStringByID( TEXTIMPORT_NAME);
return NS_OK;
}
NS_IMETHODIMP nsTextImport::GetDescription( PRUnichar **name)
{
NS_PRECONDITION(name != nsnull, "null ptr");
if (! name)
return NS_ERROR_NULL_POINTER;
*name = nsTextStringBundle::GetStringByID( TEXTIMPORT_DESCRIPTION);
return NS_OK;
}
NS_IMETHODIMP nsTextImport::GetSupports( char **supports)
{
NS_PRECONDITION(supports != nsnull, "null ptr");
if (! supports)
return NS_ERROR_NULL_POINTER;
*supports = nsCRT::strdup( kTextSupportsString);
return( NS_OK);
}
NS_IMETHODIMP nsTextImport::GetSupportsUpgrade( PRBool *pUpgrade)
{
NS_PRECONDITION(pUpgrade != nsnull, "null ptr");
if (! pUpgrade)
return NS_ERROR_NULL_POINTER;
*pUpgrade = PR_FALSE;
return( NS_OK);
}
NS_IMETHODIMP nsTextImport::GetImportInterface( const char *pImportType, nsISupports **ppInterface)
{
NS_PRECONDITION(pImportType != nsnull, "null ptr");
if (! pImportType)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(ppInterface != nsnull, "null ptr");
if (! ppInterface)
return NS_ERROR_NULL_POINTER;
*ppInterface = nsnull;
nsresult rv;
if (!nsCRT::strcmp( pImportType, "addressbook")) {
// create the nsIImportMail interface and return it!
nsIImportAddressBooks * pAddress = nsnull;
nsIImportGeneric * pGeneric = nsnull;
rv = ImportAddressImpl::Create( &pAddress);
if (NS_SUCCEEDED( rv)) {
NS_WITH_SERVICE( nsIImportService, impSvc, kImportServiceCID, &rv);
if (NS_SUCCEEDED( rv)) {
rv = impSvc->CreateNewGenericAddressBooks( &pGeneric);
if (NS_SUCCEEDED( rv)) {
pGeneric->SetData( "addressInterface", pAddress);
rv = pGeneric->QueryInterface( kISupportsIID, (void **)ppInterface);
}
}
}
NS_IF_RELEASE( pAddress);
NS_IF_RELEASE( pGeneric);
return( rv);
}
return( NS_ERROR_NOT_AVAILABLE);
}
/////////////////////////////////////////////////////////////////////////////////
nsresult ImportAddressImpl::Create(nsIImportAddressBooks** aImport)
{
NS_PRECONDITION(aImport != nsnull, "null ptr");
if (! aImport)
return NS_ERROR_NULL_POINTER;
*aImport = new ImportAddressImpl();
if (! *aImport)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*aImport);
return NS_OK;
}
ImportAddressImpl::ImportAddressImpl()
{
NS_INIT_REFCNT();
}
ImportAddressImpl::~ImportAddressImpl()
{
}
NS_IMPL_ISUPPORTS(ImportAddressImpl, nsIImportAddressBooks::GetIID());
NS_IMETHODIMP ImportAddressImpl::GetAutoFind(PRUnichar **description, PRBool *_retval)
{
NS_PRECONDITION(description != nsnull, "null ptr");
NS_PRECONDITION(_retval != nsnull, "null ptr");
if (! description || !_retval)
return NS_ERROR_NULL_POINTER;
nsString str;
*_retval = PR_FALSE;
nsTextStringBundle::GetStringByID( TEXTIMPORT_ADDRESS_NAME, str);
*description = str.ToNewUnicode();
return( NS_OK);
}
NS_IMETHODIMP ImportAddressImpl::GetDefaultLocation(nsIFileSpec **ppLoc, PRBool *found, PRBool *userVerify)
{
NS_PRECONDITION(found != nsnull, "null ptr");
NS_PRECONDITION(ppLoc != nsnull, "null ptr");
NS_PRECONDITION(userVerify != nsnull, "null ptr");
if (! found || !userVerify || !ppLoc)
return NS_ERROR_NULL_POINTER;
*ppLoc = nsnull;
*found = PR_FALSE;
*userVerify = PR_TRUE;
return( NS_OK);
}
NS_IMETHODIMP ImportAddressImpl::FindAddressBooks(nsIFileSpec *pLoc, nsISupportsArray **ppArray)
{
NS_PRECONDITION(pLoc != nsnull, "null ptr");
NS_PRECONDITION(ppArray != nsnull, "null ptr");
if (!pLoc || !ppArray)
return NS_ERROR_NULL_POINTER;
*ppArray = nsnull;
PRBool exists = PR_FALSE;
nsresult rv = pLoc->Exists( &exists);
if (NS_FAILED( rv) || !exists)
return( NS_ERROR_FAILURE);
PRBool isFile = PR_FALSE;
rv = pLoc->IsFile( &isFile);
if (NS_FAILED( rv) || !isFile)
return( NS_ERROR_FAILURE);
rv = m_text.DetermineDelim( pLoc);
if (NS_FAILED( rv)) {
IMPORT_LOG0( "*** Error determining delimitter\n");
return( rv);
}
/* Build an address book descriptor based on the file passed in! */
nsCOMPtr<nsISupportsArray> array;
rv = NS_NewISupportsArray( getter_AddRefs( array));
if (NS_FAILED( rv)) {
IMPORT_LOG0( "FAILED to allocate the nsISupportsArray\n");
return( rv);
}
NS_WITH_SERVICE( nsIImportService, impSvc, kImportServiceCID, &rv);
if (NS_FAILED( rv)) {
IMPORT_LOG0( "*** Failed to obtain the import service\n");
return( rv);
}
char *pName = nsnull;
rv = pLoc->GetLeafName( &pName);
if (NS_FAILED( rv)) {
IMPORT_LOG0( "*** Failed getting leaf name of file\n");
return( rv);
}
nsString name = pName;
PRInt32 idx = name.RFindChar( '.');
if ((idx != -1) && (idx > 0) && ((name.Length() - idx - 1) < 5)) {
nsString t;
name.Left( t, idx);
name = t;
}
nsCOMPtr<nsIImportABDescriptor> desc;
nsISupports * pInterface;
rv = impSvc->CreateNewABDescriptor( getter_AddRefs( desc));
if (NS_SUCCEEDED( rv)) {
PRUint32 sz = 0;
pLoc->GetFileSize( &sz);
desc->SetPreferredName( name.GetUnicode());
desc->SetSize( sz);
nsIFileSpec *pSpec = nsnull;
desc->GetFileSpec( &pSpec);
if (pSpec) {
pSpec->FromFileSpec( pLoc);
NS_RELEASE( pSpec);
}
rv = desc->QueryInterface( kISupportsIID, (void **) &pInterface);
array->AppendElement( pInterface);
pInterface->Release();
}
if (NS_FAILED( rv)) {
IMPORT_LOG0( "*** Error creating address book descriptor for text import\n");
}
else {
rv = array->QueryInterface( kISupportsArrayIID, (void **) ppArray);
}
return( rv);
}
void ImportAddressImpl::ReportSuccess( nsString& name, nsString *pStream)
{
if (!pStream)
return;
// load the success string
PRUnichar *pText = nsTextStringBundle::GetStringByID( TEXTIMPORT_ADDRESS_SUCCESS);
pStream->Append( pText);
nsTextStringBundle::FreeString( pText);
pStream->Append( NS_LINEBREAK);
}
void ImportAddressImpl::ReportError( PRInt32 errorNum, nsString& name, nsString *pStream)
{
if (!pStream)
return;
// load the error string
PRUnichar *pFmt = nsTextStringBundle::GetStringByID( errorNum);
PRUnichar *pText = nsTextFormater::smprintf( pFmt, name.GetUnicode());
pStream->Append( pText);
nsTextFormater::smprintf_free( pText);
nsTextStringBundle::FreeString( pFmt);
pStream->Append( NS_LINEBREAK);
}
void ImportAddressImpl::SetLogs( nsString& success, nsString& error, PRUnichar **pError, PRUnichar **pSuccess)
{
if (pError)
*pError = error.ToNewUnicode();
if (pSuccess)
*pSuccess = success.ToNewUnicode();
}
NS_IMETHODIMP ImportAddressImpl::ImportAddressBook( nsIImportABDescriptor *pSource,
nsIAddrDatabase * pDestination,
nsIImportFieldMap * fieldMap,
PRUnichar ** pErrorLog,
PRUnichar ** pSuccessLog,
PRBool * fatalError)
{
NS_PRECONDITION(pSource != nsnull, "null ptr");
NS_PRECONDITION(pDestination != nsnull, "null ptr");
NS_PRECONDITION(fatalError != nsnull, "null ptr");
nsString success;
nsString error;
if (!pSource || !pDestination || !fatalError) {
IMPORT_LOG0( "*** Bad param passed to text address import\n");
nsTextStringBundle::GetStringByID( TEXTIMPORT_ADDRESS_BADPARAM, error);
if (fatalError)
*fatalError = PR_TRUE;
SetLogs( success, error, pErrorLog, pSuccessLog);
return( NS_ERROR_NULL_POINTER);
}
PRBool abort = PR_FALSE;
nsString name;
PRUnichar * pName;
if (NS_SUCCEEDED( pSource->GetPreferredName( &pName))) {
name = pName;
nsCRT::free( pName);
}
PRUint32 addressSize = 0;
pSource->GetSize( &addressSize);
if (addressSize == 0) {
IMPORT_LOG0( "Address book size is 0, skipping import.\n");
ReportSuccess( name, &success);
SetLogs( success, error, pErrorLog, pSuccessLog);
return( NS_OK);
}
nsIFileSpec * inFile;
if (NS_FAILED( pSource->GetFileSpec( &inFile))) {
ReportError( TEXTIMPORT_ADDRESS_BADSOURCEFILE, name, &error);
SetLogs( success, error, pErrorLog, pSuccessLog);
return( NS_ERROR_FAILURE);
}
#ifdef IMPORT_DEBUG
char *pPath;
inFile->GetNativePath( &pPath);
IMPORT_LOG1( "Import address book: %s\n", pPath);
nsCRT::free( pPath);
#endif
nsresult rv = NS_OK;
PRBool isLDIF = PR_FALSE;
rv = nsTextAddress::IsLDIFFile( inFile, &isLDIF);
if (NS_FAILED( rv)) {
inFile->Release();
ReportError( TEXTIMPORT_ADDRESS_CONVERTERROR, name, &error);
SetLogs( success, error, pErrorLog, pSuccessLog);
return( rv);
}
if (isLDIF) {
// This get's tricky, the database really requires the thing
// to have an .ldi extension so if it doesn't we may need to
// copy the file to a temp file with the correct name, then
// import it!
rv = m_text.ImportLDIF( &abort, name.GetUnicode(), inFile, pDestination, error);
}
else {
rv = m_text.ImportAddresses( &abort, name.GetUnicode(), inFile, pDestination, fieldMap, error);
}
inFile->Release();
if (NS_SUCCEEDED( rv) && error.IsEmpty()) {
ReportSuccess( name, &success);
}
else {
ReportError( TEXTIMPORT_ADDRESS_CONVERTERROR, name, &error);
}
SetLogs( success, error, pErrorLog, pSuccessLog);
IMPORT_LOG0( "*** Text address import done\n");
return( rv);
}
NS_IMETHODIMP ImportAddressImpl::GetImportProgress(PRUint32 *_retval)
{
return( NS_OK);
}
NS_IMETHODIMP ImportAddressImpl::GetNeedsFieldMap(nsIFileSpec *location, PRBool *_retval)
{
NS_PRECONDITION(_retval != nsnull, "null ptr");
NS_PRECONDITION(location != nsnull, "null ptr");
if (!location || !_retval)
return( NS_ERROR_NULL_POINTER);
*_retval = PR_TRUE;
PRBool exists = PR_FALSE;
PRBool isFile = PR_FALSE;
nsresult rv = location->Exists( &exists);
rv = location->IsFile( &isFile);
if (!exists || !isFile)
return( NS_ERROR_FAILURE);
PRBool isLDIF = PR_FALSE;
rv = nsTextAddress::IsLDIFFile( location, &isLDIF);
if (NS_FAILED( rv)) {
IMPORT_LOG0( "*** Error determining if file is of type LDIF\n");
return( rv);
}
if (isLDIF)
*_retval = PR_FALSE;
return( NS_OK);
}

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

@ -0,0 +1,57 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsTextImport_h___
#define nsTextImport_h___
#include "nsIImportModule.h"
#include "nsCOMPtr.h"
#define NS_TEXTIMPORT_CID \
{ /* A5991D01-ADA7-11d3-A9C2-00A0CC26DA63 */ \
0xa5991d01, 0xada7, 0x11d3, \
{0xa9, 0xc2, 0x0, 0xa0, 0xcc, 0x26, 0xda, 0x63 }}
#define kTextSupportsString NS_IMPORT_ADDRESS_STR
class nsTextImport : public nsIImportModule
{
public:
nsTextImport();
virtual ~nsTextImport();
NS_DECL_ISUPPORTS
////////////////////////////////////////////////////////////////////////////////////////
// we suppport the nsIImportModule interface
////////////////////////////////////////////////////////////////////////////////////////
NS_DECL_NSIIMPORTMODULE
protected:
};
extern nsresult NS_NewTextImport(nsIImportModule** aImport);
#endif /* nsTextImport_h___ */

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

@ -0,0 +1,82 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "prprf.h"
#include "prmem.h"
#include "nsCOMPtr.h"
#include "nsIStringBundle.h"
#include "nsTextStringBundle.h"
#include "nsIServiceManager.h"
#include "nsIURI.h"
/* This is the next generation string retrieval call */
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
#define TEXT_MSGS_URL "chrome://messenger/locale/textImportMsgs.properties"
nsIStringBundle *nsTextStringBundle::GetStringBundle( void)
{
nsresult rv;
char* propertyURL = TEXT_MSGS_URL;
nsIStringBundle* sBundle = nsnull;
NS_WITH_SERVICE(nsIStringBundleService, sBundleService, kStringBundleServiceCID, &rv);
if (NS_SUCCEEDED(rv) && (nsnull != sBundleService)) {
nsILocale * locale = nsnull;
rv = sBundleService->CreateBundle(propertyURL, locale, &sBundle);
}
return( sBundle);
}
void nsTextStringBundle::GetStringByID( PRInt32 stringID, nsString& result, nsIStringBundle *pBundle)
{
PRUnichar *ptrv = GetStringByID( stringID, pBundle);
result = ptrv;
FreeString( ptrv);
}
PRUnichar *nsTextStringBundle::GetStringByID(PRInt32 stringID, nsIStringBundle *pBundle)
{
PRBool mine = PR_FALSE;
if (!pBundle) {
mine = PR_TRUE;
pBundle = GetStringBundle();
}
if (pBundle) {
PRUnichar *ptrv = nsnull;
nsresult rv = pBundle->GetStringFromID(stringID, &ptrv);
if (mine) {
NS_RELEASE(pBundle);
}
if (NS_SUCCEEDED( rv) && ptrv)
return( ptrv);
}
nsString resultString( "[StringID ");
resultString.Append(stringID, 10);
resultString += "?]";
return( resultString.ToNewUnicode());
}

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

@ -0,0 +1,47 @@
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsTextStringBundle_H__
#define nsTextStringBundle_H__
#include "nsCRT.h"
#include "nsString.h"
class nsIStringBundle;
class nsTextStringBundle {
public:
static PRUnichar * GetStringByID(PRInt32 stringID, nsIStringBundle *pBundle = nsnull);
static void GetStringByID(PRInt32 stringID, nsString& result, nsIStringBundle *pBundle = nsnull);
// GetStringBundle creates a new one every time!
static nsIStringBundle * GetStringBundle( void);
static void FreeString( PRUnichar *pStr) { nsCRT::free( pStr);}
};
#define TEXTIMPORT_NAME 2000
#define TEXTIMPORT_DESCRIPTION 2001
#define TEXTIMPORT_ADDRESS_NAME 2002
#define TEXTIMPORT_ADDRESS_SUCCESS 2003
#define TEXTIMPORT_ADDRESS_BADPARAM 2004
#define TEXTIMPORT_ADDRESS_BADSOURCEFILE 2005
#define TEXTIMPORT_ADDRESS_CONVERTERROR 2006
#endif /* nsTextStringBundle_H__ */

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

@ -78,10 +78,213 @@
## @loc None ## @loc None
2010=Unable to create an account to import mail into 2010=Unable to create an account to import mail into
# Description: Address book field name
## @name IMPORT_FIELD_DESC_START
## @loc None
2100=First Name
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2101=Last Name
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2102=Display Name
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2103=Nickname
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2104=Primary Email
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2105=Secondary Email
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2106=Work Phone
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2107=Home Phone
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2108=Fax Number
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2109=Pager Number
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2110=Cellular Number
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2111=Home Address
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2112=Home Address 2
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2113=Home City
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2114=Home State
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2115=Home ZipCode
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2116=Home Country
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2117=Work Address
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2118=Work Address 2
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2119=Work City
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2120=Work State
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2121=Work ZipCode
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2122=Work Country
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2123=Job Title
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2124=Department
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2125=Company
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2126=Web Page 1
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2127=Web Page 2
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2128=Birth Year
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2129=Birth Month
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2130=Birth Day
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2131=Custom 1
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2132=Custom 2
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2133=Custom 3
# Description: Address book field name
## @name IMPORT_FIELD_DESC
## @loc None
2134=Custom 4
# Description: Address book field name
## @name IMPORT_FIELD_DESC_END
## @loc None
2135=Notes
# Description: Strings for the import dialog
ImportMailDialogTitle=Import Mail
ImportAddressBooksDialogTitle=Import Address Books
ImportSettingsDialogTitle=Import Settings
ImportMailListLabel=Select application to import mail from:
ImportAddressBooksListLabel=Select address book format:
ImportSettingsListLabel=Select application to import settings from:
#Error strings
ImportAlreadyInProgress=An import operation is currently in progress, try again when the current import has finished.
#Error strings for settings import
ImportSettingsBadModule=Unable to load settings module
ImportSettingsNotFound=Unable to find settings. Check to make sure the application is installed on this machine.
ImportSettingsFailed=An error occurred while importing settings. Some, or all, of the settings may not have been imported.
ImportSettingsSuccess=Settings were imported from
#Error string for mail import
ImportMailBadModule=Unable to load mail import module
ImportMailNotFound=Unable to find mail to import. Check to make sure the mail application is correctly installed on this machine.
ImportMailFailed=An error occurred importing mail from
ImportMailSuccess=Mail was successfully imported from
#Error string for address import
ImportAddressBadModule=Unable to load address book import module
ImportAddressNotFound=Unable to find any address books to import. Check to make sure the selected application or format is correctly installed on this machine.
ImportAddressFailed=An error occurred importing addresses from
ImportAddressSuccess=Addresses were successfully imported from

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

@ -0,0 +1,58 @@
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
#
# The following are used by the outlook express import code to display status/error
# and informational messages
#
# Short name of import module
## @name TEXTIMPORT_NAME
## @loc None
2000=Text
# Description of import module
## @name TEXTIMPORT_DESCRIPTION
## @loc None
2001=Address books in text format, comma or tab delimitted
# Description of import module
## @name TEXTIMPORT_ADDRESS_NAME
## @loc None
2002=Text Address Book
# Description
## @name TEXTIMPORT_ADDRESS_SUCCESS
## @loc None
2003=Imported address book %S
# Error message
## @name TEXTIMPORT_ADDRESS_BADPARAM
## @loc None
2004=Bad parameter passed to import address book.
# Error message
## @name TEXTIMPORT_ADDRESS_BADSOURCEFILE
## @loc None
2005=Error accessing file for address book %S.
# Error message
## @name TEXTIMPORT_ADDRESS_CONVERTERROR
## @loc None
2006=Error importing address book %S, all addresses may not have been imported.