зеркало из https://github.com/mozilla/gecko-dev.git
make newsblog use nsIMsgLocalMailFolder::AddMessage interface to add messages, so that we can use the new mail parser object, run filters, etc, sr=mscott 225158
This commit is contained in:
Родитель
9e4764b0f8
Коммит
a6aebf0e0b
|
@ -275,7 +275,7 @@ FeedItem.prototype.toUtf8 = function(str) {
|
|||
}
|
||||
|
||||
FeedItem.prototype.writeToFolder = function() {
|
||||
debug(this.identity + " writing to message folder");
|
||||
debug(this.identity + " writing to message folder" + this.feed.name + "\n");
|
||||
|
||||
var server = getIncomingServer();
|
||||
|
||||
|
@ -326,42 +326,8 @@ FeedItem.prototype.writeToFolder = function() {
|
|||
|
||||
// Get the folder and database storing the feed's messages and headers.
|
||||
var folder = server.rootMsgFolder.getChildNamed(this.feed.name);
|
||||
folder = folder.QueryInterface(Components.interfaces.nsIMsgFolder);
|
||||
|
||||
var mbox = new LocalFile(folder.path.nativePath,
|
||||
MODE_WRONLY | MODE_APPEND | MODE_CREATE);
|
||||
|
||||
// Create a message header object using the offset of the message
|
||||
// from the front of the mbox file as the unique message key (which seems
|
||||
// to be what other mail code does).
|
||||
var key = mbox.localFile.fileSize;
|
||||
|
||||
var length = mbox.write(this.toUtf8(source));
|
||||
mbox.flush();
|
||||
mbox.close();
|
||||
|
||||
var db = folder.getMsgDatabase(getMessageWindow());
|
||||
var header = db.CreateNewHdr(key);
|
||||
|
||||
// Not sure what date should be, but guessing it's seconds-since-epoch
|
||||
// since that's what existing values look like. For some reason the values
|
||||
// in the database have three more decimal places than the values produced
|
||||
// by Date.getTime(), and in the DB values I've inspected they were all zero,
|
||||
// so I append three zeros here, which seems to work. Sheesh what a hack.
|
||||
// XXX Figure out what's up with that, maybe milliseconds?
|
||||
header.date = new Date(this.date).getTime() + "000";
|
||||
header.Charset = "UTF-8";
|
||||
header.author = this.toUtf8(this.author);
|
||||
header.subject = this.toUtf8(this.title);
|
||||
header.messageId = this.messageID;
|
||||
header.messageSize = length;
|
||||
// Count the number of line break characters to determine the line count.
|
||||
header.lineCount = this.content.match(/\r?\n?/g).length;
|
||||
header.messageOffset = key;
|
||||
header.statusOffset = openingLine.length;
|
||||
header.flags = MSG_FLAG_NEW;
|
||||
|
||||
db.AddNewHdrToDB(header, true);
|
||||
folder = folder.QueryInterface(Components.interfaces.nsIMsgLocalMailFolder);
|
||||
folder.addMessage(source);
|
||||
}
|
||||
|
||||
function W3CToIETFDate(dateString) {
|
||||
|
|
|
@ -753,7 +753,7 @@ FeedItem.prototype.toUtf8 = function(str) {
|
|||
}
|
||||
|
||||
FeedItem.prototype.writeToFolder = function() {
|
||||
debug(this.identity + " writing to message folder");
|
||||
debug(this.identity + " writing to message folder" + this.feed.name + "\n");
|
||||
|
||||
var server = this.feed.folder.server;
|
||||
|
||||
|
@ -804,42 +804,8 @@ FeedItem.prototype.writeToFolder = function() {
|
|||
|
||||
// Get the folder and database storing the feed's messages and headers.
|
||||
var folder = server.rootMsgFolder.getChildNamed(this.feed.name);
|
||||
folder = folder.QueryInterface(Components.interfaces.nsIMsgFolder);
|
||||
|
||||
var mbox = new LocalFile(folder.path.nativePath,
|
||||
MODE_WRONLY | MODE_APPEND | MODE_CREATE);
|
||||
|
||||
// Create a message header object using the offset of the message
|
||||
// from the front of the mbox file as the unique message key (which seems
|
||||
// to be what other mail code does).
|
||||
var key = mbox.localFile.fileSize;
|
||||
|
||||
var length = mbox.write(this.toUtf8(source));
|
||||
mbox.flush();
|
||||
mbox.close();
|
||||
|
||||
var db = folder.getMsgDatabase(this.feed.msgWindow);
|
||||
var header = db.CreateNewHdr(key);
|
||||
|
||||
// Not sure what date should be, but guessing it's seconds-since-epoch
|
||||
// since that's what existing values look like. For some reason the values
|
||||
// in the database have three more decimal places than the values produced
|
||||
// by Date.getTime(), and in the DB values I've inspected they were all zero,
|
||||
// so I append three zeros here, which seems to work. Sheesh what a hack.
|
||||
// XXX Figure out what's up with that, maybe milliseconds?
|
||||
header.date = new Date(this.date).getTime() + "000";
|
||||
header.Charset = "UTF-8";
|
||||
header.author = this.toUtf8(this.author);
|
||||
header.subject = this.toUtf8(this.title);
|
||||
header.messageId = this.messageID;
|
||||
header.flags = MSG_FLAG_NEW;
|
||||
header.messageSize = length;
|
||||
// Count the number of line break characters to determine the line count.
|
||||
header.lineCount = this.content.match(/\r?\n?/g).length;
|
||||
header.messageOffset = key;
|
||||
header.statusOffset = openingLine.length;
|
||||
|
||||
db.AddNewHdrToDB(header, true);
|
||||
folder = folder.QueryInterface(Components.interfaces.nsIMsgLocalMailFolder);
|
||||
folder.addMessage(source);
|
||||
}
|
||||
|
||||
function W3CToIETFDate(dateString) {
|
||||
|
|
|
@ -1027,10 +1027,10 @@ NS_IMETHODIMP nsMsgDBFolder::GetFlags(PRUint32 *_retval)
|
|||
|
||||
NS_IMETHODIMP nsMsgDBFolder::ReadFromFolderCacheElem(nsIMsgFolderCacheElement *element)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsXPIDLCString charset;
|
||||
nsresult rv = NS_OK;
|
||||
nsXPIDLCString charset;
|
||||
|
||||
element->GetInt32Property("flags", (PRInt32 *) &mFlags);
|
||||
element->GetInt32Property("flags", (PRInt32 *) &mFlags);
|
||||
|
||||
PRBool persistElided = PR_TRUE;
|
||||
rv = GetPersistElided(&persistElided);
|
||||
|
@ -1048,55 +1048,55 @@ NS_IMETHODIMP nsMsgDBFolder::ReadFromFolderCacheElem(nsIMsgFolderCacheElement *e
|
|||
element->GetInt32Property("expungedBytes", (PRInt32 *) &mExpungedBytes);
|
||||
element->GetInt32Property("folderSize", (PRInt32 *) &mFolderSize);
|
||||
|
||||
element->GetStringProperty("charset", getter_Copies(charset));
|
||||
element->GetStringProperty("charset", getter_Copies(charset));
|
||||
|
||||
#ifdef DEBUG_bienvenu1
|
||||
char *uri;
|
||||
char *uri;
|
||||
|
||||
GetURI(&uri);
|
||||
printf("read total %ld for %s\n", mNumTotalMessages, uri);
|
||||
PR_Free(uri);
|
||||
GetURI(&uri);
|
||||
printf("read total %ld for %s\n", mNumTotalMessages, uri);
|
||||
PR_Free(uri);
|
||||
#endif
|
||||
mCharset.AssignWithConversion(charset.get());
|
||||
mCharset.AssignWithConversion(charset.get());
|
||||
|
||||
mInitializedFromCache = PR_TRUE;
|
||||
return rv;
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsMsgDBFolder::GetFolderCacheKey(nsIFileSpec **aFileSpec)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr <nsIFileSpec> path;
|
||||
rv = GetPath(getter_AddRefs(path));
|
||||
|
||||
// now we put a new file spec in aFileSpec, because we're going to change it.
|
||||
rv = NS_NewFileSpec(aFileSpec);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && *aFileSpec)
|
||||
{
|
||||
nsIFileSpec *dbPath = *aFileSpec;
|
||||
dbPath->FromFileSpec(path);
|
||||
// if not a server, we need to convert to a db Path with .msf on the end
|
||||
PRBool isServer = PR_FALSE;
|
||||
GetIsServer(&isServer);
|
||||
|
||||
// if it's a server, we don't need the .msf appended to the name
|
||||
if (!isServer)
|
||||
{
|
||||
nsFileSpec folderName;
|
||||
dbPath->GetFileSpec(&folderName);
|
||||
nsLocalFolderSummarySpec summarySpec(folderName);
|
||||
|
||||
dbPath->SetFromFileSpec(summarySpec);
|
||||
|
||||
// create the .msf file
|
||||
// see bug #244217 for details
|
||||
PRBool exists;
|
||||
if (NS_SUCCEEDED(dbPath->Exists(&exists)) && !exists)
|
||||
dbPath->Touch();
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
nsresult rv;
|
||||
nsCOMPtr <nsIFileSpec> path;
|
||||
rv = GetPath(getter_AddRefs(path));
|
||||
|
||||
// now we put a new file spec in aFileSpec, because we're going to change it.
|
||||
rv = NS_NewFileSpec(aFileSpec);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && *aFileSpec)
|
||||
{
|
||||
nsIFileSpec *dbPath = *aFileSpec;
|
||||
dbPath->FromFileSpec(path);
|
||||
// if not a server, we need to convert to a db Path with .msf on the end
|
||||
PRBool isServer = PR_FALSE;
|
||||
GetIsServer(&isServer);
|
||||
|
||||
// if it's a server, we don't need the .msf appended to the name
|
||||
if (!isServer)
|
||||
{
|
||||
nsFileSpec folderName;
|
||||
dbPath->GetFileSpec(&folderName);
|
||||
nsLocalFolderSummarySpec summarySpec(folderName);
|
||||
|
||||
dbPath->SetFromFileSpec(summarySpec);
|
||||
|
||||
// create the .msf file
|
||||
// see bug #244217 for details
|
||||
PRBool exists;
|
||||
if (NS_SUCCEEDED(dbPath->Exists(&exists)) && !exists)
|
||||
dbPath->Touch();
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsMsgDBFolder::FlushToFolderCache()
|
||||
|
|
|
@ -1958,6 +1958,9 @@ nsMsgIncomingServer::ConfigureTemporaryReturnReceiptsFilter(nsIMsgFilterList *fi
|
|||
PRBool useCustomPrefs = PR_FALSE;
|
||||
PRInt32 incorp = nsIMsgMdnGenerator::eIncorporateInbox;
|
||||
|
||||
if (!identity)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
identity->GetBoolAttribute("use_custom_prefs", &useCustomPrefs);
|
||||
if (useCustomPrefs)
|
||||
rv = GetIntValue("incorporate_return_receipt", &incorp);
|
||||
|
|
|
@ -76,6 +76,9 @@ interface nsIMsgLocalMailFolder : nsISupports {
|
|||
[noscript] void markMsgsOnPop3Server(in nsISupportsArray aMessages, in PRInt32 aMark);
|
||||
void refreshSizeOnDisk(); // file size on disk has possibly changed - update and notify
|
||||
|
||||
// this adds a message to the end of the folder, parsing it as it goes, and
|
||||
// applying filters, if applicable.
|
||||
void addMessage(in string aMessage);
|
||||
/**
|
||||
* functions for updating the UI while running DownloadMessagesForOffline:
|
||||
* delete the old message before adding its newly downloaded body, and
|
||||
|
|
|
@ -106,6 +106,7 @@
|
|||
#include "nsCOMArray.h"
|
||||
#include "nsILineInputStream.h"
|
||||
#include "nsIFileStreams.h"
|
||||
#include "nsAutoPtr.h"
|
||||
|
||||
static NS_DEFINE_CID(kMailboxServiceCID, NS_MAILBOXSERVICE_CID);
|
||||
static NS_DEFINE_CID(kCMailDB, NS_MAILDB_CID);
|
||||
|
@ -3713,3 +3714,57 @@ nsMsgLocalMailFolder::GetUidlFromFolder(nsLocalFolderScanState *aState,
|
|||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
// this adds a message to the end of the folder, parsing it as it goes, and
|
||||
// applying filters, if applicable.
|
||||
NS_IMETHODIMP
|
||||
nsMsgLocalMailFolder::AddMessage(const char *aMessage)
|
||||
{
|
||||
nsCOMPtr<nsIFileSpec> pathSpec;
|
||||
nsresult rv = GetPath(getter_AddRefs(pathSpec));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsFileSpec fileSpec;
|
||||
rv = pathSpec->GetFileSpec(&fileSpec);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsIOFileStream outFileStream(fileSpec);
|
||||
outFileStream.seek(fileSpec.GetFileSize());
|
||||
|
||||
// create a new mail parser
|
||||
nsRefPtr<nsParseNewMailState> newMailParser = new nsParseNewMailState;
|
||||
if (newMailParser == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsCOMPtr<nsIMsgFolder> rootFolder;
|
||||
rv = GetRootFolder(getter_AddRefs(rootFolder));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
PRBool isLocked;
|
||||
|
||||
GetLocked(&isLocked);
|
||||
if(!isLocked)
|
||||
AcquireSemaphore(NS_STATIC_CAST(nsIMsgLocalMailFolder*, this));
|
||||
else
|
||||
return NS_MSG_FOLDER_BUSY;
|
||||
|
||||
|
||||
rv = newMailParser->Init(rootFolder, this,
|
||||
fileSpec, &outFileStream, nsnull);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
|
||||
// in_server->SetServerBusy(PR_TRUE);
|
||||
|
||||
outFileStream << aMessage;
|
||||
newMailParser->BufferInput(aMessage, strlen(aMessage));
|
||||
|
||||
outFileStream.flush();
|
||||
newMailParser->OnStopRequest(nsnull, nsnull, NS_OK);
|
||||
newMailParser->SetDBFolderStream(nsnull); // stream is going away
|
||||
if (outFileStream.is_open())
|
||||
outFileStream.close();
|
||||
}
|
||||
ReleaseSemaphore(NS_STATIC_CAST(nsIMsgLocalMailFolder*, this));
|
||||
return rv;
|
||||
}
|
||||
|
|
|
@ -1578,20 +1578,21 @@ void nsParseNewMailState::ApplyFilters(PRBool *pMoved, nsIMsgWindow *msgWindow)
|
|||
m_msgMovedByFilter = PR_FALSE;
|
||||
|
||||
nsCOMPtr<nsIMsgDBHdr> msgHdr = m_newMsgHdr;
|
||||
nsCOMPtr<nsIMsgFolder> inbox;
|
||||
nsCOMPtr<nsIMsgFolder> downloadFolder = m_downloadFolder;
|
||||
nsCOMPtr <nsIMsgFolder> rootMsgFolder = do_QueryInterface(m_rootFolder);
|
||||
if (rootMsgFolder)
|
||||
{
|
||||
PRUint32 numFolders;
|
||||
rootMsgFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_INBOX, 1, &numFolders, getter_AddRefs(inbox));
|
||||
if (inbox)
|
||||
inbox->GetURI(getter_Copies(m_inboxUri));
|
||||
if (!downloadFolder)
|
||||
rootMsgFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_INBOX, 1, &numFolders, getter_AddRefs(downloadFolder));
|
||||
if (downloadFolder)
|
||||
downloadFolder->GetURI(getter_Copies(m_inboxUri));
|
||||
char * headers = m_headers.GetBuffer();
|
||||
PRUint32 headersSize = m_headers.GetBufferPos();
|
||||
nsresult matchTermStatus;
|
||||
if (m_filterList)
|
||||
matchTermStatus = m_filterList->ApplyFiltersToHdr(nsMsgFilterType::InboxRule,
|
||||
msgHdr, inbox, m_mailDB, headers, headersSize, this, msgWindow);
|
||||
msgHdr, downloadFolder, m_mailDB, headers, headersSize, this, msgWindow);
|
||||
}
|
||||
|
||||
if (pMoved)
|
||||
|
|
|
@ -47,8 +47,9 @@ NS_IMPL_ISUPPORTS_INHERITED2(nsRssIncomingServer,
|
|||
nsIRssIncomingServer,
|
||||
nsILocalMailIncomingServer)
|
||||
|
||||
nsRssIncomingServer::nsRssIncomingServer()
|
||||
nsRssIncomingServer::nsRssIncomingServer()
|
||||
{
|
||||
m_canHaveFilters = PR_TRUE;
|
||||
}
|
||||
|
||||
nsRssIncomingServer::~nsRssIncomingServer()
|
||||
|
|
Загрузка…
Ссылка в новой задаче