Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
nsEudoraMac Class Reference

#include <nsEudoraMac.h>

Inheritance diagram for nsEudoraMac:
Inheritance graph
[legend]
Collaboration diagram for nsEudoraMac:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsEudoraMac ()
 ~nsEudoraMac ()
virtual PRBool FindMailFolder (nsIFileSpec *pFolder)
virtual nsresult FindMailboxes (nsIFileSpec *pRoot, nsISupportsArray **ppArray)
virtual nsresult FindTOCFile (nsIFileSpec *pMailFile, nsIFileSpec **pTOCFile, PRBool *pDeleteToc)
virtual nsresult GetAttachmentInfo (const char *pFileName, nsIFileSpec *pSpec, nsCString &mimeType, nsCString &aAttachment)
virtual PRBool FindAddressFolder (nsIFileSpec *pFolder)
virtual nsresult FindAddressBooks (nsIFileSpec *pRoot, nsISupportsArray **ppArray)
nsresult ImportMailbox (PRUint32 *pBytes, PRBool *pAbort, const PRUnichar *pName, nsIFileSpec *pSrc, nsIFileSpec *pDst, PRInt32 *pMsgCount)
nsresult ImportAddresses (PRUint32 *pBytes, PRBool *pAbort, const PRUnichar *pName, nsIFileSpec *pSrc, nsIAddrDatabase *pDb, nsString &errors)

Static Public Member Functions

static PRBool ImportSettings (nsIFileSpec *pIniFile, nsIMsgAccount **localMailAccount)
static PRBool FindSettingsFile (nsIFileSpec *pIniFile)
static PRInt32 IsEudoraFromSeparator (const char *pData, PRInt32 maxLen, nsCString &defaultDate)
static PRBool IsEudoraTag (const char *pChar, PRInt32 maxLen, PRBool &insideEudoraTags, nsCString &bodyType, PRInt32 &tagLength)
static PRInt32 CountQuote (const char *pLine, PRInt32 len)
static PRInt32 CountComment (const char *pLine, PRInt32 len)
static PRInt32 CountAngle (const char *pLine, PRInt32 len)

Protected Member Functions

nsresult CreateTempFile (nsIFileSpec **ppSpec)
nsresult DeleteFile (nsIFileSpec *pSpec)

Private Member Functions

nsresult ScanMailDir (nsIFileSpec *pFolder, nsISupportsArray *pArray, nsIImportService *pImport)
nsresult IterateMailDir (nsIFileSpec *pFolder, nsISupportsArray *pArray, nsIImportService *pImport)
nsresult FoundMailFolder (nsIFileSpec *mailFolder, const char *pName, nsISupportsArray *pArray, nsIImportService *pImport)
nsresult FoundMailbox (nsIFileSpec *mailFile, const char *pName, nsISupportsArray *pArray, nsIImportService *pImport)
PRBool IsValidMailFolderName (nsCString &name)
PRBool IsValidMailboxName (nsCString &fName)
PRBool IsValidMailboxFile (nsIFileSpec *pFile)
PRBool CreateTocFromResource (nsIFileSpec *pMail, nsIFileSpec *pToc)
PRBool HasResourceFork (FSSpec *fsSpec)

Static Private Member Functions

static PRBool FindEudoraLocation (nsIFileSpec *pFolder, PRBool findIni=PR_FALSE, nsIFileSpec *pLookIn=nsnull)
static PRBool BuildPOPAccount (nsIMsgAccountManager *accMgr, nsCString **pStrs, nsIMsgAccount **ppAccount, nsString &accName)
static PRBool BuildIMAPAccount (nsIMsgAccountManager *accMgr, nsCString **pStrs, nsIMsgAccount **ppAccount, nsString &accName)
static void SetIdentities (nsIMsgAccountManager *accMgr, nsIMsgAccount *acc, const char *userName, const char *serverName, nsCString **pStrs)
static void SetSmtpServer (nsIMsgAccountManager *pMgr, nsIMsgAccount *pAcc, const char *pServer, const char *pUser)
static PRBool GetSettingsFromResource (nsIFileSpec *pSettings, short resId, nsCString **pStrs, PRBool *pIMAP)

Private Attributes

PRUint32 m_depth
nsIFileSpecm_mailImportLocation

Detailed Description

Definition at line 54 of file nsEudoraMac.h.


Constructor & Destructor Documentation

Definition at line 92 of file nsEudoraMac.cpp.

Definition at line 97 of file nsEudoraMac.cpp.


Member Function Documentation

PRBool nsEudoraMac::BuildIMAPAccount ( nsIMsgAccountManager accMgr,
nsCString **  pStrs,
nsIMsgAccount **  ppAccount,
nsString accName 
) [static, private]

Definition at line 847 of file nsEudoraMac.cpp.

