Back to index

lightning-sunbird  0.9+nobinonly
Static Public Member Functions | Static Public Attributes
nsMapiHook Class Reference

#include <msgMapiHook.h>

List of all members.

Static Public Member Functions

static PRBool Initialize ()
static PRBool DisplayLoginDialog (PRBool aLogin, PRUnichar **aUsername, PRUnichar **aPassword)
static PRBool VerifyUserName (const PRUnichar *aUsername, char **aIdKey)
static PRBool IsBlindSendAllowed ()
static nsresult BlindSendMail (unsigned long aSession, nsIMsgCompFields *aCompFields)
static nsresult ShowComposerWindow (unsigned long aSession, nsIMsgCompFields *aCompFields)
static nsresult PopulateCompFields (lpnsMapiMessage aMessage, nsIMsgCompFields *aCompFields)
static nsresult PopulateCompFieldsWithConversion (lpnsMapiMessage aMessage, nsIMsgCompFields *aCompFields)
static nsresult PopulateCompFieldsForSendDocs (nsIMsgCompFields *aCompFields, ULONG aFlags, LPTSTR aDelimChar, LPTSTR aFilePaths)
static nsresult HandleAttachments (nsIMsgCompFields *aCompFields, PRInt32 aFileCount, lpnsMapiFileDesc aFiles, BOOL aIsUnicode)
static void CleanUp ()

Static Public Attributes

static PRBool isMapiService = PR_FALSE

Detailed Description

Definition at line 42 of file msgMapiHook.h.


Member Function Documentation

nsresult nsMapiHook::BlindSendMail ( unsigned long  aSession,
nsIMsgCompFields aCompFields 
) [static]

create nsIMsgComposeParams obj and other fields to populate it

initialize nsIMsgCompose, Send the message, wait for send completion response

Definition at line 345 of file msgMapiHook.cpp.

