Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
nsPop3Protocol.cpp File Reference
#include "nscore.h"
#include "msgCore.h"
#include "nsNetUtil.h"
#include "nspr.h"
#include "nsCRT.h"
#include "plbase64.h"
#include "nsIMsgMailNewsUrl.h"
#include "nsPop3Protocol.h"
#include "nsFileSpec.h"
#include "nsFileStream.h"
#include "MailNewsTypes.h"
#include "nsString.h"
#include "nsXPIDLString.h"
#include "nsIPrompt.h"
#include "nsIMsgIncomingServer.h"
#include "nsLocalStringBundle.h"
#include "nsTextFormatter.h"
#include "nsCOMPtr.h"
#include "nsIMsgWindow.h"
#include "nsIMsgFolder.h"
#include "nsIDocShell.h"
#include "nsEscape.h"
#include "nsMsgUtils.h"
#include "nsISignatureVerifier.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsIPrefLocalizedString.h"
#include "nsISocketTransport.h"
#include "nsISSLSocketControl.h"

Go to the source code of this file.

Defines

#define EXTRA_SAFETY_SPACE   3096

Functions

static PRIntn PR_CALLBACK net_pop3_check_for_hash_messages_marked_delete (PLHashEntry *he, PRIntn msgindex, void *arg)
static PRIntn PR_CALLBACK net_pop3_remove_messages_marked_delete (PLHashEntry *he, PRIntn msgindex, void *arg)
PRUint32 TimeInSecondsFromPRTime (PRTime prTime)
static void put_hash (PLHashTable *table, const char *key, char value, PRTime dateReceived)
static PRIntn PR_CALLBACK net_pop3_copy_hash_entries (PLHashEntry *he, PRIntn msgindex, void *arg)
static void *PR_CALLBACK AllocUidlTable (void *, PRSize size)
static void PR_CALLBACK FreeUidlTable (void *, void *item)
static PLHashEntry *PR_CALLBACK AllocUidlInfo (void *pool, const void *key)
static void PR_CALLBACK FreeUidlInfo (void *, PLHashEntry *he, PRUintn flag)
static Pop3UidlHostnet_pop3_load_state (const char *searchhost, const char *searchuser, nsIFileSpec *mailDirectory)
static PRIntn PR_CALLBACK hash_clear_mapper (PLHashEntry *he, PRIntn msgindex, void *arg)
static PRIntn PR_CALLBACK hash_empty_mapper (PLHashEntry *he, PRIntn msgindex, void *arg)
static PRBool hash_empty (PLHashTable *hash)
static PRIntn PR_CALLBACK net_pop3_write_mapper (PLHashEntry *he, PRIntn msgindex, void *arg)
static PRIntn PR_CALLBACK net_pop3_delete_old_msgs_mapper (PLHashEntry *he, PRIntn msgindex, void *arg)
static void net_pop3_write_state (Pop3UidlHost *host, nsIFileSpec *mailDirectory)
static void net_pop3_free_state (Pop3UidlHost *host)

Variables

static PRLogModuleInfoPOP3LOGMODULE = nsnull
static PLHashAllocOps gHashAllocOps

Define Documentation

Definition at line 86 of file nsPop3Protocol.cpp.


Function Documentation

static PLHashEntry* PR_CALLBACK AllocUidlInfo ( void pool,
const void key 
) [static]

Definition at line 203 of file nsPop3Protocol.cpp.

{
    return PR_NEWZAP(PLHashEntry);
}
static void* PR_CALLBACK AllocUidlTable ( void ,
PRSize  size 
) [static]

Definition at line 191 of file nsPop3Protocol.cpp.

{
  return PR_MALLOC(size);
}
static void PR_CALLBACK FreeUidlInfo ( void ,
PLHashEntry he,
PRUintn  flag 
) [static]

Definition at line 209 of file nsPop3Protocol.cpp.

{
  if (flag == HT_FREE_ENTRY)
  {
    Pop3UidlEntry *uidlEntry = (Pop3UidlEntry *) he->value;
    if (uidlEntry)
    {
      PR_Free(uidlEntry->uidl);
      PR_Free(uidlEntry);
    }
    PR_Free(he);
  }
}

Here is the call graph for this function:

static void PR_CALLBACK FreeUidlTable ( void ,
void item 
) [static]

Definition at line 197 of file nsPop3Protocol.cpp.

{
    PR_Free(item);
}
static PRIntn PR_CALLBACK hash_clear_mapper ( PLHashEntry he,
PRIntn  msgindex,
void arg 
) [static]

Definition at line 352 of file nsPop3Protocol.cpp.

{
  Pop3UidlEntry *uidlEntry = (Pop3UidlEntry *) he->value;
  PR_Free(uidlEntry->uidl);
  PR_Free(uidlEntry);
  he->value = nsnull;

  return HT_ENUMERATE_REMOVE;
}

Here is the caller graph for this function:

static PRBool hash_empty ( PLHashTable hash) [static]

Definition at line 370 of file nsPop3Protocol.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

static PRIntn PR_CALLBACK hash_empty_mapper ( PLHashEntry he,
PRIntn  msgindex,
void arg 
) [static]

