|
- 正常发信流程://发送邮件
- MsgComposeCommands.js
- function GenericSendMessage_Ori(msgType,spicc)
- {
- gMsgCompose.SendMsg(msgType, getCurrentIdentity(),
- getCurrentAccountKey(), msgWindow, progress);
- }nsMsgCompose.cpp
- NS_IMETHODIMP nsMsgCompose::SendMsg(MSG_DeliverMode deliverMode, nsIMsgIdentity *identity, const char *accountKey, nsIMsgWindow *aMsgWindow, nsIMsgProgress *progress)
- {
- //打开进度窗口
- mProgress->OpenProgressDialog(m_window, aMsgWindow,
- "chrome://messenger/content/messengercompose/sendProgress.xul",
- false, params);
- rv = _SendMsg(deliverMode, identity, accountKey, entityConversionDone);
- }
- nsresult nsMsgCompose::_SendMsg(MSG_DeliverMode deliverMode, nsIMsgIdentity *identity,
- const char *accountKey, bool entityConversionDone)
- { // Create the listener for the send operation...
- nsCOMPtr<nsIMsgComposeSendListener> composeSendListener = do_CreateInstance(NS_MSGCOMPOSESENDLISTENER_CONTRACTID);
- nsCOMPtr<nsIMsgSend> mMsgSend; // for composition back end
- mMsgSend = do_CreateInstance(NS_MSGSEND_CONTRACTID);
- ...
- #define NS_MSGCOMPOSESENDLISTENER_CONTRACTID \ "@mozilla.org/messengercompose/composesendlistener;1"// Create the listener for the send operation... 创建发送监听
- nsCOMPtr<nsIMsgComposeSendListener> composeSendListener = do_CreateInstance(NS_MSGCOMPOSESENDLISTENER_CONTRACTID);
- nsCOMPtr<nsIMsgSendListener> sendListener = do_QueryInterface(composeSendListener);
- //对应的实现类 class nsMsgComposeSendListener : public nsIMsgComposeSendListener, public nsIMsgSendListener, public nsIMsgCopyServiceListener, public nsIWebProgressListener
- rv = mMsgSend->CreateAndSendMessage(
- m_composeHTML ? m_editor.get() : nullptr,
- identity,
- accountKey,
- m_compFields,
- false, // bool digest_p,
- false, // bool dont_deliver_p,
- (nsMsgDeliverMode)deliverMode, // nsMsgDeliverMode mode,
- nullptr, // nsIMsgDBHdr *msgToReplace,
- m_composeHTML?TEXT_HTML:TEXT_PLAIN, // const char *attachment1_type,
- bodyString, // const char *attachment1_body,
- bodyLength, // uint32_t attachment1_body_length,
- nullptr, // nsIArray *attachments,
- nullptr, // nsIArray preloaded_attachments,
- m_window, // nsIDOMWindow *parentWindow;
- mProgress, // nsIMsgProgress *progress,
- sendListener, // listener
- mSmtpPassword.get(),
- mOriginalMsgURI,
- mType);
- }
- nsMsgSend.cpp
- nsMsgComposeAndSend::CreateAndSendMessage(..
- }
- nsMsgComposeAndSend::Init(
- nsIMsgIdentity *aUserIdentity,
- {
- return HackAttachments(attachments, preloaded_attachments);
- }
- nsMsgComposeAndSend::HackAttachments(nsIArray *attachments,
- nsIArray *preloadedAttachments)
- {AddCompFieldLocalAttachments(); //本地文件处理
- if (m_attachment_count > 0){
- for (i = 0; i < m_attachment_count; i++) //循环处理附件
- {
- //正在附加 [附件名]
- nsresult status = m_attachments.SnarfAttachment(mCompFields); //临时文件 nsmail.tmp
- }
- }
- return GatherMimeAttachments();
- }
- nsMsgComposeAndSend::AddCompFieldLocalAttachments()
- {
- //云传输判断
- // Just look for local file:// attachments and do the right thing. 是否本机上的文件判断
- if (nsMsgIsLocalFile(url.get()))
- {
- attachment->GetContentType(getter_Copies(m_attachments[newLoc].m_type)); 获取文件类型 后缀等
- 文件类型不为空,m_attachments[newLoc].m_done = true;
- mimeFinder->GetTypeFromExtension(fileExt, type); 根据文件后缀重新获取mime支持的类型
- m_attachments[newLoc].m_type = type; 只有支持的类型 m_done才为ture.
- }
- }
- nsExternalHelperAppService.cpp
- NS_IMETHODIMP nsExternalHelperAppService::GetTypeFromExtension(const nsACString& aFileExt, nsACString& aContentType)
- {
- }
- nsMsgComposeAndSend::GatherMimeAttachments()
- {
- //产生临时文件 nsemail.html
- if (m_dont_deliver_p && mListener)
- {
- // Need to ditch the file spec here so that we don't delete the
- // file, since in this case, the caller wants the file
- //
- mReturnFile = mTempFile;
- mTempFile = nullptr;
- if (!mReturnFile)
- NotifyListenerOnStopSending(nullptr, NS_ERROR_OUT_OF_MEMORY, nullptr, nullptr);
- else
- {
- NotifyListenerOnStopSending(nullptr, NS_OK, nullptr, mReturnFile);
- }
- }
- else
- {
- status = DeliverMessage();
- if (NS_SUCCEEDED(status))
- shouldDeleteDeliveryState = false;
- }
- }
- nsMsgSend.cpp
- nsMsgComposeAndSend:: DeliverMessage()
- {
- return SendToMagicFolder(m_deliver_mode); //存草稿 模板调用这个过程,直接对相应邮件夹追加文件
- return DeliverFileAsMail(); //邮件发送调用这个
- }nsMsgComposeAndSend:: DeliverFileAsMail()
- {
- nsCOMPtr<nsISmtpService> smtpService(do_GetService(NS_SMTPSERVICE_CONTRACTID, &rv));
- if (NS_SUCCEEDED(rv) && smtpService)
- {
- MsgDeliveryListener *deliveryListener = new MsgDeliveryListener(this, false); //邮件发送时,创建用于回调的监听,已对已发送的邮件进行拷贝到已发送
- rv = smtpService->SendMailMessage(mTempFile, buf, mUserIdentity,
- mSmtpPassword.get(), deliveryListener, msgStatus,
- callbacks, mCompFields->GetDSN(),
- getter_AddRefs(runningUrl),
- getter_AddRefs(mRunningRequest));
- }
- }
- NS_IMETHODIMP MsgDeliveryListener::OnStopRunningUrl(nsIURI *url, nsresult aExitCode)
- {
- mMsgSend->SendDeliveryCallback(url, mIsNewsDelivery, aExitCode);
- }
- NS_IMETHODIMP nsMsgComposeAndSend::SendDeliveryCallback(nsIURI *aUrl, bool inIsNewsDelivery, nsresult aExitCode)
- {
- DeliverAsMailExit(aUrl, aExitCode);
- }
- nsMsgComposeAndSend::DeliverAsMailExit(nsIURI *aUrl, nsresult aExitCode)
- {
- DoDeliveryExitProcessing(aUrl, aExitCode, false);
- return NS_OK;
- }
- NS_IMETHODIMP
- nsMsgComposeAndSend::DeliverAsNewsExit(nsIURI *aUrl, nsresult aExitCode)
- {
- DoDeliveryExitProcessing(aUrl, aExitCode, mSendMailAlso);
- return NS_OK;
- }
- nsMsgComposeAndSend::DoDeliveryExitProcessing(nsIURI * aUri, nsresult aExitCode, bool aCheckForMail)
- {
- DoFcc();
- }
- nsresult nsMsgComposeAndSend::DoFcc() // Now, start the appropriate copy operation.
- {
- nsresult rv = MimeDoFCC(mTempFile,
- nsMsgDeliverNow,
- mCompFields->GetBcc(),
- mCompFields->GetFcc(),
- mCompFields->GetNewspostUrl());
- }
- ///////////////////////////特定邮件夹,还是正常发送后,追加到已发送 的具体调用过程//////
- nsMsgSend.cpp
- nsMsgComposeAndSend::MimeDoFCC(nsIFile *input_file,..
- {
- status = StartMessageCopyOperation(mCopyFile, mode, turi);
- }
- nsMsgComposeAndSend::StartMessageCopyOperation(nsIFile *aFile,...
- {
- rv = mCopyObj->StartCopyOperation(mUserIdentity, aFile, mode,
- this, m_folderName.get(), mMsgToReplace);
- }
- nsMsgCopy.cpp
- nsMsgCopy::StartCopyOperation(nsIMsgIdentity *aUserIdentity,...
- {
- rv = DoCopy(aFile, dstFolder, aMsgToReplace, isDraft, msgWindow, aMsgSendObj);
- }
- nsMsgCopy::DoCopy(nsIFile *aDiskFile, nsIMsgFolder *dstFolder,...
- {
- rv = copyService->CopyFileMessage(aDiskFile, dstFolder, aMsgToReplace,...
- }
- nsMsgCopyService.cpp
- nsMsgCopyService:: CopyFileMessage(nsIFile* file,...
- {
- copyRequest = new nsCopyRequest();
- rv = copyRequest->Init(nsCopyFileMessageType, fileSupport, dstFolder,...
- rv = DoCopy(copyRequest);
- }
- nsMsgCopyService:: DoCopy(nsCopyRequest* aRequest)
- {
- m_copyRequests.AppendElement(aRequest);
- LogCopyRequest(copyImmediately ? "DoCopy" : "QueueRequest", aRequest); if (copyImmediately)
- return DoNextCopy();
- }
- void nsMsgCopyService:: LogCopyRequest(const char *logMsg, nsCopyRequest* aRequest)
- {
- PR_LOG(gCopyServiceLog, PR_LOG_ALWAYS,
- ("request %lx %s - src %s dest %s numItems %d type=%d",
- aRequest, logMsg, srcFolderUri.get(),
- destFolderUri.get(), numMsgs, aRequest->m_requestType));
- //request 8930788 DoCopy - src dest imap://hechengjin@imap.richinfo.cn/&XfJT0ZAB- numItems 0 type=1
- }
- nsMsgCopyService::DoNextCopy()
- {
- rv = copyRequest->m_dstFolder->CopyMessages
- (copySource->m_msgFolder, copySource->m_messageArray,...)
- rv = copyRequest->m_dstFolder->CopyFileMessage(...)
- }
- nsImapMailFolder.cpp
- nsImapMailFolder::CopyFileMessage(nsIFile* file,
- {
- rv = imapService->AppendMessageFromFile(file, this, messageId,...)
- }
- nsImapService.cpp
- NS_IMETHODIMP nsImapService::AppendMessageFromFile(nsIFile *aFile,..
- {if (inSelectedState)
- urlSpec.Append("/appenddraftfromfile>");
- else
- urlSpec.Append("/appendmsgfromfile>");
- ///// imap://hechengjin88@imap.126.com:143/appendmsgfromfile%3E/%26XfJT0ZAB-
- rv = GetImapConnectionAndLoadUrl(imapUrl, nullptr, aURL);
- }
- nsresult nsImapService::GetImapConnectionAndLoadUrl(nsIImapUrl *aImapUrl,
- {
- rv = aImapServer->GetImapConnectionAndLoadUrl(aImapUrl, aConsumer);
- }
- nsImapIncomingServer.cpp
- nsImapIncomingServer:: GetImapConnectionAndLoadUrl(nsIImapUrl* aImapUrl,..)
- {
- rv = aProtocol->LoadImapUrl(mailnewsurl, aConsumer);
- }
- nsImapProtocol.cpp
- NS_IMETHODIMP nsImapProtocol:: LoadImapUrl(nsIURI * aURL, nsISupports * aConsumer)
- {
- rv = SetupWithUrl(aURL, aConsumer);
- }
- nsresult nsImapProtocol:: SetupWithUrl(nsIURI * aURL, nsISupports* aConsumer) //设置队列中下个要运行的URL
- {
- m_runningUrl = do_QueryInterface(aURL, &rv);
- }
- // NOTE: Though we cleared m_nextUrlReadyToRun above, it may have been
- // set by LoadImapUrl, which runs on the main thread. Because of this,
- // we must not try to clear m_nextUrlReadyToRun here.
- 即 LoadImapUrl 可以设置imap线程中处理的url
- nsImapProtocol::ImapThreadMainLoop()
- {if (readyToRun && m_runningUrl)
- {
- ProcessCurrentURL()
- }
- }
- bool nsImapProtocol:: ProcessCurrentURL()
- {
- if (imapState == nsIImapUrl::nsImapAuthenticatedState)
- ProcessAuthenticatedStateURL();
- else // must be a url that requires us to be in the selected state
- ProcessSelectedStateURL();
- }
- void nsImapProtocol:: ProcessAuthenticatedStateURL() //走这个
- {
- case nsIImapUrl::nsImapAppendMsgFromFile:
- OnAppendMsgFromFile();
- }
- void nsImapProtocol:: OnAppendMsgFromFile()
- {
- UploadMessageFromFile(file, mailboxName, date, flagsToSet, keywords);
- }
- void nsImapProtocol:: UploadMessageFromFile (..)
- {
- command.Append(" append \"");
- }
复制代码 |
|