{
    nsresult rv = NS_OK ;

    if (!IsBlindSendAllowed())
        return NS_ERROR_FAILURE;

    nsCOMPtr<nsIDOMWindowInternal>  hiddenWindow;
    // get parent window
    nsCOMPtr<nsIAppShellService> appService = do_GetService( "@mozilla.org/appshell/appShellService;1", &rv);
    if (NS_FAILED(rv)|| (!appService) ) return rv ;

    rv = appService->GetHiddenDOMWindow(getter_AddRefs(hiddenWindow));
    if ( NS_FAILED(rv) ) return rv ;
    // smtp password and Logged in used IdKey from MapiConfig (session obj)
    nsMAPIConfiguration * pMapiConfig = nsMAPIConfiguration::GetMAPIConfiguration() ;
    if (!pMapiConfig) return NS_ERROR_FAILURE ;  // get the singelton obj
    PRUnichar * password = pMapiConfig->GetPassword(aSession) ;
    // password
    nsCAutoString smtpPassword ;
    smtpPassword.AssignWithConversion (password) ;
    // Id key
    char * MsgIdKey = pMapiConfig->GetIdKey(aSession) ;

    // get the MsgIdentity for the above key using AccountManager
    nsCOMPtr <nsIMsgAccountManager> accountManager = do_GetService (NS_MSGACCOUNTMANAGER_CONTRACTID) ;
    if (NS_FAILED(rv) || (!accountManager) ) return rv ;

    nsCOMPtr <nsIMsgIdentity> pMsgId ;
    rv = accountManager->GetIdentity (MsgIdKey, getter_AddRefs(pMsgId)) ;
    if (NS_FAILED(rv) ) return rv ;

    // create a send listener to get back the send status
    nsCOMPtr <nsIMsgSendListener> sendListener ;
    rv = nsMAPISendListener::CreateMAPISendListener(getter_AddRefs(sendListener)) ; 
    if (NS_FAILED(rv) || (!sendListener) ) return rv;

    // create the compose params object 
    nsCOMPtr<nsIMsgComposeParams> pMsgComposeParams (do_CreateInstance(NS_MSGCOMPOSEPARAMS_CONTRACTID, &rv));
    if (NS_FAILED(rv) || (!pMsgComposeParams) ) return rv ;

    // populate the compose params
    PRBool forcePlainText;
    aCompFields->GetForcePlainText(&forcePlainText);
    pMsgComposeParams->SetType(nsIMsgCompType::New);
    pMsgComposeParams->SetFormat(forcePlainText ? nsIMsgCompFormat::PlainText : nsIMsgCompFormat::HTML);
    pMsgComposeParams->SetIdentity(pMsgId);
    pMsgComposeParams->SetComposeFields(aCompFields); 
    pMsgComposeParams->SetSendListener(sendListener) ;
    pMsgComposeParams->SetSmtpPassword(smtpPassword.get());

    // create the nsIMsgCompose object to send the object
    nsCOMPtr<nsIMsgCompose> pMsgCompose (do_CreateInstance(NS_MSGCOMPOSE_CONTRACTID, &rv));
    if (NS_FAILED(rv) || (!pMsgCompose) ) return rv ;

    rv = pMsgCompose->Initialize(hiddenWindow, pMsgComposeParams) ;
    if (NS_FAILED(rv)) return rv ;

    return pMsgCompose->SendMsg(nsIMsgSend::nsMsgDeliverNow, pMsgId, nsnull, nsnull, nsnull) ;
    if (NS_FAILED(rv)) return rv ;

    // assign to interface pointer from nsCOMPtr to facilitate typecast below
    nsIMsgSendListener * pSendListener = sendListener ;  

    // we need to wait here to make sure that we return only after send is completed
    // so we will have a event loop here which will process the events till the Send IsDone.
    nsCOMPtr<nsIEventQueueService> pEventQService = do_GetService(NS_EVENTQUEUESERVICE_CONTRACTID, &rv);
    nsCOMPtr<nsIEventQueue> eventQueue;
    pEventQService->GetThreadEventQueue(NS_CURRENT_THREAD,getter_AddRefs(eventQueue));
    while ( !((nsMAPISendListener *) pSendListener)->IsDone() )
    {
        PR_CEnterMonitor(pSendListener);
        PR_CWait(pSendListener, PR_MicrosecondsToInterval(1000UL));
        PR_CExitMonitor(pSendListener);
        eventQueue->ProcessPendingEvents();
    }

    return rv ;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsMapiHook::CleanUp ( void  ) [static]

Definition at line 182 of file msgMapiHook.cpp.

{
    // This routine will be fully implemented in future
    // to cleanup mapi related stuff inside mozilla code.
}
PRBool nsMapiHook::DisplayLoginDialog ( PRBool  aLogin,
PRUnichar **  aUsername,
PRUnichar **  aPassword 
) [static]

Definition at line 188 of file msgMapiHook.cpp.

{
    nsresult rv;
    PRBool btnResult = PR_FALSE;
   
    nsCOMPtr<nsIPromptService> dlgService(do_GetService(NS_PROMPTSERVICE_CONTRACTID, &rv));
    if (NS_SUCCEEDED(rv) && dlgService)
    {
        nsCOMPtr<nsIStringBundleService> bundleService(do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv));
        if (NS_FAILED(rv) || !bundleService) return PR_FALSE;

        nsCOMPtr<nsIStringBundle> bundle;
        rv = bundleService->CreateBundle(MAPI_PROPERTIES_CHROME, getter_AddRefs(bundle));
        if (NS_FAILED(rv) || !bundle) return PR_FALSE;

        nsCOMPtr<nsIStringBundle> brandBundle;
        rv = bundleService->CreateBundle(
                        "chrome://branding/locale/brand.properties",
                        getter_AddRefs(brandBundle));
        if (NS_FAILED(rv)) return PR_FALSE;

        nsXPIDLString brandName;
        rv = brandBundle->GetStringFromName(
                           NS_LITERAL_STRING("brandFullName").get(),
                           getter_Copies(brandName));
        if (NS_FAILED(rv)) return PR_FALSE;
        
        nsXPIDLString loginTitle;
        const PRUnichar *brandStrings[] = { brandName.get() };
        NS_NAMED_LITERAL_STRING(loginTitlePropertyTag, "loginTitle");
        const PRUnichar *dTitlePropertyTag = loginTitlePropertyTag.get();
        rv = bundle->FormatStringFromName(dTitlePropertyTag, brandStrings, 1,
                                          getter_Copies(loginTitle));
        if (NS_FAILED(rv)) return PR_FALSE;
        
        if (aLogin)
        {
            nsXPIDLString loginText;
            rv = bundle->GetStringFromName(NS_LITERAL_STRING("loginTextwithName").get(),
                                           getter_Copies(loginText));
            if (NS_FAILED(rv) || !loginText) return PR_FALSE;

            rv = dlgService->PromptUsernameAndPassword(nsnull, loginTitle,
                                                       loginText, aUsername, aPassword,
                                                       nsnull, PR_FALSE, &btnResult);
        }
        else
        {
            //nsString loginString; 
            nsXPIDLString loginText;
            const PRUnichar *userNameStrings[] = { *aUsername };

            NS_NAMED_LITERAL_STRING(loginTextPropertyTag, "loginText");
            const PRUnichar *dpropertyTag = loginTextPropertyTag.get();
            rv = bundle->FormatStringFromName(dpropertyTag, userNameStrings, 1,
                                              getter_Copies(loginText));
            if (NS_FAILED(rv)) return PR_FALSE;

            rv = dlgService->PromptPassword(nsnull, loginTitle, loginText,
                                            aPassword, nsnull, PR_FALSE, &btnResult);
        }
    }            

    return btnResult;
}

Here is the call graph for this function:

nsresult nsMapiHook::HandleAttachments ( nsIMsgCompFields aCompFields,
PRInt32  aFileCount,
lpnsMapiFileDesc  aFiles,
BOOL  aIsUnicode 
) [static]

Definition at line 526 of file msgMapiHook.cpp.

{
    nsresult rv = NS_OK ;

    nsCAutoString Attachments ;
    nsCAutoString TempFiles ;

    nsCOMPtr <nsILocalFile> pFile = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID, &rv) ;
    if (NS_FAILED(rv) || (!pFile) ) return rv ;        
    nsCOMPtr <nsILocalFile> pTempDir = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID, &rv) ;
    if (NS_FAILED(rv) || (!pTempDir) ) return rv ;        

    for (int i=0 ; i < aFileCount ; i++)
    {
        PRBool bTempFile = PR_FALSE ;
        if (aFiles[i].lpszPathName)
        {
            // check if attachment exists
            if (aIsUnicode)
                pFile->InitWithPath (nsDependentString(aFiles[i].lpszPathName)); 
            else
                pFile->InitWithNativePath (nsDependentCString((const char*)aFiles[i].lpszPathName)); 

            PRBool bExist ;
            rv = pFile->Exists(&bExist) ;
            PR_LOG(MAPI, PR_LOG_DEBUG, ("nsMapiHook::HandleAttachments: filename: %s path: %s exists = %s \n", (const char*)aFiles[i].lpszFileName, (const char*)aFiles[i].lpszPathName, bExist ? "true" : "false"));
            if (NS_FAILED(rv) || (!bExist) ) return NS_ERROR_FILE_TARGET_DOES_NOT_EXIST ;

            //Temp Directory
            nsCOMPtr <nsIFile> pTempFileDir;
            NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(pTempFileDir));
            nsCOMPtr <nsILocalFile> pTempDir = do_QueryInterface(pTempFileDir);

            // create a new sub directory called moz_mapi underneath the temp directory
            pTempDir->AppendRelativePath(NS_LITERAL_STRING("moz_mapi"));
            pTempDir->Exists (&bExist) ;
            if (!bExist)
            {
                rv = pTempDir->Create(nsIFile::DIRECTORY_TYPE, 777) ;
                if (NS_FAILED(rv)) return rv ;
            }

            // rename or copy the existing temp file with the real file name
            
            nsAutoString leafName ;
            // convert to Unicode using Platform charset
            // leafName already contains a unicode leafName from lpszPathName. If we were given
            // a value for lpszFileName, use it. Otherwise stick with leafName
            if (aFiles[i].lpszFileName)
            {
              nsAutoString wholeFileName;
                if (aIsUnicode)
                    wholeFileName.Assign(aFiles[i].lpszFileName);
                else
                    ConvertToUnicode(nsMsgI18NFileSystemCharset(), (char *) aFiles[i].lpszFileName, wholeFileName);
                // need to find the last '\' and find the leafname from that.
                PRInt32 lastSlash = wholeFileName.RFindChar(PRUnichar('\\'));
                if (lastSlash != kNotFound)
                  wholeFileName.Right(leafName, wholeFileName.Length() - lastSlash - 1);
                else
                  leafName.Assign(wholeFileName);
            }
            else 
              pFile->GetLeafName (leafName);

             nsCOMPtr <nsIFile> pTempFile;
             rv = pTempDir->Clone(getter_AddRefs(pTempFile));
             if (NS_FAILED(rv) || (!pTempFile) ) 
               return rv;
 
             pTempFile->Append(leafName);
             pTempFile->Exists(&bExist);
             if (bExist)
             {
               rv = pTempFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0777);
               NS_ENSURE_SUCCESS(rv, rv);
               pTempFile->Remove(PR_FALSE); // remove so we can copy over it.
             }
            // copy the file to its new location and file name
            pFile->CopyTo(pTempDir, leafName);
            // point pFile to the new location of the attachment
            pFile->InitWithFile(pTempDir); 
            pFile->Append(leafName);

            // create MsgCompose attachment object
            nsCOMPtr<nsIMsgAttachment> attachment = do_CreateInstance(NS_MSGATTACHMENT_CONTRACTID, &rv);
            NS_ENSURE_SUCCESS(rv, rv);
            attachment->SetTemporary(PR_TRUE); // this one is a temp file so set the flag for MsgCompose

            // now set the attachment object
            nsCAutoString pURL ;
            NS_GetURLSpecFromFile(pFile, pURL);
            attachment->SetUrl(pURL.get()) ;

            // add the attachment
            rv = aCompFields->AddAttachment (attachment);
            if (NS_FAILED(rv))
              PR_LOG(MAPI, PR_LOG_DEBUG, ("nsMapiHook::HandleAttachments: AddAttachment rv =  %lx\n", rv));
        }
    }
    return rv ;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 162 of file msgMapiHook.cpp.

