Back to index

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

#include <nsIMAPBodyShell.h>

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

List of all members.

Public Member Functions

 nsIMAPBodypartLeaf (char *partNum, nsIMAPBodypart *parentPart, char *bodyType, char *bodySubType, char *bodyID, char *bodyDescription, char *bodyEncoding, PRInt32 partLength)
virtual nsIMAPBodypartType GetType ()
virtual PRInt32 Generate (nsIMAPBodyShell *aShell, PRBool stream, PRBool prefetch)
virtual PRBool ShouldFetchInline (nsIMAPBodyShell *aShell)
virtual PRBool PreflightCheckAllInline (nsIMAPBodyShell *aShell)
virtual PRBool GetIsValid ()
virtual void SetIsValid (PRBool valid)
virtual void AdoptPartDataBuffer (char *buf)
virtual void AdoptHeaderDataBuffer (char *buf)
virtual PRBool ShouldExplicitlyFetchInline ()
virtual PRBool ShouldExplicitlyNotFetchInline ()
virtual PRBool IsLastTextPart (const char *partNumberString)
virtual char * GetPartNumberString ()
virtual nsIMAPBodypartFindPartWithNumber (const char *partNum)
virtual nsIMAPBodypartGetParentPart ()
virtual nsIMAPBodypartMessageGetnsIMAPBodypartMessage ()
const char * GetBodyType ()
const char * GetBodySubType ()
void SetBoundaryData (char *boundaryData)

Protected Member Functions

virtual PRInt32 GeneratePart (nsIMAPBodyShell *aShell, PRBool stream, PRBool prefetch)
virtual PRInt32 GenerateMIMEHeader (nsIMAPBodyShell *aShell, PRBool stream, PRBool prefetch)
virtual PRInt32 GenerateBoundary (nsIMAPBodyShell *aShell, PRBool stream, PRBool prefetch, PRBool lastBoundary)
virtual PRInt32 GenerateEmptyFilling (nsIMAPBodyShell *aShell, PRBool stream, PRBool prefetch)
virtual void QueuePrefetchMIMEHeader (nsIMAPBodyShell *aShell)

Protected Attributes

PRBool m_isValid
char * m_partNumberString
char * m_partData
char * m_headerData
char * m_boundaryData
PRInt32 m_partLength
PRInt32 m_contentLength
nsIMAPBodypartm_parentPart
char * m_contentType
char * m_bodyType
char * m_bodySubType
char * m_bodyID
char * m_bodyDescription
char * m_bodyEncoding

Detailed Description

Definition at line 178 of file nsIMAPBodyShell.h.


Constructor & Destructor Documentation

nsIMAPBodypartLeaf::nsIMAPBodypartLeaf ( char *  partNum,
nsIMAPBodypart parentPart,
char *  bodyType,
char *  bodySubType,
char *  bodyID,
char *  bodyDescription,
char *  bodyEncoding,
PRInt32  partLength 
)

Definition at line 592 of file nsIMAPBodyShell.cpp.

                                                                                                                  : 
nsIMAPBodypart(partNum, parentPart)
{
  m_bodyType = bodyType;
  m_bodySubType = bodySubType;
  m_bodyID = bodyID;
  m_bodyDescription = bodyDescription;
  m_bodyEncoding = bodyEncoding;
  m_partLength = partLength;
  if (m_bodyType && m_bodySubType)
  {
    m_contentType = PR_smprintf("%s/%s", m_bodyType, m_bodySubType);
  }
  SetIsValid(PR_TRUE);
}

Here is the call graph for this function:


Member Function Documentation

void nsIMAPBodypart::AdoptHeaderDataBuffer ( char *  buf) [virtual, inherited]

Definition at line 394 of file nsIMAPBodyShell.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIMAPBodypart::AdoptPartDataBuffer ( char *  buf) [virtual, inherited]

Definition at line 384 of file nsIMAPBodyShell.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

nsIMAPBodypart * nsIMAPBodypart::FindPartWithNumber ( const char *  partNum) [virtual, inherited]

Reimplemented in nsIMAPBodypartMessage, and nsIMAPBodypartMultipart.

Definition at line 406 of file nsIMAPBodyShell.cpp.

