Back to index

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

#include <nsNNTPNewsgroupList.h>

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

List of all members.

Public Member Functions

 nsNNTPNewsgroupList ()
virtual ~nsNNTPNewsgroupList ()
void initialize (in nsINntpUrl runningURL, in nsIMsgNewsFolder newsFolder)
long getRangeOfArtsToDownload (in nsIMsgWindow aMsgWindow, in long first_message, in long last_message, in long maxextra, out long real_first_message, out long real_last_message)
void addToKnownArticles (in long first_message, in long last_message)
void initXOVER (in long first_message, in long last_message)
void processXOVERLINE (in string line, out unsigned long status)
void processNonXOVER (in string line)
void resetXOVER ()
void finishXOVERLINE (in long status, out long newstatus)
void clearXOVERState ()
boolean applyFilterHit (in nsIMsgFilter filter, in nsIMsgWindow msgWindow)

Public Attributes

attribute boolean getOldMessages

Protected Attributes

PRBool m_getOldMessages
PRBool m_promptedAlready
PRBool m_downloadAll
PRInt32 m_maxArticles
PRInt32 m_lastPercent
PRTime m_lastStatusUpdate
nsCOMPtr< nsIMsgNewsFolderm_newsFolder
nsCOMPtr< nsIMsgDatabasem_newsDB
nsCOMPtr< nsINntpUrlm_runningURL
nsMsgKey m_lastProcessedNumber
nsMsgKey m_firstMsgNumber
nsMsgKey m_lastMsgNumber
PRInt32 m_firstMsgToDownload
PRInt32 m_lastMsgToDownload
nsMsgKeySet * m_set

Private Member Functions

NS_METHOD CleanUp ()
nsresult ParseLine (char *line, PRUint32 *message_number)
nsresult GetDatabase (const char *uri, nsIMsgDatabase **db)
void SetProgressBarPercent (PRInt32 percent)
void SetProgressStatus (const PRUnichar *message)

Private Attributes

PRBool m_finishingXover
nsCOMPtr< nsIMsgWindowm_msgWindow
nsCOMPtr< nsIMsgFilterListm_filterList
nsCOMPtr< nsIMsgFilterListm_serverFilterList
nsCOMPtr< nsIMsgDBHdrm_newMsgHdr
PRBool m_addHdrToDB

Detailed Description

Definition at line 81 of file nsNNTPNewsgroupList.h.


Constructor & Destructor Documentation

Definition at line 99 of file nsNNTPNewsgroupList.cpp.

Here is the call graph for this function:

Definition at line 117 of file nsNNTPNewsgroupList.cpp.

{
  CleanUp();
}

Here is the call graph for this function:


Member Function Documentation

void nsINNTPNewsgroupList::addToKnownArticles ( in long  first_message,
in long  last_message 
) [inherited]

Definition at line 135 of file nsNNTPNewsgroupList.cpp.