{
#ifndef MOZ_THUNDERBIRD 
    nsresult rv;
    nsCOMPtr<nsINativeAppSupport> native;
    nsCOMPtr<nsICmdLineService> cmdLineArgs (do_GetService(NS_COMMANDLINESERVICE_CONTRACTID, &rv));
    if (NS_FAILED(rv)) return PR_FALSE; 

    nsCOMPtr<nsIAppStartup> appStartup (do_GetService(NS_APPSTARTUP_CONTRACTID, &rv));
    if (NS_FAILED(rv)) return PR_FALSE; 

    rv = appStartup->GetNativeAppSupport(getter_AddRefs(native)); 
    if (NS_FAILED(rv)) return PR_FALSE;

    rv = native->EnsureProfile(cmdLineArgs);
    if (NS_FAILED(rv)) return PR_FALSE;
#endif
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 298 of file msgMapiHook.cpp.

{
    PRBool enabled = PR_FALSE;
    PRBool warn = PR_TRUE;
    nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID);
    if (prefBranch) {
        prefBranch->GetBoolPref(PREF_MAPI_WARN_PRIOR_TO_BLIND_SEND, &warn);
        prefBranch->GetBoolPref(PREF_MAPI_BLIND_SEND_ENABLED, &enabled);
    } 
    if (!enabled)
        return PR_FALSE;

    if (!warn)
        return PR_TRUE; // Everything is okay.  

    nsresult rv;
    nsCOMPtr<nsIStringBundleService> bundleService(do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv));
    if (NS_FAILED(rv) || !bundleService) return PR_FALSE;

    nsCOMPtr<nsIStringBundle> bundle;
    rv = bundleService->CreateBundle(MAPI_PROPERTIES_CHROME, getter_AddRefs(bundle));
    if (NS_FAILED(rv) || !bundle) return PR_FALSE;

    nsXPIDLString warningMsg;
    rv = bundle->GetStringFromName(NS_LITERAL_STRING("mapiBlindSendWarning").get(),
                                        getter_Copies(warningMsg));
    if (NS_FAILED(rv)) return PR_FALSE;
    
       nsXPIDLString dontShowAgainMessage;
    rv = bundle->GetStringFromName(NS_LITERAL_STRING("mapiBlindSendDontShowAgain").get(),
                                        getter_Copies(dontShowAgainMessage));
    if (NS_FAILED(rv)) return PR_FALSE;

    nsCOMPtr<nsIPromptService> dlgService(do_GetService(NS_PROMPTSERVICE_CONTRACTID, &rv));
    if (NS_FAILED(rv) || !dlgService) return PR_FALSE;
    
    PRBool continueToWarn = PR_TRUE;
    PRBool okayToContinue = PR_FALSE;
    dlgService->ConfirmCheck(nsnull, nsnull, warningMsg, dontShowAgainMessage, &continueToWarn, &okayToContinue);
        
    if (!continueToWarn && okayToContinue && prefBranch)
        prefBranch->SetBoolPref(PREF_MAPI_WARN_PRIOR_TO_BLIND_SEND, PR_FALSE);
    
    return okayToContinue;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsMapiHook::PopulateCompFields ( lpnsMapiMessage  aMessage,
nsIMsgCompFields aCompFields 
) [static]