{      

       if (!pStrs[kPopServerStr]->Length() || !pStrs[kPopAccountNameStr]->Length())
              return( PR_FALSE);

       PRBool result = PR_FALSE;

       nsCOMPtr<nsIMsgIncomingServer>     in;
       nsresult rv = accMgr->FindServer( pStrs[kPopAccountNameStr]->get(), pStrs[kPopServerStr]->get(), "imap", getter_AddRefs( in));
       if (NS_FAILED( rv) || (in == nsnull)) {
              // Create the incoming server and an account for it?
              rv = accMgr->CreateIncomingServer( pStrs[kPopAccountNameStr]->get(), pStrs[kPopServerStr]->get(), "imap", getter_AddRefs( in));
              if (NS_SUCCEEDED( rv) && in) {
                     rv = in->SetType( "imap");
                     // rv = in->SetHostName( pStrs[kPopServerStr]->get());
                     // rv = in->SetUsername( pStrs[kPopAccountNameStr]->get());
                     
                     IMPORT_LOG2( "Created IMAP server named: %s, userName: %s\n", pStrs[kPopServerStr]->get(), pStrs[kPopAccountNameStr]->get());
                     
                     PRUnichar *pretty = ToNewUnicode(accName);
                     
                     IMPORT_LOG1( "\tSet pretty name to: %S\n", pretty);

                     rv = in->SetPrettyName( pretty);
                     nsCRT::free( pretty);
                     
                     // We have a server, create an account.
                     nsCOMPtr<nsIMsgAccount>     account;
                     rv = accMgr->CreateAccount( getter_AddRefs( account));
                     if (NS_SUCCEEDED( rv) && account) {
                            rv = account->SetIncomingServer( in);     
                            
                            IMPORT_LOG0( "Created an account and set the IMAP server as the incoming server\n");

                            // Fiddle with the identities
                            SetIdentities(accMgr, account, pStrs[kPopAccountNameStr]->get(), pStrs[kPopServerStr]->get(), pStrs);
                            result = PR_TRUE;
                            if (ppAccount)
                                   account->QueryInterface( NS_GET_IID(nsIMsgAccount), (void **)ppAccount);
                     }                           
              }
       }
       else
              result = PR_TRUE;

       return( result);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsEudoraMac::BuildPOPAccount ( nsIMsgAccountManager accMgr,
nsCString **  pStrs,
nsIMsgAccount **  ppAccount,
nsString accName 
) [static, private]

Definition at line 791 of file nsEudoraMac.cpp.

{
       if (ppAccount)
              *ppAccount = nsnull;
       
              
       if (!pStrs[kPopServerStr]->Length() || !pStrs[kPopAccountNameStr]->Length())
              return( PR_FALSE);

       PRBool result = PR_FALSE;

       // I now have a user name/server name pair, find out if it already exists?
       nsCOMPtr<nsIMsgIncomingServer>     in;
       nsresult rv = accMgr->FindServer( pStrs[kPopAccountNameStr]->get(), pStrs[kPopServerStr]->get(), "pop3", getter_AddRefs( in));
       if (NS_FAILED( rv) || (in == nsnull)) {
              // Create the incoming server and an account for it?
              rv = accMgr->CreateIncomingServer( pStrs[kPopAccountNameStr]->get(), pStrs[kPopServerStr]->get(), "pop3", getter_AddRefs( in));
              if (NS_SUCCEEDED( rv) && in) {
                     rv = in->SetType( "pop3");
                     // rv = in->SetHostName( pStrs[kPopServerStr]->get());
                     // rv = in->SetUsername( pStrs[kPopAccountNameStr]->get());

                     IMPORT_LOG2( "Created POP3 server named: %s, userName: %s\n", pStrs[kPopServerStr]->get(), pStrs[kPopAccountNameStr]->get());

                     PRUnichar *pretty = ToNewUnicode(accName);
                     IMPORT_LOG1( "\tSet pretty name to: %S\n", pretty);
                     rv = in->SetPrettyName( pretty);
                     nsCRT::free( pretty);
                     
                     // We have a server, create an account.
                     nsCOMPtr<nsIMsgAccount>     account;
                     rv = accMgr->CreateAccount( getter_AddRefs( account));
                     if (NS_SUCCEEDED( rv) && account) {
                            rv = account->SetIncomingServer( in);
                            
                            IMPORT_LOG0( "Created a new account and set the incoming server to the POP3 server.\n");
                                   
        nsCOMPtr<nsIPop3IncomingServer> pop3Server = do_QueryInterface(in, &rv);
        NS_ENSURE_SUCCESS(rv,rv);
        pop3Server->SetLeaveMessagesOnServer(pStrs[kLeaveOnServerStr]->First() == 'Y' ? PR_TRUE : PR_FALSE);

        // Fiddle with the identities
                            SetIdentities(accMgr, account, pStrs[kPopAccountNameStr]->get(), pStrs[kPopServerStr]->get(), pStrs);
                            result = PR_TRUE;
                            if (ppAccount)
                                   account->QueryInterface( NS_GET_IID(nsIMsgAccount), (void **)ppAccount);
                     }                           
              }
       }
       else
              result = PR_TRUE;
       
       return( result);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRInt32 nsEudoraAddress::CountAngle ( const char *  pLine,
PRInt32  len 
) [static, inherited]

Definition at line 391 of file nsEudoraAddress.cpp.

{
       if (!len)
              return( 0);
              
       PRInt32 cnt = 1;
       pLine++;
       len--;
       
       while (len && (*pLine != '>')) {
              cnt++;
              len--;
              pLine++;
       }
       
       if (len)
              cnt++;
       return( cnt);
}

Here is the caller graph for this function:

PRInt32 nsEudoraAddress::CountComment ( const char *  pLine,
PRInt32  len 
) [static, inherited]

Definition at line 411 of file nsEudoraAddress.cpp.

{
       if (!len)
              return( 0);
       
       PRInt32       cCnt;
       PRInt32 cnt = 1;
       pLine++;
       len--;
       
       while (len && (*pLine != ')')) {
              if (*pLine == '(') {
                     cCnt = CountComment( pLine, len);  
                     cnt += cCnt;
                     pLine += cCnt;
                     len -= cCnt;
              }
              else {
                     cnt++;
                     len--;
                     pLine++;
              }
       }
       
       if (len)
              cnt++;
       return( cnt);
}

Here is the caller graph for this function:

PRInt32 nsEudoraAddress::CountQuote ( const char *  pLine,
PRInt32  len 
) [static, inherited]

Definition at line 370 of file nsEudoraAddress.cpp.

{
       if (!len)
              return( 0);
              
       PRInt32 cnt = 1;
       pLine++;
       len--;
       
       while (len && (*pLine != '"')) {
              cnt++;
              len--;
              pLine++;
       }
       
       if (len)
              cnt++;
       return( cnt);
}

Here is the caller graph for this function:

nsresult nsEudoraMailbox::CreateTempFile ( nsIFileSpec **  ppSpec) [protected, inherited]

Definition at line 119 of file nsEudoraMailbox.cpp.

{
       *ppSpec = nsnull;
       
       nsSpecialSystemDirectory temp(nsSpecialSystemDirectory::OS_TemporaryDirectory);
       
       // nsSpecialSystemDirectory temp(nsSpecialSystemDirectory::Mac_DesktopDirectory);
       
    temp += "impmail.txt";
       temp.MakeUnique();
       nsresult rv = NS_NewFileSpecWithSpec( temp, ppSpec);
    if (NS_SUCCEEDED(rv)) {
              if (*ppSpec)
                     return( NS_OK);
              else
                     return( NS_ERROR_FAILURE);
       }

       return( rv);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 446 of file nsEudoraMac.cpp.

{      
       nsFileSpec    spec;
       nsresult rv = pMail->GetFileSpec( &spec);
       if (NS_FAILED( rv))
              return( PR_FALSE);
        short resFile = -1;
#ifdef XP_MACOSX
        {
          nsCOMPtr<nsILocalFileMac> macFile;
          rv = NS_FileSpecToILocalFileMac(&spec, getter_AddRefs(macFile));
          if (NS_FAILED(rv))
            return PR_FALSE;

          FSSpec fsSpec;
          rv = macFile->GetFSSpec(&fsSpec);
         if (NS_FAILED(rv))
            return PR_FALSE;

          resFile = FSpOpenResFile( &fsSpec, fsRdPerm);
        }
#else
        resFile = FSpOpenResFile( spec.GetFSSpecPtr(), fsRdPerm);
#endif
       if (resFile == -1)
              return( PR_FALSE);
       Handle resH = nil;
       short max = Count1Resources( 'TOCF');
       if (max) {
              resH = Get1IndResource( 'TOCF', 1);
       }
       PRBool  result = PR_FALSE;
       if (resH) {
              PRInt32 sz = (PRInt32) GetHandleSize( resH);
              if (sz) {
                     // Create the new TOC file
                     nsSpecialSystemDirectory    dir( nsSpecialSystemDirectory::OS_TemporaryDirectory);
                     rv = pToc->SetFromFileSpec( dir);
                     if (NS_SUCCEEDED( rv))
                            rv = pToc->AppendRelativeUnixPath( "temp.toc");
                     if (NS_SUCCEEDED( rv))
                            rv = pToc->MakeUnique();
                     if (NS_SUCCEEDED( rv))
                            rv = pToc->OpenStreamForWriting();
                     if (NS_SUCCEEDED( rv)) { 
                            HLock( resH);
                            PRInt32 written = 0;
                            rv = pToc->Write( *resH, sz, &written);
                            HUnlock( resH);
                            pToc->CloseStream();
                            if (NS_FAILED( rv) || (written != sz)) {
                                   pToc->GetFileSpec( &spec);
                                   spec.Delete( PR_FALSE);
                            }
                            else
                                   result = PR_TRUE;
                     }
              }             
              ReleaseResource( resH);
       }
       CloseResFile( resFile); 
       
       return( result);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsEudoraMailbox::DeleteFile ( nsIFileSpec pSpec) [protected, inherited]

Definition at line 140 of file nsEudoraMailbox.cpp.

{
       PRBool        result;
       nsresult      rv = NS_OK;

       result = PR_FALSE;
       pSpec->IsStreamOpen( &result);
       if (result)
              pSpec->CloseStream();
       result = PR_FALSE;
       pSpec->Exists( &result);
       if (result) {
              result = PR_FALSE;
              pSpec->IsFile( &result);
              if (result) {
                     nsFileSpec    spec;
                     rv = pSpec->GetFileSpec( &spec);
#ifndef DONT_DELETE_EUDORA_TEMP_FILES
                     if (NS_SUCCEEDED( rv))
                            spec.Delete( PR_FALSE);
#endif
              }
       }

       return( rv);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsEudoraMac::FindAddressBooks ( nsIFileSpec pRoot,
nsISupportsArray **  ppArray 
) [virtual]

Reimplemented from nsEudoraAddress.

Definition at line 1218 of file nsEudoraMac.cpp.

{
       // Look for the nicknames file in this folder and then
       // additional files in the Nicknames folder
       // Try and find the nickNames file
       nsCOMPtr<nsIFileSpec>       spec;
       nsresult rv = NS_NewFileSpec( getter_AddRefs( spec));
       if (NS_FAILED( rv))
              return( rv);
       rv = spec->FromFileSpec( pRoot);
       if (NS_FAILED( rv))
              return( rv);
       rv = NS_NewISupportsArray( ppArray);
       if (NS_FAILED( rv)) {
              IMPORT_LOG0( "FAILED to allocate the nsISupportsArray\n");
              return( rv);
       }
              
       nsCOMPtr<nsIImportService> impSvc(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
       if (NS_FAILED( rv))
              return( rv);
       
       
       nsString             displayName;
       nsEudoraStringBundle::GetStringByID( EUDORAIMPORT_NICKNAMES_NAME, displayName);
       PRUint32             sz = 0;
       
       // First find the Nicknames file itself
       rv = spec->AppendRelativeUnixPath( "Eudora Nicknames");
       PRBool exists = PR_FALSE;
       PRBool isFile = PR_FALSE;
       if (NS_SUCCEEDED( rv))
              rv = spec->Exists( &exists);
       if (NS_SUCCEEDED( rv) && exists)
              rv = spec->IsFile( &isFile);

       nsCOMPtr<nsIImportABDescriptor>    desc;
       nsISupports *                             pInterface;
       
       if (exists && isFile) {
              rv = impSvc->CreateNewABDescriptor( getter_AddRefs( desc));
              if (NS_SUCCEEDED( rv)) {
                     sz = 0;
                     spec->GetFileSize( &sz);    
                     desc->SetPreferredName( displayName.get());
                     desc->SetSize( sz);
                     nsIFileSpec *pSpec = nsnull;
                     desc->GetFileSpec( &pSpec);
                     if (pSpec) {
                            pSpec->FromFileSpec( spec);
                            NS_RELEASE( pSpec);
                     }
                     rv = desc->QueryInterface( kISupportsIID, (void **) &pInterface);
                     (*ppArray)->AppendElement( pInterface);
                     pInterface->Release();
              }
              if (NS_FAILED( rv)) {
                     IMPORT_LOG0( "*** Error creating address book descriptor for eudora nicknames\n");
                     return( rv);
              }
       }
       
       // Now try the directory of address books!
       rv = spec->FromFileSpec( pRoot);
       if (NS_SUCCEEDED( rv))
              rv = spec->AppendRelativeUnixPath( "Nicknames Folder");
       exists = PR_FALSE;
       PRBool isDir = PR_FALSE;
       if (NS_SUCCEEDED( rv))
              rv = spec->Exists( &exists);
       if (NS_SUCCEEDED( rv) && exists)
              rv = spec->IsDirectory( &isDir);
       
       if (!isDir)
              return( NS_OK);      
       
       // We need to iterate the directory
       nsCOMPtr<nsIDirectoryIterator>     dir;
       rv = NS_NewDirectoryIterator( getter_AddRefs( dir));
       if (NS_FAILED( rv))
              return( rv);

       exists = PR_FALSE;
       rv = dir->Init( spec, PR_TRUE);
       if (NS_FAILED( rv))
              return( rv);

       rv = dir->Exists( &exists);
       if (NS_FAILED( rv))
              return( rv);
       
       char *                             pName;
       nsFileSpec                         fSpec;
       OSType                             type;
       OSType                             creator;
       
       while (exists && NS_SUCCEEDED( rv)) {
              rv = dir->GetCurrentSpec( getter_AddRefs( spec));
              if (NS_SUCCEEDED( rv)) {
                     isFile = PR_FALSE;
                     pName = nsnull;
                     rv = spec->IsFile( &isFile);
                     rv = spec->GetLeafName( &pName);
                     if (pName)    {
                            NS_CopyNativeToUnicode(nsDependentCString(pName), displayName);
                            nsCRT::free( pName);
                     }
                     if (NS_SUCCEEDED( rv) && pName && isFile) {
                            rv = spec->GetFileSpec( &fSpec);
                            if (NS_SUCCEEDED( rv)) {
                                   type = 0;
                                   creator = 0;
#ifdef XP_MACOSX
  {
    nsCOMPtr<nsILocalFileMac> macFile;
    rv = NS_FileSpecToILocalFileMac(&fSpec, getter_AddRefs(macFile));
    if (NS_SUCCEEDED(rv))
    {
      macFile->GetFileCreator(&creator);
      macFile->GetFileType(&type);
    }
  }
#else
                                   fSpec.GetFileTypeAndCreator( &type, &creator);
#endif
                                   if (type == 'TEXT') {
                                          rv = impSvc->CreateNewABDescriptor( getter_AddRefs( desc));
                                          if (NS_SUCCEEDED( rv)) {
                                                 sz = 0;
                                                 spec->GetFileSize( &sz);    
                                                 desc->SetPreferredName( displayName.get());
                                                 desc->SetSize( sz);
                                                 nsIFileSpec *pSpec = nsnull;
                                                 desc->GetFileSpec( &pSpec);
                                                 if (pSpec) {
                                                        pSpec->FromFileSpec( spec);
                                                        NS_RELEASE( pSpec);
                                                 }
                                                 rv = desc->QueryInterface( kISupportsIID, (void **) &pInterface);
                                                 (*ppArray)->AppendElement( pInterface);
                                                 pInterface->Release();
                                          }
                                          if (NS_FAILED( rv)) {
                                                 IMPORT_LOG0( "*** Error creating address book descriptor for eudora address book\n");
                                                 return( rv);
                                          }
                                   }
                            }
                     }                           
              }

              rv = dir->Next();
              if (NS_SUCCEEDED( rv))
                     rv = dir->Exists( &exists);
       }

       
       return( rv);
}

Here is the call graph for this function:

Reimplemented from nsEudoraAddress.

Definition at line 1213 of file nsEudoraMac.cpp.

{
       return( FindEudoraLocation( pFolder));
}

Here is the call graph for this function:

PRBool nsEudoraMac::FindEudoraLocation ( nsIFileSpec pFolder,
PRBool  findIni = PR_FALSE,
nsIFileSpec pLookIn = nsnull 
) [static, private]

Definition at line 107 of file nsEudoraMac.cpp.

{
       PRBool result = PR_FALSE;
       
       // The "default" eudora folder is in the system folder named
       // "Eudora Folder" (not sure if this is true for intl versions of Eudora)
       
       if (!pLookIn) {
              nsSpecialSystemDirectory    sysDir( nsSpecialSystemDirectory::Mac_SystemDirectory);
              pFolder->SetFromFileSpec( sysDir);
              pFolder->AppendRelativeUnixPath( "Eudora Folder");
              PRBool link = PR_FALSE;
              nsresult rv = pFolder->IsSymlink( &link);
              if (NS_SUCCEEDED( rv) && link) {
                     rv = pFolder->ResolveSymlink();
                     if (NS_FAILED( rv))
                            return( PR_FALSE);
              }
       }
       else
              pFolder->FromFileSpec( pLookIn);
              
       PRBool exists = PR_FALSE;
       nsresult rv = pFolder->Exists( &exists);
       PRBool isFolder = PR_FALSE;
       if (NS_SUCCEEDED( rv) && exists)
              rv = pFolder->IsDirectory( &isFolder);
       if (!exists || !isFolder)
              return( PR_FALSE);
       
       
       nsFileSpec                                       pref;
       PRBool                                           foundPref = PR_FALSE;
       
       nsCOMPtr<nsIDirectoryIterator>     dir;
       rv = NS_NewDirectoryIterator( getter_AddRefs( dir));
       if (NS_SUCCEEDED( rv) && dir) {
              exists = PR_FALSE;
              rv = dir->Init( pFolder, PR_TRUE);
              if (NS_SUCCEEDED( rv)) {
                     rv = dir->Exists( &exists);               
                     nsCOMPtr<nsIFileSpec>       entry;
                     int                                       count = 0;
                     OSType                             type, creator;
                     while (exists && NS_SUCCEEDED( rv) && (count < 2)) {
                            rv = dir->GetCurrentSpec( getter_AddRefs( entry));
                            if (NS_SUCCEEDED( rv)) {
                                   nsFileSpec spec;
                                   rv = entry->GetFileSpec( &spec);
                                   if (NS_SUCCEEDED( rv)) {
                                          // find a file with TEXT, CSOm that isn't the nicknames file
                                          // or just cheat and look for more than 1 file?
#ifdef XP_MACOSX
  {
    nsCOMPtr<nsILocalFileMac> macFile;
    rv = NS_FileSpecToILocalFileMac(&spec, getter_AddRefs(macFile));
    if (NS_SUCCEEDED(rv))
    {
      macFile->GetFileCreator(&creator);
      macFile->GetFileType(&type);
    }
  }
#else
                                          rv = spec.GetFileTypeAndCreator( &type, &creator);
#endif
                                          if (NS_SUCCEEDED( rv)) {
                                                 if ((type == 'TEXT') && (creator == 'CSOm'))
                                                        count++;
                                                 else if ((type == 'PREF') && (creator == 'CSOm')) {
                                                        if (!foundPref) {
                                                               pref = spec;
                                                               foundPref = PR_TRUE;
                                                        }
                                                        else {
                                                               // does one of them end in ".bkup"?
                                                               char *pLeafName = spec.GetLeafName();
                                                               PRBool isBk = PR_FALSE;
                                                               PRInt32 len;
                                                               if (pLeafName) {
                                                                      len = strlen( pLeafName);
                                                                      if (len > 5)
                                                                             isBk = (nsCRT::strcasecmp( pLeafName + len - 5, ".bkup") == 0);
                                                                      nsCRT::free( pLeafName);
                                                               }
                                                               if (!isBk) {
                                                                      pLeafName = pref.GetLeafName();
                                                                      if (pLeafName) {
                                                                             len = strlen( pLeafName);
                                                                             if (len > 5)
                                                                                    isBk = (nsCRT::strcasecmp( pLeafName + len - 5, ".bkup") == 0);
                                                                             nsCRT::free( pLeafName);
                                                                      }
                                                                      if (isBk) {
                                                                             pref = spec;
                                                                      }
                                                                      else {
                                                                             // Neither of the pref files was named .bkup
                                                                             // Pick the newest one?
                                                                             nsFileSpec::TimeStamp       modDate1, modDate2;
                                                                             
                                                                             spec.GetModDate( modDate2);
                                                                             pref.GetModDate( modDate1);
                                                                             if (modDate2 > modDate1)
                                                                                    pref = spec;
                                                                      }
                                                               }
                                                        }
                                                 }
                                          }
                                   }
                            }
                            rv = dir->Next();
                            if (NS_SUCCEEDED( rv))
                                   rv = dir->Exists( &exists);
                     }
                     if (count >= 2)
                            result = PR_TRUE;
              }
       }
       
       if (!findIni)
              return( result);
                     
       if (!foundPref)
              return( PR_FALSE);
       
       pFolder->SetFromFileSpec( pref);
       
       return( PR_TRUE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsEudoraMac::FindMailboxes ( nsIFileSpec pRoot,
nsISupportsArray **  ppArray 
) [virtual]

Reimplemented from nsEudoraMailbox.

Definition at line 240 of file nsEudoraMac.cpp.

{
       nsresult rv = NS_NewISupportsArray( ppArray);
       if (NS_FAILED( rv)) {
              IMPORT_LOG0( "FAILED to allocate the nsISupportsArray\n");
              return( rv);
       }
              
       nsCOMPtr<nsIImportService> impSvc(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
       if (NS_FAILED( rv))
              return( rv);
       
       m_depth = 0;
       NS_IF_RELEASE( m_mailImportLocation);
       m_mailImportLocation = pRoot;
       NS_IF_ADDREF( m_mailImportLocation);

       return( ScanMailDir( pRoot, *ppArray, impSvc));
}

Here is the call graph for this function:

Reimplemented from nsEudoraMailbox.

Definition at line 102 of file nsEudoraMac.cpp.

{
       return( FindEudoraLocation( pFolder));
}

Here is the call graph for this function:

static PRBool nsEudoraMac::FindSettingsFile ( nsIFileSpec pIniFile) [inline, static]

Definition at line 75 of file nsEudoraMac.h.

{ return( FindEudoraLocation( pIniFile, PR_TRUE));}

Here is the call graph for this function:

nsresult nsEudoraMac::FindTOCFile ( nsIFileSpec pMailFile,
nsIFileSpec **  pTOCFile,
PRBool pDeleteToc 
) [virtual]

Reimplemented from nsEudoraMailbox.

Definition at line 512 of file nsEudoraMac.cpp.

{
       nsresult             rv;
       char   *             pName = nsnull;

       *pDeleteToc = PR_FALSE;
       *ppTOCFile = nsnull;
       rv = pMailFile->GetLeafName( &pName);
       if (NS_FAILED( rv))
              return( rv);
       rv = pMailFile->GetParent( ppTOCFile);
       if (NS_FAILED( rv))
              return( rv);

       nsCString     leaf(pName);
       nsCRT::free( pName);
       leaf.Append( ".toc");
       
       OSType type = 0;
       OSType creator = 0;
       PRBool exists = PR_FALSE;
       PRBool isFile = PR_FALSE;
       rv = (*ppTOCFile)->AppendRelativeUnixPath( leaf.get());
       if (NS_SUCCEEDED( rv))
              rv = (*ppTOCFile)->Exists( &exists);
       if (NS_SUCCEEDED( rv) && exists)
              rv = (*ppTOCFile)->IsFile( &isFile);
       if (isFile) {
              nsFileSpec    spec;
              rv = (*ppTOCFile)->GetFileSpec( &spec);
              if (NS_SUCCEEDED( rv))
#ifdef XP_MACOSX
  {
    nsCOMPtr<nsILocalFileMac> macFile;
    rv = NS_FileSpecToILocalFileMac(&spec, getter_AddRefs(macFile));
    if (NS_SUCCEEDED(rv))
    {
      macFile->GetFileCreator(&creator);
      macFile->GetFileType(&type);
    }
  }
#else
                     spec.GetFileTypeAndCreator( &type, &creator);
#endif
       }
       

       if (exists && isFile && (type == 'TOCF') && (creator == 'CSOm'))
              return( NS_OK);
       
       // try and create the file from a resource.
       if (CreateTocFromResource( pMailFile, *ppTOCFile)) {
              *pDeleteToc = PR_TRUE;
              return( NS_OK);
       }
       return( NS_ERROR_FAILURE);
}

Here is the call graph for this function:

nsresult nsEudoraMac::FoundMailbox ( nsIFileSpec mailFile,
const char *  pName,
nsISupportsArray pArray,
nsIImportService pImport 
) [private]

Definition at line 362 of file nsEudoraMac.cpp.

{
       nsAutoString                                            displayName;
       nsCOMPtr<nsIImportMailboxDescriptor>      desc;
       nsISupports *                                           pInterface;

       NS_CopyNativeToUnicode(nsDependentCString(pName), displayName);

#ifdef IMPORT_DEBUG
       char *pPath = nsnull;
       mailFile->GetNativePath( &pPath);
       if (pPath) {
              IMPORT_LOG2( "Found eudora mailbox, %s: %s\n", pPath, pName);
              nsCRT::free( pPath);
       }
       else {
              IMPORT_LOG1( "Found eudora mailbox, %s\n", pName);
       }
       IMPORT_LOG1( "\tm_depth = %d\n", (int)m_depth);
#endif

       nsresult rv = pImport->CreateNewMailboxDescriptor( getter_AddRefs( desc));
       if (NS_SUCCEEDED( rv)) {
              PRUint32             sz = 0;
              mailFile->GetFileSize( &sz);       
              desc->SetDisplayName( displayName.get());
              desc->SetDepth( m_depth);
              desc->SetSize( sz);
              nsIFileSpec *pSpec = nsnull;
              desc->GetFileSpec( &pSpec);
              if (pSpec) {
                     pSpec->FromFileSpec( mailFile);
                     NS_RELEASE( pSpec);
              }
              rv = desc->QueryInterface( kISupportsIID, (void **) &pInterface);
              pArray->AppendElement( pInterface);
              pInterface->Release();
       }

       return( NS_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsEudoraMac::FoundMailFolder ( nsIFileSpec mailFolder,
const char *  pName,
nsISupportsArray pArray,
nsIImportService pImport 
) [private]

Definition at line 405 of file nsEudoraMac.cpp.

{
       nsAutoString                              displayName;
       nsCOMPtr<nsIImportMailboxDescriptor>      desc;
       nsISupports *                                           pInterface;

       NS_CopyNativeToUnicode(nsDependentCString(pName), displayName);

#ifdef IMPORT_DEBUG
       char *pPath = nsnull;
       mailFolder->GetNativePath( &pPath);
       if (pPath) {
              IMPORT_LOG2( "Found eudora folder, %s: %s\n", pPath, pName);
              nsCRT::free( pPath);
       }
       else {
              IMPORT_LOG1( "Found eudora folder, %s\n", pName);
       }
       IMPORT_LOG1( "\tm_depth = %d\n", (int)m_depth);
#endif

       nsresult rv = pImport->CreateNewMailboxDescriptor( getter_AddRefs( desc));
       if (NS_SUCCEEDED( rv)) {
              PRUint32             sz = 0;
              desc->SetDisplayName( displayName.get());
              desc->SetDepth( m_depth);
              desc->SetSize( sz);
              nsIFileSpec *pSpec = nsnull;
              desc->GetFileSpec( &pSpec);
              if (pSpec) {
                     pSpec->FromFileSpec( mailFolder);
                     NS_RELEASE( pSpec);
              }
              rv = desc->QueryInterface( kISupportsIID, (void **) &pInterface);
              pArray->AppendElement( pInterface);
              pInterface->Release();
       }

       return( NS_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsEudoraMac::GetAttachmentInfo ( const char *  pFileName,
nsIFileSpec pSpec,
nsCString mimeType,
nsCString aAttachment 
) [virtual]

Reimplemented from nsEudoraMailbox.

Definition at line 959 of file nsEudoraMac.cpp.

{
       mimeType.Truncate();

       // Sample attachment line
       // Internet:sandh.jpg (JPEG/JVWR) (0003C2E8)
       
       OSType        type = '????';
       OSType        creator = '????';
       PRUint32      fNum = 0;
       int                  i;
       PRUnichar     c;
       
       nsCString     str(pFileName);
       if (str.Length() > 22) {
              // try and extract the mac file info from the attachment line
              nsCString     fileNum;
              nsCString     types;
              
              str.Right( fileNum, 10);
              if ((fileNum.CharAt( 0) == '(') && (fileNum.CharAt( 9) == ')')) {
                     for (i = 1; i < 9; i++) {
                            fNum *= 16;
                            c = fileNum.CharAt( i);
                            if ((c >= '0') && (c <= '9'))
                                   fNum += (c - '0');
                            else if ((c >= 'a') && (c <= 'f'))
                                   fNum += (c - 'a' + 10);
                            else if ((c >= 'A') && (c <= 'F'))
                                   fNum += (c - 'A' + 10);
                            else
                                   break;
                     }
                     if (i == 9) {
                            str.Left( fileNum, str.Length() - 10);
                            str = fileNum;
                            str.Trim( kWhitespace);
                            str.Right( types, 11);
                            if ((types.CharAt( 0) == '(') && (types.CharAt( 5) == '/') && (types.CharAt( 10) == ')')) {
                                   type = ((PRUint32)types.CharAt( 1)) << 24;
                                   type |= ((PRUint32)types.CharAt( 2)) << 16;
                                   type |= types.CharAt( 3) << 8;
                                   type |= types.CharAt( 4);
                                   creator = ((PRUint32)types.CharAt( 6)) << 24;
                                   creator |= ((PRUint32)types.CharAt( 7)) << 16;
                                   creator |= types.CharAt( 8) << 8;
                                   creator |= types.CharAt( 9);
                                   str.Left( types, str.Length() - 11);
                                   str = types;
                                   str.Trim( kWhitespace);
                            }
                     }
                     else
                            fNum = 0;
              }
       }
       
#ifdef IMPORT_DEBUG
       nsCString     typeStr;
       nsCString     creatStr;
       
       creatStr.Append( (const char *)&creator, 4);
       typeStr.Append( (const char *)&type, 4);
       IMPORT_LOG3( "\tAttachment type: %s, creator: %s, fileNum: %ld\n", typeStr.get(), creatStr.get(), fNum);
       IMPORT_LOG1( "\tAttachment file name: %s\n", str.get());
#endif
       FSSpec spec;
       memset( &spec, 0, sizeof( spec));
#ifdef XP_MACOSX
        {
          nsresult rv = pSpec->SetNativePath(str.get());
          if (NS_FAILED(rv)) {
            IMPORT_LOG0("\tfailed to set native path\n");
            return rv;
          }
  
          nsFileSpec tempFileSpec;
          rv = pSpec->GetFileSpec(&tempFileSpec);
          if (NS_FAILED(rv)) {
            IMPORT_LOG0("\tfailed to get file spec\n");
            return rv;
          }

          char *pLeaf = nsnull;
                    pSpec->GetLeafName( &pLeaf);
          aAttachment.Adopt(pLeaf);

          nsCOMPtr<nsILocalFileMac> macFile;
          rv = NS_FileSpecToILocalFileMac(&tempFileSpec, getter_AddRefs(macFile));
          if (NS_FAILED(rv)) {
            IMPORT_LOG0("\tfailed to get local mac file\n");
            return rv;
          }
          
          rv = macFile->GetFSSpec(&spec);
          if (NS_FAILED(rv)) {
            IMPORT_LOG0("\tfailed to get FSSpec\n");
            return rv;
          }
        }
#else
       // Now we have all of the pertinent info, find out if the file exists?
       nsCString     fileName;
       if ((str.CharAt( 0) == '"') && (str.Last() == '"')) {
              str.Mid( fileName, 1, str.Length() - 2);
              str = fileName;
       }
       
       PRInt32 idx = str.FindChar( ':');
       if (idx == -1) {
              return( NS_ERROR_FAILURE);
       }
       
       nsCString     volumeName;
       str.Left( volumeName, idx + 1);
       str.Right( fileName, str.Length() - idx - 1);
       
       // Create a FSSpec from the volume name, fileName, and folderNumber
       // Assume that we are looking for a file on the volume with macFileId
       Str63  str63;
       short  vRefNum = 0;
       if (volumeName.Length() > 63) {
              memcpy( &(str63[1]), volumeName.get(), 63);
              str63[0] = 63;
       }
       else {
              memcpy( &(str63[1]), volumeName.get(), volumeName.Length());
              str63[0] = volumeName.Length();
       }
              
       OSErr err = DetermineVRefNum( str63, 0, &vRefNum);
       if (err != noErr) {
              IMPORT_LOG0( "\t*** Error cannot find volume ref num\n");
              return( NS_ERROR_FAILURE);
       }
       
       err = FSpResolveFileIDRef( nil, vRefNum, (long) fNum, &spec);
       if (err != noErr) {
              IMPORT_LOG1( "\t*** Error, cannot resolve fileIDRef: %ld\n", (long) err);
              return( NS_ERROR_FAILURE);
       }
       
       
       FInfo  fInfo;
       err = FSpGetFInfo( &spec, &fInfo);
       if ((err != noErr) || (fInfo.fdType != (OSType) type)) {
              IMPORT_LOG0( "\t*** Error, file type does not match\n");
              return( NS_ERROR_FAILURE);
       }
       
       nsFileSpec    fSpec( spec);
       pSpec->SetFromFileSpec( fSpec);
#endif
       
#ifdef XP_MACOSX
       if (HasResourceFork(&spec)) 
#else
        // Need to find the mime type for the attachment?
        long    dataSize = 0;
        long    rsrcSize = 0;
 
        err = FSpGetFileSize( &spec, &dataSize, &rsrcSize);
 
        // TLR: FIXME: Need to get the mime type from the Mac file type.
        // Currently we just applsingle if there is a resource fork, otherwise,
        // just default to something.
 
        if (rsrcSize)
#endif
              mimeType = "application/applefile";
       else
              mimeType = "application/octet-stream";
       
       IMPORT_LOG1( "\tMimeType: %s\n", mimeType.get());
       
       return( NS_OK);
}

Here is the call graph for this function:

PRBool nsEudoraMac::GetSettingsFromResource ( nsIFileSpec pSettings,
short  resId,
nsCString **  pStrs,
PRBool pIMAP 
) [static, private]

Definition at line 594 of file nsEudoraMac.cpp.

{
       *pIMAP = PR_FALSE;
       // Get settings from the resources...
       nsFileSpec    spec;
       nsresult rv = pSettings->GetFileSpec( &spec);
       if (NS_FAILED( rv))
              return( PR_FALSE);

        short resFile = -1;
#ifdef XP_MACOSX
        {
          nsCOMPtr<nsILocalFileMac> macFile;
          rv = NS_FileSpecToILocalFileMac(&spec, getter_AddRefs(macFile));
         if (NS_FAILED(rv))
            return PR_FALSE;

          FSSpec fsSpec;
          rv = macFile->GetFSSpec(&fsSpec);
         if (NS_FAILED(rv))
            return PR_FALSE;

          resFile = FSpOpenResFile( &fsSpec, fsRdPerm);
        }
#else
       resFile = FSpOpenResFile( spec.GetFSSpecPtr(), fsRdPerm);
#endif
       if (resFile == -1)
              return( PR_FALSE);
              
       // smtp server, STR# 1000, 4
       Handle resH = Get1Resource( 'STR#', resId /* 1000 */);
       int           idx;
       if (resH) {
              ReleaseResource( resH);
              StringPtr     pStr[5];
              StringPtr     theStr;
              short         i;
              for (i = 0; i < 5; i++) {
                     pStr[i] = (StringPtr) new PRUint8[256];
                     (pStr[i])[0] = 0;
              }
              GetIndString( pStr[0], resId /* 1000 */, kSmtpServerID);
              GetIndString( pStr[1], resId, kEmailAddressID); // user name@pop server
              GetIndString( pStr[2], resId, kReturnAddressID); 
              GetIndString( pStr[3], resId, kFullNameID);
              GetIndString( pStr[4], resId, kLeaveMailOnServerID);
              CloseResFile( resFile); 
              
              theStr = pStr[0];
              if (*theStr) {
                     pStrs[0]->Append( (const char *) (theStr + 1), *theStr);
              }
              theStr = pStr[1];
              if (*theStr) {
                     idx = 1;
                     while (idx <= *theStr) {
                            if (theStr[idx] == '@')
                                   break;
                            else
                                   idx++;
                     }
                     if (idx <= *theStr) {
                            PRUint8       save = *theStr;
                            *theStr = idx - 1;
                            if (*theStr) {
                                   pStrs[1]->Append( (const char *) (theStr + 1), *theStr);
                            }
                            *theStr = save;
                     }
                     else
                            idx = 0;
                     theStr[idx] = theStr[0] - idx;
                     if (theStr[idx]) {
                            pStrs[2]->Append( (const char *) (theStr + idx + 1), *(theStr + idx));
                     }
              }
              theStr = pStr[2];
              if ( *theStr) {
                     pStrs[3]->Append( (const char *) (theStr + 1), *theStr);
              }
              theStr = pStr[3];
              if ( *theStr) {
                     pStrs[4]->Append( (const char *) (theStr + 1), *theStr);
              }
              theStr = pStr[4];
              if ( *theStr) {
                     if (theStr[1] == 'y') {
                            *(pStrs[5]) = "Y";
                     }
                     else {
                            *(pStrs[5]) = "N";
                     }
              }
              for (i = 0; i < 5; i++) {
                     delete pStr[i];
              }
              
              return( PR_TRUE);
       }
       else {
              CloseResFile( resFile); 
              return( PR_FALSE);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsEudoraMac::HasResourceFork ( FSSpec fsSpec) [private]

Definition at line 1137 of file nsEudoraMac.cpp.

{
  FSRef fsRef;
  if (::FSpMakeFSRef(fsSpec, &fsRef) == noErr)
  {
    FSCatalogInfo catalogInfo;
    OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoRsrcSizes, &catalogInfo, nsnull, nsnull, nsnull);
    return (err == noErr && catalogInfo.rsrcLogicalSize != 0);
  }
  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsEudoraAddress::ImportAddresses ( PRUint32 pBytes,
PRBool pAbort,
const PRUnichar pName,
nsIFileSpec pSrc,
nsIAddrDatabase pDb,
nsString errors 
) [inherited]

Definition at line 115 of file nsEudoraAddress.cpp.

{
       // Open the source file for reading, read each line and process it!
       
       EmptyAliases();
       
       nsresult rv = pSrc->OpenStreamForReading();
       if (NS_FAILED( rv)) {
              IMPORT_LOG0( "*** Error opening address file for reading\n");
              return( rv);
       }
       
       char *pLine = new char[kEudoraAddressBufferSz];
       PRBool wasTruncated;
       PRBool eof = PR_FALSE;
       rv = pSrc->Eof( &eof);
       if (NS_FAILED( rv)) {
              IMPORT_LOG0( "*** Error checking address file for eof\n");
              pSrc->CloseStream();
              return( rv);
       }
       
       while (!(*pAbort) && !eof && NS_SUCCEEDED( rv)) {
              wasTruncated = PR_FALSE;
              rv = pSrc->ReadLine( &pLine, kEudoraAddressBufferSz, &wasTruncated);
              if (wasTruncated)
                     pLine[kEudoraAddressBufferSz - 1] = 0;
              if (NS_SUCCEEDED( rv)) {
                     PRInt32       len = strlen( pLine);
                     ProcessLine( pLine, len, errors);
                     rv = pSrc->Eof( &eof);
                     if (pBytes)
                            *pBytes += (len / 2);
              }
       }
       
       rv = pSrc->CloseStream();
       
       delete [] pLine;

       if (!eof) {
              IMPORT_LOG0( "*** Error reading the address book, didn't reach the end\n");
              return( NS_ERROR_FAILURE);
       }
       
       // Run through the alias array and make address book entries...
       #ifdef IMPORT_DEBUG
       DumpAliasArray( m_alias);
       #endif
       
       BuildABCards( pBytes, pDb);
       
  rv = pDb->Commit(nsAddrDBCommitType::kLargeCommit);
       return rv;
}

Here is the call graph for this function:

nsresult nsEudoraMailbox::ImportMailbox ( PRUint32 pBytes,
PRBool pAbort,
const PRUnichar pName,
nsIFileSpec pSrc,
nsIFileSpec pDst,
PRInt32 pMsgCount 
) [inherited]

Definition at line 171 of file nsEudoraMailbox.cpp.

{
       nsCOMPtr<nsIFileSpec>       tocFile;
       PRBool                             deleteToc = PR_FALSE;
       nsresult                           rv;
       nsCOMPtr<nsIFileSpec>       mailFile;
       PRBool                             deleteMailFile = PR_FALSE;
       PRUint32                           div = 1;
       PRUint32                           mul = 1;

       if (pMsgCount)
              *pMsgCount = 0;

       rv = pSrc->GetFileSize( &m_mailSize);

       rv = pSrc->OpenStreamForReading();
       if (NS_FAILED( rv))
              return( rv);

       NS_ADDREF( pSrc);

       // First, get the index file for this mailbox
       rv = FindTOCFile( pSrc, getter_AddRefs( tocFile), &deleteToc);
       if (NS_SUCCEEDED( rv) && tocFile) {
              IMPORT_LOG0( "Reading euroda toc file: ");
              DUMP_FILENAME( tocFile, PR_TRUE);

              rv = CreateTempFile( getter_AddRefs( mailFile));
              deleteMailFile = PR_TRUE;
              if (NS_SUCCEEDED( rv)) {
                     // Read the TOC and compact the mailbox file into a temp file
                     rv = tocFile->OpenStreamForReading();
                     if (NS_SUCCEEDED( rv)) {
                            rv = mailFile->OpenStreamForWriting();
                            if (NS_SUCCEEDED( rv)) {
                                   // Read the toc and compact the mailbox into mailFile
                                   rv = CompactMailbox( pBytes, pAbort, pSrc, tocFile, mailFile);
                                   div = 4;
                                   mul = 3;
                            }
                     }
              }
              
              pSrc->CloseStream();

              // clean up
              if (deleteToc) {
                     DeleteFile( tocFile);
              }
              if (NS_SUCCEEDED( rv))
                     rv = mailFile->CloseStream();
              if (NS_FAILED( rv)) {
                     DeleteFile( mailFile);
                     mailFile->FromFileSpec( pSrc);
                     deleteMailFile = PR_FALSE;
                     IMPORT_LOG0( "*** Error compacting mailbox.\n");
              }
              
              IMPORT_LOG0( "Compacted mailbox: "); DUMP_FILENAME( mailFile, PR_TRUE);

              rv = mailFile->OpenStreamForReading();
              if (NS_SUCCEEDED( rv)) {
                     pSrc->Release();
                     mailFile->QueryInterface( NS_GET_IID(nsIFileSpec), (void **)&pSrc);

                     IMPORT_LOG0( "Compacting mailbox was successful\n");
              }
              else {
                     DeleteFile( mailFile);
                     deleteMailFile = PR_FALSE;
                     IMPORT_LOG0( "*** Error accessing compacted mailbox\n");
              }
       }
       
       // So, where we are now, is we have the mail file to import in pSrc
       // It may need deleting if deleteMailFile is PR_TRUE.
       // pSrc must be Released before returning
       
       // The source file contains partially constructed mail messages,
       // and attachments.  We should first investigate if we can use the mailnews msgCompose
       // stuff to do the work for us.  If not we have to scan the mailboxes and do TONS
       // of work to properly reconstruct the message - Eudora is so nice that it strips things
       // like MIME headers, character encoding, and attachments - beautiful!
       
       rv = pSrc->GetFileSize( &m_mailSize);

       nsCOMPtr<nsIFileSpec>       compositionFile;
       SimpleBufferTonyRCopiedOnce               readBuffer;
       SimpleBufferTonyRCopiedOnce               headers;
       SimpleBufferTonyRCopiedOnce               body;
       SimpleBufferTonyRCopiedOnce               copy;
       PRInt32                                   written;
       nsCString                          fromLine(eudoraFromLine);
       
       headers.m_convertCRs = PR_TRUE;
       body.m_convertCRs = PR_TRUE;
       
       copy.Allocate( kCopyBufferSize);
       readBuffer.Allocate( kMailReadBufferSize);
       ReadFileState               state;
       state.offset = 0;
       state.size = m_mailSize;
       state.pFile = pSrc;

       IMPORT_LOG0( "Reading mailbox\n");

       if (NS_SUCCEEDED( rv = NS_NewFileSpec( getter_AddRefs( compositionFile)))) {
              nsEudoraCompose             compose;
    nsCString defaultDate;
    nsCAutoString bodyType;
              
              /*
              IMPORT_LOG0( "Calling compose.SendMessage\n");
              rv = compose.SendMessage( compositionFile);
              if (NS_SUCCEEDED( rv)) {
                     IMPORT_LOG0( "Composed message in file: "); DUMP_FILENAME( compositionFile, PR_TRUE);
              }
              else {
                     IMPORT_LOG0( "*** Error composing message\n");
              }
              */

              IMPORT_LOG0( "Reading first message\n");

    while (!*pAbort && NS_SUCCEEDED( rv = ReadNextMessage( &state, readBuffer, headers, body, defaultDate, bodyType))) {
                     
                     if (pBytes) {
                            *pBytes += (((body.m_writeOffset - 1 + headers.m_writeOffset - 1) / div) * mul);
                     }

      // Unfortunately Eudora stores HTML messages in the sent folder
      // without any content type header at all. If the first line of the message body is <html>
      // then mark the message as html internally...See Bug #258489
      if (body.m_pBuffer && (body.m_writeOffset > strlen(kHTMLTag)) && (strncmp(body.m_pBuffer, kHTMLTag, strlen(kHTMLTag)) == 0 ))
        bodyType = "text/html"; // ignore whatever body type we were given...force html

      compose.SetBody( body.m_pBuffer, body.m_writeOffset - 1, bodyType);
                     compose.SetHeaders( headers.m_pBuffer, headers.m_writeOffset - 1);
                     compose.SetAttachments( &m_attachments);
      compose.SetDefaultDate(defaultDate);

                     rv = compose.SendTheMessage( compositionFile);
                     if (NS_SUCCEEDED( rv)) {
                            /* IMPORT_LOG0( "Composed message in file: "); DUMP_FILENAME( compositionFile, PR_TRUE); */
                            // copy the resulting file into the destination file!
                            rv = compose.CopyComposedMessage( fromLine, compositionFile, pDst, copy);
                            DeleteFile( compositionFile);
                            if (NS_FAILED( rv)) {
                                   IMPORT_LOG0( "*** Error copying composed message to destination mailbox\n");
                                   break;
                            }
                            if (pMsgCount)
                                   (*pMsgCount)++;
                     }
                     else {
                            IMPORT_LOG0( "*** Error composing message, writing raw message\n");
                            rv = WriteFromSep( pDst);
                            
                            rv = pDst->Write( kComposeErrorStr,
                                                               strlen( kComposeErrorStr),
                                                               &written );
                            
                            if (NS_SUCCEEDED( rv))
                                   rv = pDst->Write( headers.m_pBuffer, headers.m_writeOffset - 1, &written);
                            if (NS_SUCCEEDED( rv) && (written == (headers.m_writeOffset - 1)))
                                   rv = pDst->Write( "\x0D\x0A" "\x0D\x0A", 4, &written);
                            if (NS_SUCCEEDED( rv) && (written == 4))
                                   rv = pDst->Write( body.m_pBuffer, body.m_writeOffset - 1, &written);
                            if (NS_SUCCEEDED( rv) && (written == (body.m_writeOffset - 1))) {
                                   rv = pDst->Write( "\x0D\x0A", 2, &written);
                                   if (written != 2)
                                          rv = NS_ERROR_FAILURE;
                            }
                            
                            if (NS_FAILED( rv)) {
                                   IMPORT_LOG0( "*** Error writing to destination mailbox\n");
                                   break;
                            }
                     }

                     if (!readBuffer.m_bytesInBuf && (state.offset >= state.size))
                            break;
              }
              
       }
       else {
              IMPORT_LOG0( "*** Error creating file spec for composition\n");
       }

       if (deleteMailFile)
              DeleteFile( pSrc);
       
       pSrc->Release();

       return( rv);
}

Here is the call graph for this function:

PRBool nsEudoraMac::ImportSettings ( nsIFileSpec pIniFile,
nsIMsgAccount **  localMailAccount 
) [static]

Definition at line 700 of file nsEudoraMac.cpp.

{
       nsresult      rv;

       nsCOMPtr<nsIMsgAccountManager> accMgr = 
                do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
    if (NS_FAILED(rv)) {
              IMPORT_LOG0( "*** Failed to create a account manager!\n");
              return( PR_FALSE);
       }

       short  baseResId = 1000;
       nsCString **pStrs = new nsCString *[kNumSettingStrs];
       int           i;
       
       for (i = 0; i < kNumSettingStrs; i++) {
              pStrs[i] = new nsCString;
       }
       
       nsString accName(NS_LITERAL_STRING("Eudora Settings"));
       nsEudoraStringBundle::GetStringByID( EUDORAIMPORT_ACCOUNTNAME, accName);
       
       // This is a little overkill but we're not sure yet how multiple accounts
       // are stored in the Mac preferences, hopefully similar to existing prefs
       // which means the following is a good start!
       PRBool isIMAP = PR_FALSE;   
       
       int                         popCount = 0;
       int                         accounts = 0; 
       nsIMsgAccount *      pAccount;

       while (baseResId) {
              isIMAP = PR_FALSE;
              if (GetSettingsFromResource( pIniFile, baseResId, pStrs, &isIMAP)) {
                     pAccount = nsnull;
                     if (!isIMAP) {
                            // This is a POP account
                            if (BuildPOPAccount( accMgr, pStrs, &pAccount, accName)) {
                                   accounts++;
                                   popCount++;
                                   if (popCount > 1) {
                                          if (localMailAccount && *localMailAccount) {
                                                 NS_RELEASE( *localMailAccount);
                                                 *localMailAccount = nsnull;
                                          }
                                   }
                                   else {
                                          if (localMailAccount) {
                                                 *localMailAccount = pAccount;
                                                 NS_IF_ADDREF( pAccount);
                                          }                                  
                                   }
                            }
                     }
                     else {
                            // This is an IMAP account
                            if (BuildIMAPAccount( accMgr, pStrs, &pAccount, accName)) {
                                   accounts++;
                            }
                     }
                     if (pAccount && (baseResId == 1000)) {
                            accMgr->SetDefaultAccount( pAccount);
                     }

                     NS_IF_RELEASE( pAccount);
              }
                            
              baseResId = 0;
              // Set the next account name???
              
              if (baseResId) {
                     for (i = 0; i < kNumSettingStrs; i++) {
                            pStrs[i]->Truncate();
                     }
              }             
       }

       // Now save the new acct info to pref file.
       rv = accMgr->SaveAccountInfo();
       NS_ASSERTION(NS_SUCCEEDED(rv), "Can't save account info to pref file");

       for (i = 0; i < kNumSettingStrs; i++) {
              delete pStrs[i];
       }
       delete pStrs;

       return( accounts != 0);
}

Here is the call graph for this function:

PRInt32 nsEudoraMailbox::IsEudoraFromSeparator ( const char *  pData,
PRInt32  maxLen,
nsCString defaultDate 
) [static, inherited]

Definition at line 778 of file nsEudoraMailbox.cpp.

{
       if (maxLen < 12)
              return( -1);

       PRInt32              len = 0;
       if ((*pChar != 'F') || (*(pChar + 1) != 'r') || (*(pChar + 2) != 'o') || (*(pChar + 3) != 'm'))
              return( -1);
       pChar += 4;
       len += 4;

       // According to Eudora the next char MUST be a space, and there can only be 1 space 
       // before the return mail address.
       // I'll be nicer and allow any amount of whitespace
       while (((*pChar == ' ') || (*pChar == '\t')) && (len < maxLen)) {
              pChar++;
              len++;
       }
       if (len == maxLen)
              return( -1);
       
       // Determine the length of the line
       PRInt32                     lineLen = len;
       const char *  pTok = pChar;
       while ((lineLen < maxLen) && (*pTok != 0x0D) && (*pTok != 0x0A)) {
              lineLen++;
              pTok++;
       }

       if (len >= lineLen)
              return( -1);

       // Eudora allows the return address to be double quoted or not at all..
       // I'll allow single or double quote, but other than that, just skip
       // the return address until you hit a space char (I allow tab as well)
       char   quote = *pChar;
       if ((quote == '"') || (quote == '\'')) {
              pChar++;
              len++;
              while ((len < lineLen) && (*pChar != quote)) {
                     pChar++;
                     len++;
              }
              if (len == lineLen)
                     return( -1);
              len++;
              pChar++;
       }
       else {
              while ((len < lineLen) && (*pChar != ' ') && (*pChar != '\t')) {
                     pChar++;
                     len++;
              }
       }
       while (((*pChar == ' ') || (*pChar == '\t')) && (len < lineLen)) {
              pChar++;
              len++;
       }
       if (len == lineLen)
              return( -1);
       
       // we've passed the address, now check for the remaining data  
       // Now it gets really funky!
       // In no particular order, with token separators space, tab, comma, newline
       // a - the phrase "remote from", remote must be first, from is optional.  2 froms or 2 remotes fails
       // b - one and only one time value xx:xx or xx:xx:xx
       // c - one and only one day, 1 to 31
       // d - one and only one year, 2 digit anything or 4 digit > 1900
       // e - one and only one weekday, 3 letter abreviation
       // f - one and only one month, 3 letter abreviation
       // 2 allowable "other" tokens
       // to be valid, day, year, month, & tym must exist and other must be less than 3
       
       int           day = 0;
       int           month = 0;
       int           year = 0;
       int           weekDay = 0;
       int           other = 0;
       int           result;
       char   tymStr[9];  // Make it a null terminated string (used in PR_snprintf() call()).
       PRBool tym = PR_FALSE;
       PRBool remote = PR_FALSE;
       PRBool from = PR_FALSE;
       PRInt32       tokLen;
       PRInt32       tokStart;
       PRInt32       num;

       while ((len < lineLen) && (other < 3)) {
              pTok = pChar;
              tokStart = len;
              while ((len < lineLen) && (*pChar != ' ') && (*pChar != '\t') && (*pChar != ',')) {
                     pChar++;
                     len++;
              }
              tokLen = len - tokStart;
              if (tokLen) {
                     num = AsciiToLong( pTok, tokLen);
                     if ((tokLen == 3) && ((result = IsWeekDayStr( pTok)) != 0)) {
                            if (weekDay)
                                   return( -1);
                            weekDay = result;
                     }             
                     else if ((tokLen == 3) && ((result = IsMonthStr( pTok)) != 0)) {
                            if (month)
                                   return( -1);
                            month = result;
                     }
                     else if ((tokLen == 6) && !nsCRT::strncasecmp( pTok, "remote", 6)) {
                            if (remote || from)
                                   return( -1);
                            remote = PR_TRUE;
                     } 
                     else if ((tokLen == 4) && !nsCRT::strncasecmp( pTok, "from", 4)) {
                            if (!remote || from)
                                   return( -1);
                            from = PR_TRUE;
                     }
                     else if ((tokLen == 4) && ((num > 1900) || !nsCRT::strncmp( pTok, "0000", 4))) {
                            if (year)
                                   return( -1);
                            year = (int)num;
                            if (!year)
                                   year = 1900;
                     }
                     else if (!year && day && (tokLen == 2) && (*(pTok + 1) >= '0') && (*(pTok + 1) <= '9')) {
                            if (num < 65)
                                   num += 1900;
                            else
                                   num += 2000;
                             year = (int) num;
                     }
                     else if ((tokLen <= 2) && (*pTok >= '0') && (*pTok <= '9')) {
                            day = (int) num;
                            if ((day < 1) || (day > 31))
                                   day = 1;
                     }
                     else if ((tokLen >= 5) && (pTok[2] == ':') && ((tokLen == 5) || ((tokLen == 8) && (pTok[5] == ':')))) {
                            // looks like the tym...
                            for (result = 0; result < (int)tokLen; result++) {
                                   if ((result != 2) && (result != 5)) {
                                          if ((pTok[result] < '0') || (pTok[result] > '9')) {
                                                 break;
                                          }
                                   }
                            }
                            if (result == tokLen) {
                                   if (tym)
                                          return( -1);
                                   tym = PR_TRUE;
                                   // for future use, get the time value
                                   memcpy( tymStr, pTok, tokLen);
                                   if (tokLen == 5) {
                                          tymStr[5] = ':';
                                          tymStr[6] = '0';
                                          tymStr[7] = '0';
                                   }
          tymStr[8] = 0;
                            }
                            else {
                                   other++;
                            }
                     }
                     else
                            other++;
              }      
              // Skip the space chars...
              while ((len < lineLen) && ((*pChar == ' ') || (*pChar == '\t') || (*pChar == ','))) {
                     pChar++;
                     len++;
              }
       } // end while (len < lineLen) token loop
       
       // Now let's see what we found on the line
       if (day && year && month && tym && (other < 3)) {
              // Now we need to make sure the next line
              // isn't blank!
              while (len < lineLen) {
                     len++;
                     pChar++;
              }
              if (len == maxLen)
                     return( -1);
              
              if (*pChar == 0x0D) {
                     len++;
                     pChar++;
                     if (*pChar == 0x0A) {
                            len++;
                            pChar++;
                     }
              }
              else if (*pChar == 0x0A) {
                     len++;
                     pChar++;
              }
              else
                     return( -1);
              if (len >= maxLen)
                     return( -1);

              while (len < maxLen) {
                     if ((*pChar == 0x0D) || (*pChar == 0x0A))
                            return( -1);
                     if ((*pChar != ' ') && (*pChar != '\t'))
                            break;
                     pChar++;
                     len++;
              }

              // Whew!, the next line isn't blank.
    // Generate the default date header in case the date header is missing when we
    // write out headers later. The header looks like "Date: Tue, 5 Feb 2002 23:05:04"
    char date_header_str[DATE_STR_LEN];
    PR_snprintf(date_header_str, DATE_STR_LEN, "Date: %s, %2d %s %4d %s", eudoraWeekDays[weekDay-1], day, eudoraMonths[month-1], year, tymStr);
    defaultDate.Assign(date_header_str);

              return( lineLen);
       }
       
       return( -1);

}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsEudoraMailbox::IsEudoraTag ( const char *  pChar,
PRInt32  maxLen,
PRBool insideEudoraTags,
nsCString bodyType,
PRInt32 tagLength 
) [static, inherited]

Definition at line 757 of file nsEudoraMailbox.cpp.

{
       PRInt32       idx = 0;
       while ((tagLength = eudoraTagLen[idx]) != 0) {
              if (maxLen >= tagLength && !nsCRT::strncmp( eudoraTag[idx], pChar, tagLength)) {
                     insideEudoraTags = (pChar[1] != '/');
                     bodyType = TagContentType[idx];
                     return PR_TRUE;
              }
              idx++;
       }

       return PR_FALSE;
}

Here is the caller graph for this function:

Definition at line 1185 of file nsEudoraMac.cpp.

{
       PRUint32      size = 0;
       nsresult rv = pFile->GetFileSize( &size);
       if (size) {
              if (size < 10)
                     return( PR_FALSE);
              rv = pFile->OpenStreamForReading();
              if (NS_FAILED( rv))
                     return( PR_FALSE);
              PRInt32       read = 0;
              char   buffer[6];
              char * pBuf = buffer;
              rv = pFile->Read( &pBuf, 5, &read);
              pFile->CloseStream();
              if (NS_FAILED( rv) || (read != 5))
                     return( PR_FALSE);
              buffer[5] = 0;
              if (nsCRT::strcmp( buffer, "From "))
                     return( PR_FALSE);
       }
       
       return( PR_TRUE);
}

Here is the caller graph for this function:

Definition at line 1175 of file nsEudoraMac.cpp.

{
       if (m_depth > 1)
              return( PR_TRUE);
       if (fName.Equals(NS_LITERAL_CSTRING("Eudora Nicknames"), nsCaseInsensitiveCStringComparator()))
              return( PR_FALSE);
       return( PR_TRUE);
}

Here is the caller graph for this function:

Definition at line 1161 of file nsEudoraMac.cpp.

{
       if (m_depth > 1)
              return( PR_TRUE);
       
       for (int i = 0; i < kNumBadFolderNames; i++) {
              if (name.Equals( cBadFolderNames[i], nsCaseInsensitiveCStringComparator()))
                     return( PR_FALSE);
       }
       
       return( PR_TRUE);
}

Here is the caller graph for this function:

nsresult nsEudoraMac::IterateMailDir ( nsIFileSpec pFolder,
nsISupportsArray pArray,
nsIImportService pImport 
) [private]

Definition at line 276 of file nsEudoraMac.cpp.

{
       nsCOMPtr<nsIDirectoryIterator>     dir;
       nsresult rv = NS_NewDirectoryIterator( getter_AddRefs( dir));
       if (NS_FAILED( rv))
              return( rv);

       PRBool exists = PR_FALSE;
       rv = dir->Init( pFolder, PR_TRUE);
       if (NS_FAILED( rv))
              return( rv);

       rv = dir->Exists( &exists);
       if (NS_FAILED( rv))
              return( rv);
       
       PRBool                             isFolder;
       PRBool                             isFile;
       nsCOMPtr<nsIFileSpec>       entry;
       char *                             pName;
       nsCString                          fName;
       nsCString                          ext;
       nsCString                          name;
       nsFileSpec                         spec;
       OSType                             type;
       OSType                             creator;
       
       while (exists && NS_SUCCEEDED( rv)) {
              rv = dir->GetCurrentSpec( getter_AddRefs( entry));
              if (NS_SUCCEEDED( rv)) {
                     isFolder = PR_FALSE;
                     isFile = PR_FALSE;
                     pName = nsnull;
                     rv = entry->IsDirectory( &isFolder);
                     rv = entry->IsFile( &isFile);
                     rv = entry->GetLeafName( &pName);
                     if (NS_SUCCEEDED( rv) && pName) {
                            fName = pName;
                            nsCRT::free( pName);
                            if (isFolder) {
                                   if (IsValidMailFolderName( fName)) {
                                          rv = FoundMailFolder( entry, fName.get(), pArray, pImport);
                                          if (NS_SUCCEEDED( rv)) {
                                                 rv = ScanMailDir( entry, pArray, pImport);
                                                 if (NS_FAILED( rv)) {
                                                        IMPORT_LOG0( "*** Error scanning mail directory\n");
                                                 }
                                          }
                                   }
                            }
                            else if (isFile) {
                                   rv = entry->GetFileSpec( &spec);
                                   if (NS_SUCCEEDED( rv)) {
                                          type = 0;
                                          creator = 0;
#ifdef XP_MACOSX
  {
    nsCOMPtr<nsILocalFileMac> macFile;
    rv = NS_FileSpecToILocalFileMac(&spec, getter_AddRefs(macFile));
    if (NS_SUCCEEDED(rv))
    {
      macFile->GetFileCreator(&creator);
      macFile->GetFileType(&type);
    }
  }
#else
    spec.GetFileTypeAndCreator( &type, &creator);
#endif
                                          if ((type == 'TEXT') && IsValidMailboxName( fName) && IsValidMailboxFile( entry)) {
                                                 rv = FoundMailbox( entry, fName.get(), pArray, pImport);
                                          }
                                   }
                            }
                     }                           
              }

              rv = dir->Next();
              if (NS_SUCCEEDED( rv))
                     rv = dir->Exists( &exists);
       }

       return( rv);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsEudoraMac::ScanMailDir ( nsIFileSpec pFolder,
nsISupportsArray pArray,
nsIImportService pImport 
) [private]

Definition at line 261 of file nsEudoraMac.cpp.

{

       // On Windows, we look for a descmap file but on Mac we just iterate
       // the directory
       
       m_depth++;

       nsresult rv = IterateMailDir( pFolder, pArray, pImport);
       
       m_depth--;

       return( rv);                
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsEudoraMac::SetIdentities ( nsIMsgAccountManager accMgr,
nsIMsgAccount acc,
const char *  userName,
const char *  serverName,
nsCString **  pStrs 
) [static, private]

Definition at line 897 of file nsEudoraMac.cpp.

{
       nsresult      rv;
       
       nsCOMPtr<nsIMsgIdentity>    id;
       rv = accMgr->CreateIdentity( getter_AddRefs( id));
       if (id) {
              nsAutoString fullName; 
              if (pStrs[kFullNameStr]->Length()) {
                     fullName.AssignWithConversion(pStrs[kFullNameStr]->get());
              }
              id->SetFullName( fullName.get());
              id->SetIdentityName( fullName.get());
              if (pStrs[kReturnAddressStr]->Length()) {
                     id->SetEmail( pStrs[kReturnAddressStr]->get());
              }
              else {
                     nsCAutoString emailAddress;
                     emailAddress = userName;
                     emailAddress += "@";
                     emailAddress += serverName;
                     id->SetEmail(emailAddress.get()); 
              }
              acc->AddIdentity( id);

              IMPORT_LOG0( "Created identity and added to the account\n");
              IMPORT_LOG1( "\tname: %s\n", pStrs[kFullNameStr]->get());
              IMPORT_LOG1( "\temail: %s\n", pStrs[kReturnAddressStr]->get());
       }

       SetSmtpServer( accMgr, acc, pStrs[kSmtpServerStr]->get(), userName);
              
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsEudoraMac::SetSmtpServer ( nsIMsgAccountManager pMgr,
nsIMsgAccount pAcc,
const char *  pServer,
const char *  pUser 
) [static, private]

Definition at line 932 of file nsEudoraMac.cpp.

{
       nsresult      rv;
       
       nsCOMPtr<nsISmtpService> smtpService(do_GetService(NS_SMTPSERVICE_CONTRACTID, &rv)); 
       if (NS_SUCCEEDED(rv) && smtpService) {
              nsCOMPtr<nsISmtpServer>            foundServer;
       
              rv = smtpService->FindServer( pUser, pServer, getter_AddRefs( foundServer));
              if (NS_SUCCEEDED( rv) && foundServer) {
                     IMPORT_LOG1( "SMTP server already exists: %s\n", pServer);
                     return;
              }
              nsCOMPtr<nsISmtpServer>            smtpServer;
              
              rv = smtpService->CreateSmtpServer( getter_AddRefs( smtpServer));
              if (NS_SUCCEEDED( rv) && smtpServer) {
                     smtpServer->SetHostname( pServer);
                     if (pUser)
                            smtpServer->SetUsername( pUser);

                     IMPORT_LOG1( "Created new SMTP server: %s\n", pServer);
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 103 of file nsEudoraMac.h.

Definition at line 104 of file nsEudoraMac.h.


The documentation for this class was generated from the following files: