bool StatusThread::copyLogFiles(QList<QFileInfo> listEDAT2, QList<QFileInfo> listTXT) { QString folderName(e->getFi().baseName() + (listEDAT2[0].created().toString("yyyyMMddhhmmss"))); if (log.mkdir(folderName)) { for (int i = 0; i < listEDAT2.size(); ++i) { QFile::copy(listEDAT2[i].absoluteFilePath(), log.absolutePath() + "/" + folderName + "/" + folderName + ".edat2"); QFileInfo edat2(log.absolutePath() + "/" + folderName + "/" + folderName + ".edat2"); emit textAppend1("Log file: " + edat2.fileName()); emit textAppend1("Location: " + edat2.absolutePath()); qDebug() << "copy " << log.absolutePath() + "/" + folderName + "/" + folderName + ".edat2"; } for (int i = 0; i < listTXT.size(); ++i) { QFile::copy(listTXT[i].absoluteFilePath(), log.absolutePath() + "/" + folderName + "/" + folderName + ".txt"); QFileInfo txt(log.absolutePath() + "/" + folderName + "/" + folderName + ".txt"); emit textAppend1("Log file: " + txt.fileName()); emit textAppend1("Location: " + txt.absolutePath()); qDebug() << "copy " << log.absolutePath() + "/" + folderName + "/" + folderName + ".txt"; } return true; } else { return false; } }
void et::findSubfolders(const std::string& folder, bool recursive, StringList& list) { std::string normalizedFolder = addTrailingSlash(folder); std::string foldersSearchPath = normalizedFolder + "*.*"; StringList folderList; WIN32_FIND_DATA folders = { }; HANDLE folderSearch = FindFirstFile(foldersSearchPath.c_str(), &folders); if (folderSearch != INVALID_HANDLE_VALUE) { do { if (strcmp(folders.cFileName, ".") && strcmp(folders.cFileName, "..") && ((folders.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)) { std::string folderName(folders.cFileName); folderList.push_back(normalizedFolder + folderName + "\\"); } } while (FindNextFile(folderSearch, &folders)); FindClose(folderSearch); } if (recursive) { for (const std::string& i : folderList) findSubfolders(i, true, list); } list.insert(list.end(), folderList.begin(), folderList.end()); }
void VETypeList::ScanAtLaunch() { // Validate pointers. ValidateThis_(); // Find application file. FSSpec appFile; UApplicationFile::GetApplicationFile(appFile); // Read from application file. { StApplicationContext appContext; StValueChanger<Boolean> builtIn(mTypesAreBuiltIn, true); ScanCurrentResourceFile(appFile); } // Read application folder. try { ScanFolderForPlugIns(appFile.vRefNum, appFile.parID); } catch(...) { // ignore errors } // Read "Constructor Plugins" folder in same folder as application // find the folder CInfoPBRec folderInfo; LStr255 folderName(STR_TargetInfo, str_PluginsFolderName); folderInfo.hFileInfo.ioCompletion = nil; folderInfo.hFileInfo.ioNamePtr = (StringPtr) folderName; folderInfo.hFileInfo.ioVRefNum = appFile.vRefNum; folderInfo.hFileInfo.ioFDirIndex = 0; folderInfo.hFileInfo.ioDirID = appFile.parID; OSErr err = ::PBGetCatInfoSync( &folderInfo ); if (err == noErr) { // read it try { ScanFolderForPlugIns(folderInfo.hFileInfo.ioVRefNum, folderInfo.hFileInfo.ioDirID); } catch(...) { // ignore errors } } }
QString CJobRunner::folderName(bool sys) { if(!theInterface) return QString(); QDBusPendingReply<QString> reply=theInterface->folderName(sys); reply.waitForFinished(); return reply.isError() ? QString() : reply.argumentAt<0>(); }
void et::findFiles(const std::string& folder, const std::string& mask, bool recursive, StringList& list) { std::string normalizedFolder = addTrailingSlash(folder); std::string searchPath = normalizedFolder + mask; StringList folderList; if (recursive) { std::string foldersSearchPath = normalizedFolder + "*.*"; WIN32_FIND_DATA folders = { }; HANDLE folderSearch = FindFirstFile(foldersSearchPath.c_str(), &folders); if (folderSearch != INVALID_HANDLE_VALUE) { do { if (strcmp(folders.cFileName, ".") && strcmp(folders.cFileName, "..") && ((folders.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)) { std::string folderName(folders.cFileName); folderList.push_back(normalizedFolder + folderName); } } while (FindNextFile(folderSearch, &folders)); FindClose(folderSearch); } } WIN32_FIND_DATA data = { }; HANDLE search = FindFirstFile(searchPath.c_str(), &data); if (search != INVALID_HANDLE_VALUE) { do { if (strcmp(data.cFileName, ".") && strcmp(data.cFileName, "..")) { std::string fileName(data.cFileName); list.push_back(normalizedFolder + fileName); } } while (FindNextFile(search, &data)); FindClose(search); } if (recursive) { for (const std::string& i : folderList) findFiles(i, mask, recursive, list); } }
// GetParentFolderName(_T("C:\\RootFolder\\ChildFolder\\")); return C:\RootFolder\ // GetParentFolderName(_T("C:\\RootFolder\\ChildFolder\\readme.txt")); return C:\RootFolder\ChildFolder\ // GetParentFolderName(_T("RootFolder\\")); return .\ // The last char is always '\' in the return value. CString GetParentFolderName(const CString& fileOrFolderName) { CString tempName = fileOrFolderName; WCHAR lastChar = tempName.GetAt(tempName.GetLength() - 1); if(lastChar == _T('\\')) tempName.Truncate(tempName.GetLength() - 1); // delete the last '\' int lastPos = tempName.ReverseFind(_T('\\')); CString folderName(_T(".\\")); // current directory if(lastPos != -1) folderName = tempName.Left(lastPos + 1); return folderName; }
nsresult nsEudoraFilters::Init() { nsresult rv; nsCOMPtr<nsIMsgAccountManager> accMgr = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr <nsIMsgIncomingServer> server; rv = accMgr->GetLocalFoldersServer(getter_AddRefs(server)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr <nsIMsgFolder> localRootFolder; rv = server->GetRootMsgFolder(getter_AddRefs(localRootFolder)); NS_ENSURE_SUCCESS(rv, rv); // we need to call GetSubFolders() so that the folders get initialized // if they are not initialized yet. nsCOMPtr<nsISimpleEnumerator> enumerator; rv = localRootFolder->GetSubFolders(getter_AddRefs(enumerator)); NS_ENSURE_SUCCESS(rv, rv); // Get the name of the folder where one-off imported mail is placed nsAutoString folderName(NS_LITERAL_STRING("Eudora Import")); nsCOMPtr<nsIStringBundleService> bundleService = mozilla::services::GetStringBundleService(); NS_ENSURE_TRUE(bundleService, NS_ERROR_UNEXPECTED); nsCOMPtr<nsIStringBundle> bundle; rv = bundleService->CreateBundle("chrome://messenger/locale/importMsgs.properties", getter_AddRefs(bundle)); if (NS_SUCCEEDED(rv)) { nsAutoString Eudora(NS_LITERAL_STRING("Eudora")); const char16_t *moduleName[] = { Eudora.get() }; rv = bundle->FormatStringFromName(MOZ_UTF16("ImportModuleFolderName"), moduleName, 1, getter_Copies(folderName)); } localRootFolder->GetChildNamed(folderName, getter_AddRefs(m_pMailboxesRoot)); if (!m_pMailboxesRoot) { // If no "Eudora Import" folder then this is a // migration which just puts it in the root m_pMailboxesRoot = localRootFolder; } return rv; }
QString CJobRunner::errorString(int value) const { Misc::TFont font(FC::decode(*itsIt)); QString urlStr; if(CMD_REMOVE_FILE==itsCmd) urlStr=(*itsIt).fileName; else if(font.family.isEmpty()) urlStr=(*itsIt).prettyUrl(); else urlStr=FC::createName(font.family, font.styleInfo); switch(value) { case constDownloadFailed: return i18n("Failed to download <i>%1</i>", urlStr); case FontInst::STATUS_SERVICE_DIED: return i18n("System backend died. Please try again.<br><i>%1</i>", urlStr); case FontInst::STATUS_BITMAPS_DISABLED: return i18n("<i>%1</i> is a bitmap font, and these have been disabled on your system.", urlStr); case FontInst::STATUS_ALREADY_INSTALLED: return i18n("<i>%1</i> contains the font <b>%2</b>, which is already installed on your system.", urlStr, FC::getName(itsCurrentFile)); case FontInst::STATUS_NOT_FONT_FILE: return i18n("<i>%1</i> is not a font.", urlStr); case FontInst::STATUS_PARTIAL_DELETE: return i18n("Could not remove all files associated with <i>%1</i>", urlStr); case FontInst::STATUS_NO_SYS_CONNECTION: return i18n("Failed to start the system daemon.<br><i>%1</i>", urlStr); case KIO::ERR_FILE_ALREADY_EXIST: { QString name(Misc::modifyName(Misc::getFile((*itsIt).fileName))), destFolder(Misc::getDestFolder(folderName(itsDestIsSystem), name)); return i18n("<i>%1</i> already exists.", destFolder+name); } case KIO::ERR_DOES_NOT_EXIST: return i18n("<i>%1</i> does not exist.", urlStr); case KIO::ERR_WRITE_ACCESS_DENIED: return i18n("Permission denied.<br><i>%1</i>", urlStr); case KIO::ERR_UNSUPPORTED_ACTION: return i18n("Unsupported action.<br><i>%1</i>", urlStr); case KIO::ERR_COULD_NOT_AUTHENTICATE: return i18n("Authentication failed.<br><i>%1</i>", urlStr); default: return i18n("Unexpected error while processing: <i>%1</i>", urlStr); } }
PRBool nsImapOfflineSync::CreateOfflineFolder(nsIMsgFolder *folder) { nsCOMPtr<nsIMsgFolder> parent; folder->GetParent(getter_AddRefs(parent)); nsCOMPtr <nsIMsgImapMailFolder> imapFolder = do_QueryInterface(parent); nsCOMPtr <nsIURI> createFolderURI; nsCString onlineName; imapFolder->GetOnlineName(onlineName); NS_ConvertASCIItoUTF16 folderName(onlineName); nsresult rv = imapFolder->PlaybackOfflineFolderCreate(folderName, nsnull, getter_AddRefs(createFolderURI)); if (createFolderURI && NS_SUCCEEDED(rv)) { nsCOMPtr <nsIMsgMailNewsUrl> mailnewsUrl = do_QueryInterface(createFolderURI); if (mailnewsUrl) mailnewsUrl->RegisterListener(this); } return NS_SUCCEEDED(rv) ? PR_TRUE : PR_FALSE; // this is asynch, we have to return and be called again by the OfflineOpExitFunction }
// ----------------------------------------------------------------------------- // CDirectoryDesc::Open // Constructs Directory Descriptor // ----------------------------------------------------------------------------- TInt CDirectoryDesc::Open(RFs& aSession, const TDesC& aName, int mode, int /*perms*/) { //Save name of the directory iDirName = aName; TFileName folderName(aName); //Check whether dir name is appended with \ or not TPtrC right = folderName.Right(1); _LIT(KSlash, "\\"); if( right != KSlash) { folderName.Append(KSlash); } TInt err = KErrDirectoryOpen; if( mode == O_RDONLY ) { err = iDir.Open( aSession, folderName, KEntryAttMaskSupported); iFcntlFlag = mode & O_ACCMODE; } return err; }
generic_string getFolderName(HWND parent, const TCHAR *defaultDir) { generic_string folderName(TEXT("")); LPMALLOC pShellMalloc = 0; if (::SHGetMalloc(&pShellMalloc) == NO_ERROR) { BROWSEINFO info; memset(&info, 0, sizeof(info)); info.hwndOwner = parent; info.pidlRoot = NULL; TCHAR szDisplayName[MAX_PATH]; info.pszDisplayName = szDisplayName; info.lpszTitle = TEXT("Select a folder"); info.ulFlags = 0; info.lpfn = BrowseCallbackProc; info.lParam = reinterpret_cast<LPARAM>(defaultDir); // Execute the browsing dialog. LPITEMIDLIST pidl = ::SHBrowseForFolder(&info); // pidl will be null if they cancel the browse dialog. // pidl will be not null when they select a folder. if (pidl) { // Try to convert the pidl to a display generic_string. // Return is true if success. TCHAR szDir[MAX_PATH]; if (::SHGetPathFromIDList(pidl, szDir)) // Set edit control to the directory path. folderName = szDir; pShellMalloc->Free(pidl); } pShellMalloc->Release(); } return folderName; }
/* * Reads a file (given a file name) and compresses it * Returns the file extension for every compressed file name */ char *readFile(char file[]){ numCols = 0; snprintf(col_path,BUFF_SIZE,"%s%s",file,"/col_"); size = 0; mut = PTHREAD_MUTEX_INITIALIZER;//initialize mutex for locking threads char *folder = folderName(file);//make a folder for the compressed files mkdir(folder); compressed_folder = (char *) malloc(sizeof(char)*BUFF_SIZE); snprintf(compressed_folder,BUFF_SIZE,"%s%s",folder,"/col_");//build the generic file name we used (to return for querying) if(RUN_COMPRESSION==0) return compressed_folder; int i; for(i=0;i<NUM_THREADS;i++){ id[i]=i; } runOverhead(); threads = (pthread_t *) malloc(sizeof(pthread_t) * NUM_THREADS);//allocate each thread pointer printf("Start threaded compression\n"); time_t start = clock(); if(FORMAT_TYPE == UNSTRIPED) compressUnstriped();//start compression else if(FORMAT_TYPE == STRIPED) compressStriped(); time_t end = clock(); unsigned long total = (unsigned long) (end-start); printf("End threaded compression\n"); printf("Compression time: %lu\n",total); return compressed_folder; }
nsresult nsOutlookMail::ImportMailbox(uint32_t *pDoneSoFar, bool *pAbort, int32_t index, const PRUnichar *pName, nsIMsgFolder *dstFolder, int32_t *pMsgCount) { if ((index < 0) || (index >= m_folderList.GetSize())) { IMPORT_LOG0("*** Bad mailbox identifier, unable to import\n"); *pAbort = true; return NS_ERROR_FAILURE; } int32_t dummyMsgCount = 0; if (pMsgCount) *pMsgCount = 0; else pMsgCount = &dummyMsgCount; CMapiFolder *pFolder = m_folderList.GetItem(index); OpenMessageStore(pFolder); if (!m_lpMdb) { IMPORT_LOG1("*** Unable to obtain mapi message store for mailbox: %S\n", pName); return NS_ERROR_FAILURE; } if (pFolder->IsStore()) return NS_OK; // now what? CMapiFolderContents contents(m_lpMdb, pFolder->GetCBEntryID(), pFolder->GetEntryID()); BOOL done = FALSE; ULONG cbEid; LPENTRYID lpEid; ULONG oType; LPMESSAGE lpMsg = nullptr; ULONG totalCount; double doneCalc; nsCOMPtr<nsIOutputStream> outputStream; nsCOMPtr<nsIMsgPluggableStore> msgStore; nsresult rv = dstFolder->GetMsgStore(getter_AddRefs(msgStore)); NS_ENSURE_SUCCESS(rv, rv); while (!done) { if (!contents.GetNext(&cbEid, &lpEid, &oType, &done)) { IMPORT_LOG1("*** Error iterating mailbox: %S\n", pName); return NS_ERROR_FAILURE; } nsCOMPtr<nsIMsgDBHdr> msgHdr; bool reusable; rv = msgStore->GetNewMsgOutputStream(dstFolder, getter_AddRefs(msgHdr), &reusable, getter_AddRefs(outputStream)); totalCount = contents.GetCount(); doneCalc = *pMsgCount; doneCalc /= totalCount; doneCalc *= 1000; if (pDoneSoFar) { *pDoneSoFar = (uint32_t) doneCalc; if (*pDoneSoFar > 1000) *pDoneSoFar = 1000; } if (!done && (oType == MAPI_MESSAGE)) { if (!m_mapi.OpenMdbEntry(m_lpMdb, cbEid, lpEid, (LPUNKNOWN *) &lpMsg)) { IMPORT_LOG1("*** Error opening messages in mailbox: %S\n", pName); return NS_ERROR_FAILURE; } // See if it's a drafts folder. Outlook doesn't allow drafts // folder to be configured so it's ok to hard code it here. nsAutoString folderName(pName); nsMsgDeliverMode mode = nsIMsgSend::nsMsgDeliverNow; mode = nsIMsgSend::nsMsgSaveAsDraft; if (folderName.LowerCaseEqualsLiteral("drafts")) mode = nsIMsgSend::nsMsgSaveAsDraft; rv = ImportMessage(lpMsg, outputStream, mode); if (NS_SUCCEEDED(rv)){ // No errors & really imported (*pMsgCount)++; msgStore->FinishNewMessage(outputStream, msgHdr); } else { IMPORT_LOG1( "*** Error reading message from mailbox: %S\n", pName); msgStore->DiscardNewMessage(outputStream, msgHdr); } if (!reusable) outputStream->Close(); } } if (outputStream) outputStream->Close(); return NS_OK; }
void CFileBrowserEngine::GetCurrentItemsL(CDesCArray* aItems) { __LOGSTR_TOFILE("CFileBrowserEngine::GetCurrentItemsL() begins"); aItems->Reset(); // If the current directory is not the first one, // add '...' entry as the first element of the listbox if (iCurrentDirectory.Length() > 0) { TFileName upperLevel(KNullDesC); upperLevel.Format(KStringUp, 2); aItems->AppendL(upperLevel); } // Retrieve folders names TFileName folderName(KNullDesC); if (iCurrentDirectory.Length() == 0) { // Get CCoeEnv instance CEikonEnv* eikonEnv = CEikonEnv::Static(); HBufC* stringHolder1 = StringLoader::LoadL(R_FILEBROWSER_PHONEMEMORY, eikonEnv ); HBufC* stringHolder2 = StringLoader::LoadL(R_FILEBROWSER_CARDMEMORY, eikonEnv ); for (TInt i = 0; i < iCurrentFolders.Count(); i++) { // As icon we use folder icon (index 0) if ( i == 0) { TFileName fileName = iCurrentFolders[i].iName; fileName.Append(*stringHolder1); folderName.Format(KStringIcon, 3, &fileName); } else { TFileName fileName = iCurrentFolders[i].iName; fileName.Append(*stringHolder2); folderName.Format(KStringIcon, 4, &fileName); } aItems->AppendL(folderName); } delete stringHolder2; stringHolder2 = NULL; delete stringHolder1; stringHolder1 = NULL; } else { for (TInt i = 0; i < iCurrentFolders.Count(); i++) { // As icon we use folder icon (index 0) folderName.Format(KStringIcon, 0, &iCurrentFolders[i].iName); aItems->AppendL(folderName); } } // Retrieve files names TFileName fileName(KNullDesC); for (TInt i = 0; i < iCurrentFiles.Count(); i++) { // As folder we use file icon (index 1) fileName.Format(KStringIcon, 1, &iCurrentFiles[i].iName); aItems->AppendL(fileName); } __LOGSTR_TOFILE("CFileBrowserEngine::GetCurrentItemsL() ends"); }
nsresult nsOutlookMail::ImportMailbox( PRUint32 *pDoneSoFar, bool *pAbort, PRInt32 index, const PRUnichar *pName, nsIFile *pDest, PRInt32 *pMsgCount) { if ((index < 0) || (index >= m_folderList.GetSize())) { IMPORT_LOG0( "*** Bad mailbox identifier, unable to import\n"); *pAbort = PR_TRUE; return( NS_ERROR_FAILURE); } PRInt32 dummyMsgCount = 0; if (pMsgCount) *pMsgCount = 0; else pMsgCount = &dummyMsgCount; CMapiFolder *pFolder = m_folderList.GetItem( index); OpenMessageStore( pFolder); if (!m_lpMdb) { IMPORT_LOG1( "*** Unable to obtain mapi message store for mailbox: %S\n", pName); return( NS_ERROR_FAILURE); } if (pFolder->IsStore()) return( NS_OK); nsresult rv; // now what? CMapiFolderContents contents( m_lpMdb, pFolder->GetCBEntryID(), pFolder->GetEntryID()); BOOL done = FALSE; ULONG cbEid; LPENTRYID lpEid; ULONG oType; LPMESSAGE lpMsg = nsnull; ULONG totalCount; PRFloat64 doneCalc; nsCOMPtr<nsIOutputStream> destOutputStream; rv = MsgNewBufferedFileOutputStream(getter_AddRefs(destOutputStream), pDest, -1, 0600); NS_ENSURE_SUCCESS(rv, rv); while (!done) { if (!contents.GetNext( &cbEid, &lpEid, &oType, &done)) { IMPORT_LOG1( "*** Error iterating mailbox: %S\n", pName); return( NS_ERROR_FAILURE); } totalCount = contents.GetCount(); doneCalc = *pMsgCount; doneCalc /= totalCount; doneCalc *= 1000; if (pDoneSoFar) { *pDoneSoFar = (PRUint32) doneCalc; if (*pDoneSoFar > 1000) *pDoneSoFar = 1000; } if (!done && (oType == MAPI_MESSAGE)) { if (!m_mapi.OpenMdbEntry( m_lpMdb, cbEid, lpEid, (LPUNKNOWN *) &lpMsg)) { IMPORT_LOG1( "*** Error opening messages in mailbox: %S\n", pName); return( NS_ERROR_FAILURE); } // See if it's a drafts folder. Outlook doesn't allow drafts // folder to be configured so it's ok to hard code it here. nsAutoString folderName(pName); nsMsgDeliverMode mode = nsIMsgSend::nsMsgDeliverNow; mode = nsIMsgSend::nsMsgSaveAsDraft; if ( folderName.LowerCaseEqualsLiteral("drafts") ) mode = nsIMsgSend::nsMsgSaveAsDraft; rv = ImportMessage(lpMsg, destOutputStream, mode); if (NS_SUCCEEDED( rv)) // No errors & really imported (*pMsgCount)++; else { IMPORT_LOG1( "*** Error reading message from mailbox: %S\n", pName); } } } return( NS_OK); }
nsresult nsOutlookMail::ImportMailbox( PRUint32 *pDoneSoFar, PRBool *pAbort, PRInt32 index, const PRUnichar *pName, nsIFile *pDest, PRInt32 *pMsgCount) { if ((index < 0) || (index >= m_folderList.GetSize())) { IMPORT_LOG0( "*** Bad mailbox identifier, unable to import\n"); *pAbort = PR_TRUE; return( NS_ERROR_FAILURE); } PRInt32 dummyMsgCount = 0; if (pMsgCount) *pMsgCount = 0; else pMsgCount = &dummyMsgCount; CMapiFolder *pFolder = m_folderList.GetItem( index); OpenMessageStore( pFolder); if (!m_lpMdb) { IMPORT_LOG1( "*** Unable to obtain mapi message store for mailbox: %S\n", pName); return( NS_ERROR_FAILURE); } if (pFolder->IsStore()) return( NS_OK); nsresult rv; nsOutlookCompose compose; SimpleBufferTonyRCopiedTwice copy; copy.Allocate( kCopyBufferSize); // now what? CMapiFolderContents contents( m_lpMdb, pFolder->GetCBEntryID(), pFolder->GetEntryID()); BOOL done = FALSE; ULONG cbEid; LPENTRYID lpEid; ULONG oType; LPMESSAGE lpMsg = nsnull; int attachCount; ULONG totalCount; PRFloat64 doneCalc; nsCString fromLine; int fromLen; PRBool lostAttach = PR_FALSE; nsCOMPtr<nsIOutputStream> destOutputStream; rv = NS_NewLocalFileOutputStream(getter_AddRefs(destOutputStream), pDest, -1, 0600); NS_ENSURE_SUCCESS(rv, rv); while (!done) { if (!contents.GetNext( &cbEid, &lpEid, &oType, &done)) { IMPORT_LOG1( "*** Error iterating mailbox: %S\n", pName); return( NS_ERROR_FAILURE); } totalCount = contents.GetCount(); doneCalc = *pMsgCount; doneCalc /= totalCount; doneCalc *= 1000; if (pDoneSoFar) { *pDoneSoFar = (PRUint32) doneCalc; if (*pDoneSoFar > 1000) *pDoneSoFar = 1000; } if (!done && (oType == MAPI_MESSAGE)) { if (!m_mapi.OpenMdbEntry( m_lpMdb, cbEid, lpEid, (LPUNKNOWN *) &lpMsg)) { IMPORT_LOG1( "*** Error opening messages in mailbox: %S\n", pName); return( NS_ERROR_FAILURE); } CMapiMessage msg( lpMsg); BOOL bResult = msg.FetchHeaders(); if (bResult) bResult = msg.FetchBody(); if (bResult) fromLine = msg.GetFromLine( fromLen); attachCount = msg.CountAttachments(); BuildAttachments( msg, attachCount); if (!bResult) { IMPORT_LOG1( "*** Error reading message from mailbox: %S\n", pName); return( NS_ERROR_FAILURE); } // -------------------------------------------------------------- compose.SetBody( msg.GetBody()); // Need to convert all headers to unicode (for i18n). // Init header here since 'composes' is used for all msgs. compose.SetHeaders(""); nsAutoString newheader; nsCAutoString tempCStr(msg.GetHeaders(), msg.GetHeaderLen()); rv = nsMsgI18NConvertToUnicode(nsMsgI18NFileSystemCharset(), tempCStr, newheader); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to convert headers to utf8"); if (NS_SUCCEEDED(rv)) compose.SetHeaders(NS_ConvertUTF16toUTF8(newheader).get()); compose.SetAttachments( &m_attachments); // See if it's a drafts folder. Outlook doesn't allow drafts // folder to be configured so it's ok to hard code it here. nsAutoString folderName(pName); nsMsgDeliverMode mode = nsIMsgSend::nsMsgDeliverNow; mode = nsIMsgSend::nsMsgSaveAsDraft; if ( folderName.LowerCaseEqualsLiteral("drafts") ) mode = nsIMsgSend::nsMsgSaveAsDraft; /* If I can't get no headers, I can't get no satisfaction */ if (msg.GetHeaderLen()) { nsCAutoString cType; SetDefaultContentType(msg, cType); nsCOMPtr<nsIFile> compositionFile; rv = compose.SendTheMessage(mode, cType, getter_AddRefs(compositionFile)); if (NS_SUCCEEDED( rv)) { rv = compose.CopyComposedMessage( fromLine, compositionFile, destOutputStream, copy); DeleteFile( compositionFile); if (NS_FAILED( rv)) { IMPORT_LOG0( "*** Error copying composed message to destination mailbox\n"); return( rv); } (*pMsgCount)++; } } else rv = NS_OK; // The following code to write msg to folder when compose.SendTheMessage() fails is commented // out for now because the code doesn't handle attachments and users will complain anyway so // until we fix the code to handle all kinds of msgs correctly we should not even make users // think that all msgs are imported ok. This will also help users to identify which msgs are // not imported and help to debug the problem. #if 0 if (NS_FAILED( rv)) { /* NS_PRECONDITION( FALSE, "Manual breakpoint"); */ IMPORT_LOG1( "Message #%d failed.\n", (int) (*pMsgCount)); DumpAttachments(); // -------------------------------------------------------------- // This is the OLD way of writing out the message which uses // all kinds of crufty old crap for attachments. // Since we now use Compose to send attachments, // this is only fallback error stuff. // Attachments get lost. if (attachCount) { lostAttach = PR_TRUE; attachCount = 0; } BOOL needsTerminate = FALSE; if (!WriteMessage( destOutputStream, &msg, attachCount, &needsTerminate)) { IMPORT_LOG0( "*** Error writing message\n"); *pAbort = PR_TRUE; return( NS_ERROR_FAILURE); } if (needsTerminate) { if (!WriteMimeBoundary( destOutputStream, &msg, TRUE)) { IMPORT_LOG0( "*** Error writing message mime boundary\n"); *pAbort = PR_TRUE; return( NS_ERROR_FAILURE); } } } #endif // Just for YUCKS, let's try an extra endline WriteData( destOutputStream, "\x0D\x0A", 2); } } return( NS_OK); }