{
  // either brute force, or do it the smart way - look at the number.
  // (the parts should be ordered, and hopefully indexed by their number)
  
  if (m_partNumberString && !PL_strcasecmp(partNum, m_partNumberString))
    return this;
  
  //if (!m_partNumberString && !PL_strcasecmp(partNum, "1"))
  //   return this;
  
  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRInt32 nsIMAPBodypartLeaf::Generate ( nsIMAPBodyShell aShell,
PRBool  stream,
PRBool  prefetch 
) [virtual]

Reimplemented from nsIMAPBodypart.

Reimplemented in nsIMAPBodypartMessage.

Definition at line 614 of file nsIMAPBodyShell.cpp.

{
  PRInt32 len = 0;
  
  if (GetIsValid())
  {
    
    if (stream && !prefetch)
      aShell->GetConnection()->Log("SHELL","GENERATE-Leaf",m_partNumberString);
    
    // Stream out the MIME part boundary
    //GenerateBoundary();
    NS_ASSERTION(m_parentPart, "part has no parent");
    //nsIMAPBodypartMessage *parentMessage = m_parentPart ? m_parentPart->GetnsIMAPBodypartMessage() : NULL;
    
    // Stream out the MIME header of this part, if this isn't the only body part of a message
    //if (parentMessage ? !parentMessage->GetIsTopLevelMessage() : PR_TRUE)
    if ((m_parentPart->GetType() != IMAP_BODY_MESSAGE_RFC822)
      && !aShell->GetPseudoInterrupted())
      len += GenerateMIMEHeader(aShell, stream, prefetch);
    
    if (!aShell->GetPseudoInterrupted())
    {
      if (ShouldFetchInline(aShell))
      {
        // Fetch and stream the content of this part
        len += GeneratePart(aShell, stream, prefetch);
      }
      else
      {
        // fill in the filling within the empty part
        len += GenerateEmptyFilling(aShell, stream, prefetch);
      }
    }
  }
  m_contentLength = len;
  return m_contentLength;
}

Here is the call graph for this function:

PRInt32 nsIMAPBodypart::GenerateBoundary ( nsIMAPBodyShell aShell,
PRBool  stream,
PRBool  prefetch,
PRBool  lastBoundary 
) [protected, virtual, inherited]

Definition at line 511 of file nsIMAPBodyShell.cpp.

{
  if (prefetch)
    return 0; // don't need to prefetch anything
  
  if (m_boundaryData)
  {
    if (!lastBoundary)
    {
      if (stream)
      {
        aShell->GetConnection()->Log("SHELL","GENERATE-Boundary",m_partNumberString);
        aShell->GetConnection()->HandleMessageDownLoadLine(m_boundaryData, PR_FALSE);
      }
      return PL_strlen(m_boundaryData);
    }
    else      // the last boundary
    {
      char *lastBoundaryData = PR_smprintf("%s--", m_boundaryData);
      if (lastBoundaryData)
      {
        if (stream)
        {
          aShell->GetConnection()->Log("SHELL","GENERATE-Boundary-Last",m_partNumberString);
          aShell->GetConnection()->HandleMessageDownLoadLine(lastBoundaryData, PR_FALSE);
        }
        PRInt32 rv = PL_strlen(lastBoundaryData);
        PR_Free(lastBoundaryData);
        return rv;
      }
      else
      {
        //HandleMemoryFailure();
        return 0;
      }
    }
  }
  else
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRInt32 nsIMAPBodypart::GenerateEmptyFilling ( nsIMAPBodyShell aShell,
PRBool  stream,
PRBool  prefetch 
) [protected, virtual, inherited]

Definition at line 552 of file nsIMAPBodyShell.cpp.

{
  if (prefetch)
    return 0; // don't need to prefetch anything
  
  const char emptyString[] = "This body part will be downloaded on demand.";
  // XP_GetString(MK_IMAP_EMPTY_MIME_PART);  ### need to be able to localize
  if (emptyString)
  {
    if (stream)
    {
      aShell->GetConnection()->Log("SHELL","GENERATE-Filling",m_partNumberString);
      aShell->GetConnection()->HandleMessageDownLoadLine(emptyString, PR_FALSE);
    }
    return PL_strlen(emptyString);
  }
  else
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRInt32 nsIMAPBodypart::GenerateMIMEHeader ( nsIMAPBodyShell aShell,
PRBool  stream,
PRBool  prefetch 
) [protected, virtual, inherited]

Definition at line 440 of file nsIMAPBodyShell.cpp.

{
  if (prefetch && !m_headerData)
  {
    QueuePrefetchMIMEHeader(aShell);
    return 0;
  }
  else if (m_headerData)
  {
    PRInt32 mimeHeaderLength = 0;
    
    if (!ShouldFetchInline(aShell))
    {
      // if this part isn't inline, add the X-Mozilla-IMAP-Part header
      char *xPartHeader = PR_smprintf("%s: %s", IMAP_EXTERNAL_CONTENT_HEADER, m_partNumberString);
      if (xPartHeader)
      {
        if (stream)
        {
          aShell->GetConnection()->Log("SHELL","GENERATE-XHeader",m_partNumberString);
          aShell->GetConnection()->HandleMessageDownLoadLine(xPartHeader, PR_FALSE);
        }
        mimeHeaderLength += PL_strlen(xPartHeader);
        PR_Free(xPartHeader);
      }
    }
    
    mimeHeaderLength += PL_strlen(m_headerData);
    if (stream)
    {
      aShell->GetConnection()->Log("SHELL","GENERATE-MIMEHeader",m_partNumberString);
      aShell->GetConnection()->HandleMessageDownLoadLine(m_headerData, PR_FALSE);  // all one line?  Can we do that?
    }
    
    return mimeHeaderLength;
  }
  else 
  {
    SetIsValid(PR_FALSE);   // prefetch didn't adopt a MIME header
    return 0;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRInt32 nsIMAPBodypart::GeneratePart ( nsIMAPBodyShell aShell,
PRBool  stream,
PRBool  prefetch 
) [protected, virtual, inherited]

Definition at line 483 of file nsIMAPBodyShell.cpp.

{
  if (prefetch)
    return 0; // don't need to prefetch anything
  
  if (m_partData)    // we have prefetched the part data
  {
    if (stream)
    {
      aShell->GetConnection()->Log("SHELL","GENERATE-Part-Prefetched",m_partNumberString);
      aShell->GetConnection()->HandleMessageDownLoadLine(m_partData, PR_FALSE);
    }
    return PL_strlen(m_partData);
  }
  else // we are fetching and streaming this part's body as we go
  {
    if (stream && !aShell->DeathSignalReceived())
    {
      char *generatingPart = aShell->GetGeneratingPart();
      PRBool fetchingSpecificPart = (generatingPart && !PL_strcmp(generatingPart, m_partNumberString));
      
      aShell->GetConnection()->Log("SHELL","GENERATE-Part-Inline",m_partNumberString);
      aShell->GetConnection()->FetchTryChunking(aShell->GetUID().get(), kMIMEPart, PR_TRUE, m_partNumberString, m_partLength, !fetchingSpecificPart);
    }
    return m_partLength;    // the part length has been filled in from the BODYSTRUCTURE response
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* nsIMAPBodypart::GetBodySubType ( ) [inline, inherited]

Definition at line 110 of file nsIMAPBodyShell.h.

{ return m_bodySubType; }

Here is the caller graph for this function:

const char* nsIMAPBodypart::GetBodyType ( ) [inline, inherited]

Definition at line 109 of file nsIMAPBodyShell.h.

{ return m_bodyType; }

Here is the caller graph for this function:

virtual PRBool nsIMAPBodypart::GetIsValid ( ) [inline, virtual, inherited]

Definition at line 65 of file nsIMAPBodyShell.h.

{ return m_isValid; }

Here is the caller graph for this function:

virtual nsIMAPBodypartMessage* nsIMAPBodypart::GetnsIMAPBodypartMessage ( ) [inline, virtual, inherited]

Reimplemented in nsIMAPBodypartMessage.

Definition at line 107 of file nsIMAPBodyShell.h.

{ return NULL; }

Here is the caller graph for this function:

virtual nsIMAPBodypart* nsIMAPBodypart::GetParentPart ( ) [inline, virtual, inherited]

Definition at line 98 of file nsIMAPBodyShell.h.

{ return m_parentPart; }    // Returns the parent of this part.

Here is the caller graph for this function:

virtual char* nsIMAPBodypart::GetPartNumberString ( ) [inline, virtual, inherited]

Definition at line 96 of file nsIMAPBodyShell.h.

{ return m_partNumberString; }

Here is the caller graph for this function:

Implements nsIMAPBodypart.

Reimplemented in nsIMAPBodypartMessage.

Definition at line 609 of file nsIMAPBodyShell.cpp.

{
  return IMAP_BODY_LEAF;
}
virtual PRBool nsIMAPBodypart::IsLastTextPart ( const char *  partNumberString) [inline, virtual, inherited]

Reimplemented in nsIMAPBodypartMultipart.

Definition at line 79 of file nsIMAPBodyShell.h.

{return PR_TRUE;}

Here is the caller graph for this function:

Reimplemented from nsIMAPBodypart.

Reimplemented in nsIMAPBodypartMessage.

Definition at line 804 of file nsIMAPBodyShell.cpp.

{
  // only need to check this part, since it has no children.
  return ShouldFetchInline(aShell);
}

Here is the call graph for this function:

void nsIMAPBodypart::QueuePrefetchMIMEHeader ( nsIMAPBodyShell aShell) [protected, virtual, inherited]

Definition at line 435 of file nsIMAPBodyShell.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIMAPBodypart::SetBoundaryData ( char *  boundaryData) [inline, inherited]

Definition at line 111 of file nsIMAPBodyShell.h.

{ m_boundaryData = boundaryData; }

Here is the caller graph for this function:

void nsIMAPBodypart::SetIsValid ( PRBool  valid) [virtual, inherited]

Definition at line 374 of file nsIMAPBodyShell.cpp.

{
  m_isValid = valid;
  if (!m_isValid)
  {
    //PR_LOG(IMAP, out, ("BODYSHELL: Part is invalid.  Part Number: %s Content-Type: %s", m_partNumberString, m_contentType));
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 575 of file nsIMAPBodyShell.cpp.

{
        return PR_FALSE;
}

Here is the caller graph for this function:

Definition at line 583 of file nsIMAPBodyShell.cpp.

{
  return PR_FALSE;
}

Here is the caller graph for this function:

Reimplemented from nsIMAPBodypart.

Reimplemented in nsIMAPBodypartMessage.

Definition at line 656 of file nsIMAPBodyShell.cpp.

{
  char *generatingPart = aShell->GetGeneratingPart();
  if (generatingPart)
  {
    // If we are generating a specific part
    if (!PL_strcmp(generatingPart, m_partNumberString))
    {
      // This is the part we're generating
      return PR_TRUE;
    }
    else
    {
      // If this is the only body part of a message, and that
      // message is the part being generated, then this leaf should
      // be inline as well.
      if ((m_parentPart->GetType() == IMAP_BODY_MESSAGE_RFC822) &&
        (!PL_strcmp(m_parentPart->GetPartNumberString(), generatingPart)))
        return PR_TRUE;
      
      // The parent of this part is a multipart
      if (m_parentPart->GetType() == IMAP_BODY_MULTIPART)
      {
        // This is the first text part of a forwarded message
        // with a multipart body, and that message is being generated,
        // then generate this part.
        nsIMAPBodypart *grandParent = m_parentPart->GetParentPart();
        NS_ASSERTION(grandParent, "grandparent doesn't exist for multi-part alt");         // grandParent must exist, since multiparts need parents
        if (grandParent && 
          (grandParent->GetType() == IMAP_BODY_MESSAGE_RFC822) &&
          (!PL_strcmp(grandParent->GetPartNumberString(), generatingPart)) &&
          (m_partNumberString[PL_strlen(m_partNumberString)-1] == '1') &&
          !PL_strcasecmp(m_bodyType, "text"))
          return PR_TRUE;   // we're downloading it inline
        
        
        // This is a child of a multipart/appledouble attachment,
        // and that multipart/appledouble attachment is being generated
        if (m_parentPart &&
          !PL_strcasecmp(m_parentPart->GetBodySubType(), "appledouble") &&
          !PL_strcmp(m_parentPart->GetPartNumberString(), generatingPart))
          return PR_TRUE;   // we're downloading it inline
      }
      
      // Leave out all other leaves if this isn't the one
      // we're generating.
      // Maybe change later to check parents, etc.
      return PR_FALSE;
    }
  }
  else
  {
    // We are generating the whole message, possibly (hopefully)
    // leaving out non-inline parts
    
    if (ShouldExplicitlyFetchInline())
      return PR_TRUE;
    if (ShouldExplicitlyNotFetchInline())
      return PR_FALSE;
    
    // If the parent is a message (this is the only body part of that
    // message), and that message should be inline, then its body
    // should inherit the inline characteristics of that message
    if (m_parentPart->GetType() == IMAP_BODY_MESSAGE_RFC822)
      return m_parentPart->ShouldFetchInline(aShell);
    
    // View Attachments As Links is on.
    if (!(aShell->GetContentModified() == IMAP_CONTENT_MODIFIED_VIEW_INLINE))
    {
      // The last text part is still displayed inline,
      // even if View Attachments As Links is on.
      nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
      PRBool preferPlainText = PR_FALSE;
      if (prefBranch)
        prefBranch->GetBoolPref("mailnews.display.prefer_plaintext", &preferPlainText);

      nsIMAPBodypart *grandParentPart = m_parentPart->GetParentPart();
      if (((preferPlainText || !PL_strcasecmp(m_parentPart->GetBodySubType(), "mixed")) 
              && !PL_strcmp(m_partNumberString, "1") 
              && !PL_strcasecmp(m_bodyType, "text"))
          || ((!PL_strcasecmp(m_parentPart->GetBodySubType(), "alternative") ||
                (grandParentPart && !PL_strcasecmp(grandParentPart->GetBodySubType(), "alternative"))) &&
                m_parentPart->IsLastTextPart(m_partNumberString)))
      {
        return PR_TRUE;     // we're downloading it inline
      }
      else
      {
        // This is the first text part of a top-level multipart.
        // For instance, a message with multipart body, where the first
        // part is multipart, and this is the first leaf of that first part.
        if (m_parentPart->GetType() == IMAP_BODY_MULTIPART &&
          (PL_strlen(m_partNumberString) >= 2) &&
          !PL_strcmp(m_partNumberString + PL_strlen(m_partNumberString) - 2, ".1") &&      // this is the first text type on this level
          (!PL_strcmp(m_parentPart->GetPartNumberString(), "1") || !PL_strcmp(m_parentPart->GetPartNumberString(), "2")) &&
          !PL_strcasecmp(m_bodyType, "text"))
          return PR_TRUE;
        else
          return PR_FALSE;  // we can leave it on the server
      }
    }
#if defined(XP_MAC) || defined(XP_MACOSX)
    // If it is either applesingle, or a resource fork for appledouble
    if (!PL_strcasecmp(m_contentType, "application/applefile"))
    {
      // if it is appledouble
      if (m_parentPart->GetType() == IMAP_BODY_MULTIPART &&
        !PL_strcasecmp(m_parentPart->GetBodySubType(), "appledouble"))
      {
        // This is the resource fork of a multipart/appledouble.
        // We inherit the inline attributes of the parent,
        // which was derived from its OTHER child.  (The data fork.)
        return m_parentPart->ShouldFetchInline(aShell);
      }
      else    // it is applesingle
      {
        return PR_FALSE;    // we can leave it on the server
      }
    }
#endif // XP_MAC
    
    // Leave out parts with type application/*
    if (!PL_strcasecmp(m_bodyType, "APPLICATION") &&    // If it is of type "application"
      PL_strncasecmp(m_bodySubType, "x-pkcs7", 7)       // and it's not a signature (signatures are inline)
      )
      return PR_FALSE;      // we can leave it on the server
    
    // Here's where we can add some more intelligence -- let's leave out
    // any other parts that we know we can't display inline.
    return PR_TRUE;  // we're downloading it inline
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

char* nsIMAPBodypart::m_bodyDescription [protected, inherited]

Definition at line 133 of file nsIMAPBodyShell.h.

char* nsIMAPBodypart::m_bodyEncoding [protected, inherited]

Definition at line 134 of file nsIMAPBodyShell.h.

char* nsIMAPBodypart::m_bodyID [protected, inherited]

Definition at line 132 of file nsIMAPBodyShell.h.

char* nsIMAPBodypart::m_bodySubType [protected, inherited]

Definition at line 131 of file nsIMAPBodyShell.h.

char* nsIMAPBodypart::m_bodyType [protected, inherited]

Definition at line 130 of file nsIMAPBodyShell.h.

char* nsIMAPBodypart::m_boundaryData [protected, inherited]

Definition at line 123 of file nsIMAPBodyShell.h.

PRInt32 nsIMAPBodypart::m_contentLength [protected, inherited]

Definition at line 125 of file nsIMAPBodyShell.h.

char* nsIMAPBodypart::m_contentType [protected, inherited]

Definition at line 129 of file nsIMAPBodyShell.h.

char* nsIMAPBodypart::m_headerData [protected, inherited]

Definition at line 122 of file nsIMAPBodyShell.h.

PRBool nsIMAPBodypart::m_isValid [protected, inherited]

Definition at line 119 of file nsIMAPBodyShell.h.

Definition at line 126 of file nsIMAPBodyShell.h.

char* nsIMAPBodypart::m_partData [protected, inherited]

Definition at line 121 of file nsIMAPBodyShell.h.

PRInt32 nsIMAPBodypart::m_partLength [protected, inherited]

Definition at line 124 of file nsIMAPBodyShell.h.

char* nsIMAPBodypart::m_partNumberString [protected, inherited]

Definition at line 120 of file nsIMAPBodyShell.h.


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