Definition at line 430 of file msgMapiHook.cpp.

{
    nsresult rv = NS_OK ;

    if (aMessage->lpOriginator)
    {
        char * From = aMessage->lpOriginator->lpszAddress ;
        nsAutoString FromStr; FromStr.AssignWithConversion(From);
        aCompFields->SetFrom (FromStr) ;
    }

    nsAutoString To ;
    nsAutoString Cc ; 
    nsAutoString Bcc ;

    NS_NAMED_LITERAL_STRING(Comma, ",") ;

    if (aMessage->lpRecips)
    {
        for (int i=0 ; i < (int) aMessage->nRecipCount ; i++)
        {
            if (aMessage->lpRecips[i].lpszAddress || aMessage->lpRecips[i].lpszName)
            {
                const char *addressWithoutType = (aMessage->lpRecips[i].lpszAddress)
                  ? aMessage->lpRecips[i].lpszAddress : aMessage->lpRecips[i].lpszName;
                if (!PL_strncasecmp(addressWithoutType, "SMTP:", 5))
                  addressWithoutType += 5;
                switch (aMessage->lpRecips[i].ulRecipClass)
                {
                case MAPI_TO :
                    if (!To.IsEmpty())
                        To += Comma ;
                    To.AppendWithConversion(addressWithoutType) ;
                    break ;

                case MAPI_CC :
                    if (!Cc.IsEmpty())
                        Cc += Comma ;
                    Cc.AppendWithConversion(addressWithoutType) ;
                    break ;

                case MAPI_BCC :
                    if (!Bcc.IsEmpty())
                        Bcc += Comma ;
                    Bcc.AppendWithConversion(addressWithoutType) ; 
                    break ;
                }
            }
        }
    }

    PR_LOG(MAPI, PR_LOG_DEBUG, ("to: %s cc: %s bcc: %s \n", NS_ConvertUCS2toUTF8(To).get(), NS_ConvertUCS2toUTF8(Cc).get(), NS_ConvertUCS2toUTF8(Bcc).get()));
    // set To, Cc, Bcc
    aCompFields->SetTo (To) ;
    aCompFields->SetCc (Cc) ;
    aCompFields->SetBcc (Bcc) ;

    // set subject
    if (aMessage->lpszSubject)
    {
        nsAutoString Subject;

        Subject.AssignWithConversion(aMessage->lpszSubject);
        aCompFields->SetSubject(Subject) ;
    }

    // handle attachments as File URL
    rv = HandleAttachments (aCompFields, aMessage->nFileCount, aMessage->lpFiles, PR_TRUE) ;
    if (NS_FAILED(rv)) return rv ;    

    // set body
    if (aMessage->lpszNoteText)
    {
        nsString Body;
        Body.AssignWithConversion(aMessage->lpszNoteText);
        if (Body.Last() != nsCRT::LF)
          Body.AppendLiteral(CRLF); 

        if (Body.Find("<html>") == kNotFound)
          aCompFields->SetForcePlainText(PR_TRUE);

        rv = aCompFields->SetBody(Body) ;
    }

#ifdef RAJIV_DEBUG
    // testing what all was set in CompFields
    printf ("To : %S \n", To.get()) ;
    printf ("CC : %S \n", Cc.get() ) ;
    printf ("BCC : %S \n", Bcc.get() ) ;
#endif

    return rv ;

}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsMapiHook::PopulateCompFieldsForSendDocs ( nsIMsgCompFields aCompFields,
ULONG  aFlags,
LPTSTR  aDelimChar,
LPTSTR  aFilePaths 
) [static]