Definition at line 363 of file nsPop3Protocol.cpp.

{
  *((PRBool*) arg) = PR_FALSE;
  return HT_ENUMERATE_STOP;
}

Here is the caller graph for this function:

static PRIntn PR_CALLBACK net_pop3_check_for_hash_messages_marked_delete ( PLHashEntry he,
PRIntn  msgindex,
void arg 
) [static]

Definition at line 123 of file nsPop3Protocol.cpp.

{
  Pop3UidlEntry *uidlEntry = (Pop3UidlEntry *) he->value;
  if (uidlEntry->status == DELETE_CHAR)
  {
    ((Pop3ConData *) arg)->delete_server_message_during_top_traversal = PR_TRUE;
    return HT_ENUMERATE_STOP;      /* XP_Maphash will stop traversing hash table now */
  }
  
  return HT_ENUMERATE_NEXT;        /* XP_Maphash will continue traversing the hash */
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRIntn PR_CALLBACK net_pop3_copy_hash_entries ( PLHashEntry he,
PRIntn  msgindex,
void arg 
) [static]

Definition at line 182 of file nsPop3Protocol.cpp.

{
  Pop3UidlEntry *uidlEntry = (Pop3UidlEntry *) he->value;
  put_hash((PLHashTable *) arg, uidlEntry->uidl, uidlEntry->status, uidlEntry->dateReceived);
  return HT_ENUMERATE_NEXT;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRIntn PR_CALLBACK net_pop3_delete_old_msgs_mapper ( PLHashEntry he,
PRIntn  msgindex,
void arg 
) [static]

Definition at line 396 of file nsPop3Protocol.cpp.

{
  PRTime cutOffDate = (PRTime) arg;
  Pop3UidlEntry *uidlEntry = (Pop3UidlEntry *) he->value;
  if (uidlEntry->dateReceived < cutOffDate)
    uidlEntry->status = DELETE_CHAR; // mark for deletion
  return HT_ENUMERATE_NEXT;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void net_pop3_free_state ( Pop3UidlHost host) [static]

Definition at line 443 of file nsPop3Protocol.cpp.

{
  Pop3UidlHost* h;
  while (host) 
  {
    h = host->next;
    PR_Free(host->host);
    PR_Free(host->user);
    PL_HashTableDestroy(host->hash);
    PR_Free(host);
    host = h;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static Pop3UidlHost* net_pop3_load_state ( const char *  searchhost,
const char *  searchuser,
nsIFileSpec mailDirectory 
) [static]

Definition at line 230 of file nsPop3Protocol.cpp.

{
  char* buf;
  char* newStr;
  char* host;
  char* user;
  char* uidl;
  char* flags;
  char *dateReceivedStr;
  Pop3UidlHost* result = nsnull;
  Pop3UidlHost* current = nsnull;
  Pop3UidlHost* tmp;
  
  result = PR_NEWZAP(Pop3UidlHost);
  if (!result) return nsnull;
  result->host = PL_strdup(searchhost);
  result->user = PL_strdup(searchuser);
  result->hash = PL_NewHashTable(20, PL_HashString, PL_CompareStrings, PL_CompareValues, &gHashAllocOps, nsnull);
  
  if (!result->host || !result->user || !result->hash) 
  {
    PR_Free(result->host);
    PR_Free(result->user);
    if (result->hash) 
      PL_HashTableDestroy(result->hash);
    PR_Free(result);
    return nsnull;
  }
  
  nsFileSpec fileSpec;
  mailDirectory->GetFileSpec(&fileSpec);
  fileSpec += "popstate.dat";
  
  nsInputFileStream fileStream(fileSpec);
  
  buf = (char*)PR_CALLOC(512);
  if (buf) 
  {
    while (!fileStream.eof() && !fileStream.failed() && fileStream.is_open())
    {
      fileStream.readline(buf, 512);
      if (*buf == '#' || *buf == nsCRT::CR || *buf == nsCRT::LF || *buf == 0)
        continue;
      if (buf[0] == '*') {
        /* It's a host&user line. */
        current = NULL;
        /* XP_FileReadLine uses LF on all platforms */
        host = nsCRT::strtok(buf + 1, " \t\r\n", &newStr);
        /* without space to also get realnames - see bug 225332 */
        user = nsCRT::strtok(newStr, "\t\r\n", &newStr);
        if (host == NULL || user == NULL) continue;
        for (tmp = result ; tmp ; tmp = tmp->next) 
        {
          if (PL_strcmp(host, tmp->host) == 0 &&
            PL_strcmp(user, tmp->user) == 0) 
          {
            current = tmp;
            break;
          }
        }
        if (!current) 
        {
          current = PR_NEWZAP(Pop3UidlHost);
          if (current) 
          {
            current->host = PL_strdup(host);
            current->user = PL_strdup(user);
            current->hash = PL_NewHashTable(20, PL_HashString, PL_CompareStrings, PL_CompareValues, &gHashAllocOps, nsnull);
            if (!current->host || !current->user || !current->hash) 
            {
              PR_Free(current->host);
              PR_Free(current->user);
              if (current->hash) 
                PL_HashTableDestroy(current->hash);
              PR_Free(current);
            }
            else 
            {
              current->next = result->next;
              result->next = current;
            }
          }
        }
      } 
      else 
      {
        /* It's a line with a UIDL on it. */
        if (current) 
        {
          flags = nsCRT::strtok(buf, " \t\r\n", &newStr);             /* XP_FileReadLine uses LF on all platforms */
          uidl = nsCRT::strtok(newStr, " \t\r\n", &newStr);
          dateReceivedStr = nsCRT::strtok(newStr, " \t\r\n", &newStr);
          PRTime dateReceived = PR_Now(); // if we don't find a date str, assume now.
          if (dateReceivedStr)
            dateReceived = atoi(dateReceivedStr);
          if (flags && uidl) 
          {
            if ((flags[0] == KEEP) || (flags[0] == DELETE_CHAR) ||
              (flags[0] == TOO_BIG) || (flags[0] == FETCH_BODY)) 
            {
              put_hash(current->hash, uidl, flags[0], dateReceived);
            }
            else
            {
              NS_ASSERTION(PR_FALSE, "invalid flag in popstate.dat"); 
            }
          }
        }
      }
    }
    
    PR_Free(buf);
  }
  if (fileStream.is_open())
    fileStream.close();
  
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRIntn PR_CALLBACK net_pop3_remove_messages_marked_delete ( PLHashEntry he,
PRIntn  msgindex,
void arg 
) [static]

Definition at line 138 of file nsPop3Protocol.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

static PRIntn PR_CALLBACK net_pop3_write_mapper ( PLHashEntry he,
PRIntn  msgindex,
void arg 
) [static]

Definition at line 379 of file nsPop3Protocol.cpp.

{
  nsOutputFileStream* file = (nsOutputFileStream*) arg;
  Pop3UidlEntry *uidlEntry = (Pop3UidlEntry *) he->value;
  NS_ASSERTION((uidlEntry->status == KEEP) ||
    (uidlEntry->status ==  DELETE_CHAR) ||
    (uidlEntry->status ==  FETCH_BODY) ||
    (uidlEntry->status == TOO_BIG), "invalid status");
  char* tmpBuffer = PR_smprintf("%c %s %d" MSG_LINEBREAK, uidlEntry->status, (char*)
    uidlEntry->uidl, uidlEntry->dateReceived);
  PR_ASSERT(tmpBuffer);
  *file << tmpBuffer;
  PR_Free(tmpBuffer);
  return HT_ENUMERATE_NEXT;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void net_pop3_write_state ( Pop3UidlHost host,
nsIFileSpec mailDirectory 
) [static]

Definition at line 406 of file nsPop3Protocol.cpp.

{
  PRInt32 len = 0;
  
  nsFileSpec fileSpec;
  mailDirectory->GetFileSpec(&fileSpec);
  fileSpec += "popstate.dat";
  
  nsOutputFileStream outFileStream(fileSpec, PR_WRONLY | PR_CREATE_FILE |
    PR_TRUNCATE);
  const char tmpBuffer[] =
    "# POP3 State File" MSG_LINEBREAK
    "# This is a generated file!  Do not edit." MSG_LINEBREAK
    MSG_LINEBREAK;
  
  outFileStream << tmpBuffer;
  
  for (; host && (len >= 0); host = host->next)
  {
    if (!hash_empty(host->hash))
    {
      outFileStream << "*";
      outFileStream << host->host;
      outFileStream << " ";
      outFileStream << host->user;
      outFileStream << MSG_LINEBREAK;
      PL_HashTableEnumerateEntries(host->hash, net_pop3_write_mapper, (void *)&outFileStream);
    }
  }
  if (outFileStream.is_open())
  {
    outFileStream.flush();
    outFileStream.close();
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void put_hash ( PLHashTable table,
const char *  key,
char  value,
PRTime  dateReceived 
) [static]

Definition at line 159 of file nsPop3Protocol.cpp.

{
  Pop3UidlEntry* tmp;

  tmp = PR_NEWZAP(Pop3UidlEntry);
  if (tmp) 
  {
    tmp->uidl = PL_strdup(key);
    if (tmp->uidl) 
    {
      tmp->dateReceived = dateReceived;
      tmp->status = value;
      PL_HashTableAdd(table, (const void *)tmp->uidl, (void*) tmp);
    }
    else 
    {
      PR_Free(tmp);
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 147 of file nsPop3Protocol.cpp.

{
  PRUint32 retTimeInSeconds;

  PRInt64 microSecondsPerSecond, intermediateResult;
  LL_I2L(microSecondsPerSecond, PR_USEC_PER_SEC);
  LL_DIV(intermediateResult, prTime, microSecondsPerSecond);
  LL_L2UI(retTimeInSeconds, intermediateResult);
  return retTimeInSeconds;
}

Here is the caller graph for this function:


Variable Documentation

Initial value:

Definition at line 223 of file nsPop3Protocol.cpp.

Definition at line 88 of file nsPop3Protocol.cpp.