{
  // here we make sure that there aren't missing articles in the unread set
  // So if an article is the unread set, and the known arts set, but isn't in the
  // db, then we should mark it read in the unread set.
  if (m_newsDB)
  {
    if (m_knownArts.set)
    {
      nsCOMPtr <nsIDBFolderInfo> folderInfo;
      m_newsDB->GetDBFolderInfo(getter_AddRefs(folderInfo));
      PRInt32 firstKnown = m_knownArts.set->GetFirstMember();
      PRInt32 lastKnown =  m_knownArts.set->GetLastMember();
      if (folderInfo)
      {
        PRUint32 lastMissingCheck;
        folderInfo->GetUint32Property("lastMissingCheck", 0, &lastMissingCheck);
        if (lastMissingCheck)
          firstKnown = lastMissingCheck + 1;
      }
      PRBool done = firstKnown > lastKnown; // just in case...
      PRBool foundMissingArticle = PR_FALSE;
      while (!done)
      {
        PRInt32 firstUnreadStart, firstUnreadEnd;
        m_set->FirstMissingRange(firstKnown, lastKnown, &firstUnreadStart, &firstUnreadEnd);
        if (firstUnreadStart)
        {
          while (firstUnreadStart <= firstUnreadEnd)
          {
            PRBool containsKey;
            m_newsDB->ContainsKey(firstUnreadStart, &containsKey);
            if (!containsKey)
            {
              m_set->Add(firstUnreadStart);
              foundMissingArticle = PR_TRUE;
            }
            firstUnreadStart++;
          }
          firstKnown = firstUnreadStart;
        }
        else
          break;

      }
      if (folderInfo)
        folderInfo->SetUint32Property("lastMissingCheck", lastKnown);
      
      if (foundMissingArticle)
      {
        nsresult rv;
        nsCOMPtr<nsINewsDatabase> db(do_QueryInterface(m_newsDB, &rv));
        NS_ENSURE_SUCCESS(rv,rv);
        db->SetReadSet(m_set);
      }
    }
    m_newsDB->Commit(nsMsgDBCommitType::kSessionCommit);
    m_newsDB->Close(PR_TRUE);
    m_newsDB = nsnull;
  }

  if (m_knownArts.set)
  {
    delete m_knownArts.set;
    m_knownArts.set = nsnull;
  }
  if (m_newsFolder)
    m_newsFolder->NotifyFinishedDownloadinghdrs();
  
  m_newsFolder = nsnull;
  m_runningURL = nsnull;
    
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsINNTPNewsgroupList::finishXOVERLINE ( in long  status,
out long  newstatus 
) [inherited]
nsresult nsNNTPNewsgroupList::GetDatabase ( const char *  uri,
nsIMsgDatabase **  db 
) [private]
long nsINNTPNewsgroupList::getRangeOfArtsToDownload ( in nsIMsgWindow  aMsgWindow,
in long  first_message,
in long  last_message,
in long  maxextra,
out long  real_first_message,
out long  real_last_message 
) [inherited]
void nsINNTPNewsgroupList::initialize ( in nsINntpUrl  runningURL,
in nsIMsgNewsFolder  newsFolder 
) [inherited]
void nsINNTPNewsgroupList::initXOVER ( in long  first_message,
in long  last_message 
) [inherited]
nsresult nsNNTPNewsgroupList::ParseLine ( char *  line,
PRUint32 message_number 
) [private]

Definition at line 527 of file nsNNTPNewsgroupList.cpp.

{
  nsresult rv = NS_OK;
  nsCOMPtr <nsIMsgDBHdr> newMsgHdr;
  char *dateStr = nsnull;  // keep track of date str, for filters
  char *authorStr = nsnull; // keep track of author str, for filters

  if (!line || !message_number) {
    return NS_ERROR_NULL_POINTER;
  }
  
  char *next = line;
  
#define GET_TOKEN()                                                   \
  line = next;                                                               \
  next = (line ? PL_strchr (line, '\t') : 0);    \
  if (next) *next++ = 0
  
  GET_TOKEN (); /* message number */
  *message_number = atol(line);
  
  if (atol(line) == 0)                                  /* bogus xover data */
    return NS_ERROR_UNEXPECTED;
  
  m_newsDB->CreateNewHdr(*message_number, getter_AddRefs(newMsgHdr));      
  
  NS_ASSERTION(newMsgHdr, "CreateNewHdr didn't fail, but it returned a null newMsgHdr");
  if (!newMsgHdr) 
    return NS_ERROR_NULL_POINTER;
  
  GET_TOKEN (); /* subject */
  if (line) {
    const char *subject = line;  /* #### const evilness */
    PRUint32 subjectLen = strlen(line);
    
    PRUint32 flags = 0;
    // ### should call IsHeaderRead here...
    /* strip "Re: " */
    nsXPIDLCString modifiedSubject;
    if (NS_MsgStripRE(&subject, &subjectLen, getter_Copies(modifiedSubject)))
      (void) newMsgHdr->OrFlags(MSG_FLAG_HAS_RE, &flags); // this will make sure read flags agree with newsrc
    
    if (! (flags & MSG_FLAG_READ))
      rv = newMsgHdr->OrFlags(MSG_FLAG_NEW, &flags);
    
    rv = newMsgHdr->SetSubject(modifiedSubject.IsEmpty() ? subject : modifiedSubject.get());
    if (NS_FAILED(rv)) 
      return rv;
  }
  
  GET_TOKEN ();                                                                            /* author */
  if (line) {
    authorStr = line;
    rv = newMsgHdr->SetAuthor(line);
    if (NS_FAILED(rv)) 
      return rv;
  }
  
  GET_TOKEN ();      
  if (line) {
    dateStr = line;
    PRTime date;
    PRStatus status = PR_ParseTimeString (line, PR_FALSE, &date);
    if (PR_SUCCESS == status) {      
      rv = newMsgHdr->SetDate(date);                                  /* date */
      if (NS_FAILED(rv)) 
        return rv;
    }
  }
  
  GET_TOKEN ();                                                                            /* message id */
  if (line) {
    char *strippedId = line;
    
    if (strippedId[0] == '<')
      strippedId++;
    
    char * lastChar = strippedId + PL_strlen(strippedId) -1;
    
    if (*lastChar == '>')
      *lastChar = '\0';
    
    rv = newMsgHdr->SetMessageId(strippedId);
    if (NS_FAILED(rv)) 
      return rv;           
  }
  
  GET_TOKEN ();                                                                            /* references */
  if (line) {
    rv = newMsgHdr->SetReferences(line);
    if (NS_FAILED(rv)) 
      return rv;           
  }
  
  GET_TOKEN ();                                                                            /* bytes */
  if (line) {
    PRUint32 msgSize = 0;
    msgSize = (line) ? atol (line) : 0;
    
    rv = newMsgHdr->SetMessageSize(msgSize);
    if (NS_FAILED(rv)) return rv;           
  }
  
  GET_TOKEN ();                                                                            /* lines */
  if (line) {
    PRUint32 numLines = 0;
    numLines = line ? atol (line) : 0;
    rv = newMsgHdr->SetLineCount(numLines);
    if (NS_FAILED(rv)) return rv;           
  }
  
  GET_TOKEN (); /* xref */
  
  // apply filters
  // XXX TODO
  // do spam classification for news

  nsCOMPtr <nsIMsgFolder> folder = do_QueryInterface(m_newsFolder, &rv);
  NS_ENSURE_SUCCESS(rv,rv);
  
  if (!m_filterList) 
  {
    rv = folder->GetFilterList(m_msgWindow, getter_AddRefs(m_filterList));
    NS_ENSURE_SUCCESS(rv,rv);
  }
  
  if (!m_serverFilterList)
  {
    nsCOMPtr<nsIMsgIncomingServer> server;
    rv = folder->GetServer(getter_AddRefs(server));
    NS_ENSURE_SUCCESS(rv,rv);

    rv = server->GetFilterList(m_msgWindow, getter_AddRefs(m_serverFilterList));
    NS_ENSURE_SUCCESS(rv,rv);
  }

  // flag for kill
  // if the action is Delete, and we get a hit (see ApplyFilterHit())
  // we set this to PR_FALSE.  if false, we won't add it to the db.
  m_addHdrToDB = PR_TRUE;

  PRUint32 filterCount = 0;
  if (m_filterList) {
       rv = m_filterList->GetFilterCount(&filterCount);
    NS_ENSURE_SUCCESS(rv,rv);
  }

  PRUint32 serverFilterCount = 0;
  if (m_serverFilterList) {
       rv = m_serverFilterList->GetFilterCount(&serverFilterCount);
    NS_ENSURE_SUCCESS(rv,rv);
  }

  // only do this if we have filters
  if (filterCount || serverFilterCount) 
  {
    // build up a "headers" for filter code
    nsXPIDLCString subject;
    rv = newMsgHdr->GetSubject(getter_Copies(subject));
    NS_ENSURE_SUCCESS(rv,rv);
    
    PRUint32 headersSize = 0;
 
    // +1 to separate headers with a null byte 
    if (authorStr)
      headersSize += strlen(FROM_HEADER) + strlen(authorStr) + 1;
    
    if (!(subject.IsEmpty()))
      headersSize += strlen(SUBECT_HEADER) + subject.Length() + 1;

    if (dateStr)
     headersSize += strlen(DATE_HEADER) + strlen(dateStr) + 1;
    
    if (headersSize) {
      char *headers = (char *)PR_Malloc(headersSize);
      char *headerPos = headers;
      if (!headers)
        return NS_ERROR_OUT_OF_MEMORY;
    
      if (authorStr) {
        PL_strcpy(headerPos, FROM_HEADER);
        headerPos += strlen(FROM_HEADER);
    
        PL_strcpy(headerPos, authorStr);
        headerPos += strlen(authorStr);
    
        *headerPos = '\0';
        headerPos++;
      }

      if (!(subject.IsEmpty())) {
        PL_strcpy(headerPos, SUBECT_HEADER);
        headerPos += strlen(SUBECT_HEADER);
        
        PL_strcpy(headerPos, subject.get());
        headerPos += subject.Length();
        
        *headerPos = '\0';
        headerPos++;
      }

      if (dateStr) {        
        PL_strcpy(headerPos, DATE_HEADER);
        headerPos += strlen(DATE_HEADER);
        
        PL_strcpy(headerPos, dateStr);
        headerPos += strlen(dateStr);
        
        *headerPos = '\0';
        headerPos++;
      }

      // on a filter hit (see ApplyFilterHit()), we'll be modifying the header 
      // so keep track of the header
      m_newMsgHdr = newMsgHdr;
      
      // the per-newsgroup filters should probably go first. It doesn't matter
      // right now since nothing stops filter execution for newsgroups, but if something
      // does, like adding a "stop execution" action, then users should be able to
      // override the global filters in the per-newsgroup filters.
      if (filterCount)
      {
        rv = m_filterList->ApplyFiltersToHdr(nsMsgFilterType::NewsRule, newMsgHdr, folder, m_newsDB, 
          headers, headersSize, this, m_msgWindow, nsnull);
      }
      if (serverFilterCount)
      {
        rv = m_serverFilterList->ApplyFiltersToHdr(nsMsgFilterType::NewsRule, newMsgHdr, folder, m_newsDB, 
          headers, headersSize, this, m_msgWindow, nsnull);
      }

      PR_Free ((void*) headers);
      NS_ENSURE_SUCCESS(rv,rv);
    }
  }
  
  // if we deleted it, don't add it
  if (m_addHdrToDB) {
    rv = m_newsDB->AddNewHdrToDB(newMsgHdr, PR_TRUE);
    NS_ENSURE_SUCCESS(rv,rv);
  }
  
  return NS_OK;
}
void nsINNTPNewsgroupList::processXOVERLINE ( in string  line,
out unsigned long  status 
) [inherited]

Definition at line 1087 of file nsNNTPNewsgroupList.cpp.

{
  if (!m_runningURL) 
    return;

  nsCOMPtr <nsIMsgMailNewsUrl> mailnewsUrl = do_QueryInterface(m_runningURL);
  if (mailnewsUrl) {
    nsCOMPtr <nsIMsgStatusFeedback> feedback;
    mailnewsUrl->GetStatusFeedback(getter_AddRefs(feedback));

    if (feedback) {
      feedback->ShowProgress(percent);
    }
  }
} 

Here is the call graph for this function:

Definition at line 1104 of file nsNNTPNewsgroupList.cpp.

{
  if (!m_runningURL) 
    return;

  nsCOMPtr <nsIMsgMailNewsUrl> mailnewsUrl = do_QueryInterface(m_runningURL);
  if (mailnewsUrl) {
    nsCOMPtr <nsIMsgStatusFeedback> feedback;
    mailnewsUrl->GetStatusFeedback(getter_AddRefs(feedback));

    if (feedback) {
      feedback->ShowStatusString(message);
    }
  }
}     

Here is the call graph for this function:


Member Data Documentation

Definition at line 81 of file nsINNTPNewsgroupList.idl.

Definition at line 132 of file nsNNTPNewsgroupList.h.

Definition at line 109 of file nsNNTPNewsgroupList.h.

Definition at line 129 of file nsNNTPNewsgroupList.h.

Definition at line 96 of file nsNNTPNewsgroupList.h.

Definition at line 119 of file nsNNTPNewsgroupList.h.

Definition at line 121 of file nsNNTPNewsgroupList.h.

Definition at line 107 of file nsNNTPNewsgroupList.h.

Definition at line 120 of file nsNNTPNewsgroupList.h.

Definition at line 122 of file nsNNTPNewsgroupList.h.

Definition at line 111 of file nsNNTPNewsgroupList.h.

Definition at line 118 of file nsNNTPNewsgroupList.h.

Definition at line 112 of file nsNNTPNewsgroupList.h.

Definition at line 110 of file nsNNTPNewsgroupList.h.

Definition at line 128 of file nsNNTPNewsgroupList.h.

Definition at line 131 of file nsNNTPNewsgroupList.h.

Definition at line 115 of file nsNNTPNewsgroupList.h.

Definition at line 114 of file nsNNTPNewsgroupList.h.

Definition at line 108 of file nsNNTPNewsgroupList.h.

Definition at line 116 of file nsNNTPNewsgroupList.h.

Definition at line 130 of file nsNNTPNewsgroupList.h.

nsMsgKeySet* nsNNTPNewsgroupList::m_set [protected]

Definition at line 125 of file nsNNTPNewsgroupList.h.


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