Definition at line 736 of file msgMapiHook.cpp.

{
    nsAutoString strDelimChars ;
    nsString strFilePaths;
    nsresult rv = NS_OK ;
    PRBool bExist ;

    if (aFlags & MAPI_UNICODE)
    {
        if (aDelimChar)
            strDelimChars.Assign (aDelimChar) ;
        if (aFilePaths)
            strFilePaths.Assign (aFilePaths) ;
    }
    else
    {
        if (aDelimChar)
            strDelimChars.AssignWithConversion ((char*) aDelimChar) ;
        if (aFilePaths)
            strFilePaths.AssignWithConversion ((char *) aFilePaths) ;
    }

    // check for comma in filename 
    if (strDelimChars.Find (",") == kNotFound)  // if comma is not in the delimiter specified by user
    {
        if (strFilePaths.Find(",") != kNotFound) // if comma found in filenames return error
            return NS_ERROR_FILE_INVALID_PATH ;
    }

    nsCString Attachments ;

    // only 1 file is to be sent, no delim specified
    if (strDelimChars.IsEmpty())
        strDelimChars.AssignLiteral(";");

    PRInt32 offset = 0 ;
    PRInt32 FilePathsLen = strFilePaths.Length() ;
    if (FilePathsLen)
    {
        nsAutoString Subject ;

        // multiple files to be sent, delim specified
        nsCOMPtr <nsILocalFile> pFile = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID, &rv) ;
        if (NS_FAILED(rv) || (!pFile) ) return rv ;        

        PRUnichar * newFilePaths = (PRUnichar *) strFilePaths.get() ;
        while (offset != kNotFound)
        {
            //Temp Directory
            nsCOMPtr <nsIFile> pTempFileDir;
            NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(pTempFileDir));
            nsCOMPtr <nsILocalFile> pTempDir = do_QueryInterface(pTempFileDir);

            // if not already existing, create another temp dir for mapi within Win temp dir
            // this is windows only so we can do "\\"
            pTempDir->AppendRelativePath (NS_LITERAL_STRING("moz_mapi"));
            pTempDir->Exists(&bExist) ;
            if (!bExist)
            {
                rv = pTempDir->Create(nsIFile::DIRECTORY_TYPE, 777) ;
                if (NS_FAILED(rv)) return rv ;
            }

            nsString RemainingPaths ;
            RemainingPaths.Assign(newFilePaths) ;
            offset = RemainingPaths.Find (strDelimChars) ;
            if (offset != kNotFound)
            {
                RemainingPaths.SetLength (offset) ;
                if ((offset + strDelimChars.Length()) < FilePathsLen)
                    newFilePaths += offset + strDelimChars.Length() ;
                else
                  offset = kNotFound;
                FilePathsLen -= offset + strDelimChars.Length();
            }

            if (RemainingPaths[1] != ':' && RemainingPaths[1] != '\\') 
            {
              char cwd[MAX_PATH];  
              if (_getdcwd(_getdrive(), cwd, MAX_PATH)) 
              {
                nsAutoString cwdStr;
                CopyASCIItoUTF16(cwd, cwdStr);
                cwdStr.Append('\\');
                RemainingPaths.Insert(cwdStr, 0);
              }
            }

            pFile->InitWithPath (RemainingPaths) ;

            rv = pFile->Exists(&bExist) ;
            if (NS_FAILED(rv) || (!bExist) ) return NS_ERROR_FILE_TARGET_DOES_NOT_EXIST ;

            // filename of the file attachment
            nsAutoString leafName ;
            pFile->GetLeafName (leafName) ;
            if(NS_FAILED(rv) || leafName.IsEmpty()) return rv ;

            if (!Subject.IsEmpty()) 
                Subject.AppendLiteral(", ");
            Subject += leafName;

            // create MsgCompose attachment object
            nsCOMPtr<nsIMsgAttachment> attachment = do_CreateInstance(NS_MSGATTACHMENT_CONTRACTID, &rv);
            NS_ENSURE_SUCCESS(rv, rv);

            nsDependentString fileNameNative(leafName.get());
            rv = pFile->CopyTo(pTempDir, fileNameNative);
            if (NS_FAILED(rv)) return rv ;

            // now turn pTempDir into a full file path to the temp file
            pTempDir->Append(fileNameNative);

            // this one is a temp file so set the flag for MsgCompose
            attachment->SetTemporary(PR_TRUE) ;

            // now set the attachment object
            nsCAutoString pURL ;
            NS_GetURLSpecFromFile(pTempDir, pURL);
            attachment->SetUrl(pURL.get()) ;

            // add the attachment
            rv = aCompFields->AddAttachment (attachment);
            if (NS_FAILED(rv)) return rv ;
        }

        rv = aCompFields->SetBody(Subject) ;
    }

    return rv ;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 632 of file msgMapiHook.cpp.

{
    nsresult rv = NS_OK ;

    if (aMessage->lpOriginator)
    {
        nsAutoString From ;
        From.AssignWithConversion((char *) aMessage->lpOriginator->lpszAddress);
        aCompFields->SetFrom (From) ;
    }

    nsAutoString To ;
    nsAutoString Cc ; 
    nsAutoString Bcc ;

    NS_NAMED_LITERAL_STRING(Comma, ",") ;

    if (aMessage->lpRecips)
    {
        for (int i=0 ; i < (int) aMessage->nRecipCount ; i++)
        {
            if (aMessage->lpRecips[i].lpszAddress || aMessage->lpRecips[i].lpszName)
            {
                const char *addressWithoutType = (aMessage->lpRecips[i].lpszAddress)
                  ? aMessage->lpRecips[i].lpszAddress : aMessage->lpRecips[i].lpszName;
                if (!PL_strncasecmp(addressWithoutType, "SMTP:", 5))
                  addressWithoutType += 5;

                switch (aMessage->lpRecips[i].ulRecipClass)
                {
                case MAPI_TO :
                    if (!To.IsEmpty())
                        To += Comma ;
                    To.AppendWithConversion (addressWithoutType);
                    break ;

                case MAPI_CC :
                    if (!Cc.IsEmpty())
                        Cc += Comma ;
                    Cc.AppendWithConversion (addressWithoutType);
                    break ;

                case MAPI_BCC :
                    if (!Bcc.IsEmpty())
                        Bcc += Comma ;
                    Bcc.AppendWithConversion (addressWithoutType) ; 
                    break ;
                }
            }
        }
    }
    
    // set To, Cc, Bcc
    aCompFields->SetTo (To) ;
    aCompFields->SetCc (Cc) ;
    aCompFields->SetBcc (Bcc) ;

    PR_LOG(MAPI, PR_LOG_DEBUG, ("to: %s cc: %s bcc: %s \n", NS_ConvertUCS2toUTF8(To).get(), NS_ConvertUCS2toUTF8(Cc).get(), NS_ConvertUCS2toUTF8(Bcc).get()));

    nsCAutoString platformCharSet;
    // set subject
    if (aMessage->lpszSubject)
    {
        nsAutoString Subject ;
        if (platformCharSet.IsEmpty())
            platformCharSet.Assign(nsMsgI18NFileSystemCharset());
        rv = ConvertToUnicode(platformCharSet.get(), (char *) aMessage->lpszSubject, Subject);
        if (NS_FAILED(rv)) return rv ;         
        aCompFields->SetSubject(Subject) ;
    }

    // handle attachments as File URL
    rv = HandleAttachments (aCompFields, aMessage->nFileCount, aMessage->lpFiles, PR_FALSE) ;
    if (NS_FAILED(rv)) return rv ;    

    // set body
    if (aMessage->lpszNoteText)
    {
        nsAutoString Body ;
        if (platformCharSet.IsEmpty())
            platformCharSet.Assign(nsMsgI18NFileSystemCharset());
        rv = ConvertToUnicode(platformCharSet.get(), (char *) aMessage->lpszNoteText, Body);
        if (NS_FAILED(rv)) return rv ;
        if (Body.Last() != nsCRT::LF)
          Body.AppendLiteral(CRLF); 

        if (Body.Find("<html>") == kNotFound)
          aCompFields->SetForcePlainText(PR_TRUE);

        rv = aCompFields->SetBody(Body) ;
    }

#ifdef RAJIV_DEBUG
    // testing what all was set in CompFields
    printf ("To : %S \n", To.get()) ;
    printf ("CC : %S \n", Cc.get() ) ;
    printf ("BCC : %S \n", Bcc.get() ) ;
#endif

    return rv ;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsMapiHook::ShowComposerWindow ( unsigned long  aSession,
nsIMsgCompFields aCompFields 
) [static]

get the nsIMsgComposeService object to open the compose window

Definition at line 870 of file msgMapiHook.cpp.

{
    nsresult rv = NS_OK ;

    // create a send listener to get back the send status
    nsCOMPtr <nsIMsgSendListener> sendListener ;
    rv = nsMAPISendListener::CreateMAPISendListener(getter_AddRefs(sendListener)) ; 
    if (NS_FAILED(rv) || (!sendListener) ) return rv ;

    // create the compose params object 
    nsCOMPtr<nsIMsgComposeParams> pMsgComposeParams (do_CreateInstance(NS_MSGCOMPOSEPARAMS_CONTRACTID, &rv));
    if (NS_FAILED(rv) || (!pMsgComposeParams) ) return rv ;

    PRBool forcePlainText;
    aCompFields->GetForcePlainText(&forcePlainText);
    pMsgComposeParams->SetFormat(forcePlainText ? nsIMsgCompFormat::Default : nsIMsgCompFormat::HTML);
    // populate the compose params
    pMsgComposeParams->SetType(nsIMsgCompType::New);
    pMsgComposeParams->SetFormat(nsIMsgCompFormat::Default);
    pMsgComposeParams->SetComposeFields(aCompFields); 
    pMsgComposeParams->SetSendListener(sendListener) ;

    nsCOMPtr <nsIMsgComposeService> compService = do_GetService (NS_MSGCOMPOSESERVICE_CONTRACTID) ;
    if (NS_FAILED(rv)|| (!compService) ) return rv ;

    rv = compService->OpenComposeWindowWithParams(nsnull, pMsgComposeParams) ;
    if (NS_FAILED(rv)) return rv ;

    return rv ;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsMapiHook::VerifyUserName ( const PRUnichar aUsername,
char **  aIdKey 
) [static]

Definition at line 255 of file msgMapiHook.cpp.

{
    nsresult rv;

    if (aUsername == nsnull)
        return PR_FALSE;

    nsCOMPtr<nsIMsgAccountManager> accountManager(do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv));
    if (NS_FAILED(rv)) return PR_FALSE;
    nsCOMPtr<nsISupportsArray> identities;
    rv = accountManager->GetAllIdentities(getter_AddRefs(identities));
    if (NS_FAILED(rv)) return PR_FALSE;
    PRUint32 numIndentities;
    identities->Count(&numIndentities);

    for (PRUint32 i = 0; i < numIndentities; i++)
    {
        // convert supports->Identity
        nsCOMPtr<nsISupports> thisSupports;
        rv = identities->GetElementAt(i, getter_AddRefs(thisSupports));
        if (NS_FAILED(rv)) continue;
        nsCOMPtr<nsIMsgIdentity> thisIdentity(do_QueryInterface(thisSupports, &rv));
        if (NS_SUCCEEDED(rv) && thisIdentity)
        {
            nsXPIDLCString email;
            rv = thisIdentity->GetEmail(getter_Copies(email));
            if (NS_FAILED(rv)) continue;

            // get the username from the email and compare with the username
            nsCAutoString aEmail(email.get());
            PRInt32 index = aEmail.FindChar('@');
            if (index != -1)
                aEmail.Truncate(index);

                     if (nsDependentString(aUsername) == NS_ConvertASCIItoUCS2(aEmail))  // == overloaded
                return NS_SUCCEEDED(thisIdentity->GetKey(aIdKey));
        }
    }

    return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 63 of file msgMapiHook.h.


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