VMime
text Class Reference

#include <text.hpp>

Inheritance diagram for text:
Collaboration diagram for text:

Public Types

enum  EncodeAndFoldFlags {
  FORCE_NO_ENCODING = (1 << 0) , FORCE_ENCODING = (1 << 1) , NO_NEW_LINE_SEQUENCE = (1 << 2) , QUOTE_IF_POSSIBLE = (1 << 3) ,
  QUOTE_IF_NEEDED = (1 << 4)
}

Public Member Functions

 text ()
 text (const text &t)
 text (const string &t, const charset &ch)
 text (const string &t)
 text (const word &w)
 ~text ()
bool operator== (const text &t) const
bool operator!= (const text &t) const
shared_ptr< componentclone () const
void copyFrom (const component &other)
textoperator= (const component &other)
textoperator= (const text &other)
const std::vector< shared_ptr< component > > getChildComponents ()
void appendWord (shared_ptr< word > w)
void insertWordBefore (const size_t pos, shared_ptr< word > w)
void insertWordAfter (const size_t pos, shared_ptr< word > w)
void removeWord (const size_t pos)
void removeAllWords ()
size_t getWordCount () const
bool isEmpty () const
const shared_ptr< wordgetWordAt (const size_t pos)
const shared_ptr< const wordgetWordAt (const size_t pos) const
const std::vector< shared_ptr< const word > > getWordList () const
const std::vector< shared_ptr< word > > getWordList ()
const string getConvertedText (const charset &dest, const charsetConverterOptions &opts=charsetConverterOptions()) const
const string getWholeBuffer () const
void createFromString (const string &in, const charset &ch)
void encodeAndFold (const generationContext &ctx, utility::outputStream &os, const size_t firstLineOffset, size_t *lastLineLength, const int flags) const
Public Member Functions inherited from headerFieldValue
size_t getGeneratedSize (const generationContext &ctx)
Public Member Functions inherited from component
 component ()
virtual ~component ()
void parse (const string &buffer)
void parse (const parsingContext &ctx, const string &buffer)
void parse (shared_ptr< utility::inputStream > inputStream, const size_t length)
void parse (const string &buffer, const size_t position, const size_t end, size_t *newPosition=NULL)
void parse (const parsingContext &ctx, const string &buffer, const size_t position, const size_t end, size_t *newPosition=NULL)
void parse (shared_ptr< utility::inputStream > inputStream, const size_t position, const size_t end, size_t *newPosition=NULL)
void parse (const parsingContext &ctx, shared_ptr< utility::inputStream > inputStream, const size_t position, const size_t end, size_t *newPosition=NULL)
virtual const string generate (const size_t maxLineLength=lineLengthLimits::infinite, const size_t curLinePos=0) const
virtual void generate (utility::outputStream &outputStream, const size_t curLinePos=0, size_t *newLinePos=NULL) const
virtual void generate (const generationContext &ctx, utility::outputStream &outputStream, const size_t curLinePos=0, size_t *newLinePos=NULL) const
size_t getParsedOffset () const
size_t getParsedLength () const

Static Public Member Functions

static shared_ptr< textnewFromString (const string &in, const charset &ch)
static shared_ptr< textdecodeAndUnfold (const string &in)
static shared_ptr< textdecodeAndUnfold (const parsingContext &ctx, const string &in)
static textdecodeAndUnfold (const string &in, text *generateInExisting)
static textdecodeAndUnfold (const parsingContext &ctx, const string &in, text *generateInExisting)

Protected Member Functions

void parseImpl (const parsingContext &ctx, const string &buffer, const size_t position, const size_t end, size_t *newPosition=NULL)
void generateImpl (const generationContext &ctx, utility::outputStream &os, const size_t curLinePos=0, size_t *newLinePos=NULL) const
Protected Member Functions inherited from component
void setParsedBounds (const size_t start, const size_t end)
virtual void parseImpl (const parsingContext &ctx, shared_ptr< utility::parserInputStreamAdapter > parser, const size_t position, const size_t end, size_t *newPosition=NULL)
Protected Member Functions inherited from object
 object ()
 object (const object &)
objectoperator= (const object &)
virtual ~object ()

Static Protected Member Functions

static void fixBrokenWords (std::vector< shared_ptr< word > > &words)

Detailed Description

List of encoded-words, as defined in RFC-2047 (basic type).

Member Enumeration Documentation

◆ EncodeAndFoldFlags

Flags used by "encodeAndFold" function.

Enumerator
FORCE_NO_ENCODING 

Just fold lines, don't encode them.

FORCE_ENCODING 

Encode lines even if they are plain ASCII text.

NO_NEW_LINE_SEQUENCE 

Use CRLF instead of new-line sequence (CRLF + TAB).

QUOTE_IF_POSSIBLE 

Use quoting instead of encoding when possible (even if FORCE_ENCODING is specified).

QUOTE_IF_NEEDED 

Use quoting instead of encoding if needed (eg.

whitespaces and/or special chars).

Constructor & Destructor Documentation

◆ text() [1/5]

◆ text() [2/5]

text ( const text & t)

References copyFrom(), and text().

◆ text() [3/5]

text ( const string & t,
const charset & ch )

References createFromString().

◆ text() [4/5]

text ( const string & t)
explicit

◆ text() [5/5]

text ( const word & w)
explicit

References appendWord().

◆ ~text()

~text ( )

References removeAllWords().

Member Function Documentation

◆ appendWord()

void appendWord ( shared_ptr< word > w)

Add a word at the end of the list.

Parameters
wword to append

Referenced by createFromString(), text(), and emailAddress::toText().

◆ clone()

shared_ptr< component > clone ( ) const
virtual

Clone this component.

Returns
a copy of this component

Implements component.

Referenced by htmlTextPart::setText().

◆ copyFrom()

void copyFrom ( const component & other)
virtual

Replace data in this component by data in other component.

Both components must be of the same type.

Exceptions
std::bad_cast_exceptionif the components are not of the same (dynamic) type
Parameters
otherother component to copy data from

Implements component.

References removeAllWords(), and text().

Referenced by operator=(), operator=(), and text().

◆ createFromString()

void createFromString ( const string & in,
const charset & ch )

This function can be used to make several encoded words from a text.

All the characters in the text must be in the same specified charset.

Eg: giving:

   <iso-8859-1> "Linux dans un t'el'ephone mobile"
   ("=?iso-8859-1?Q?Linux_dans_un_t=E9l=E9phone_mobile?=")

it will return:

   <us-ascii>   "Linux dans un "
   <iso-8859-1> "t'el'ephone "
   <us-ascii>   "mobile"
   ("Linux dans un =?iso-8859-1?Q?t=E9l=E9phone_?= mobile")
Parameters
ininput string
chinput charset

References appendWord(), vmime::count(), stringUtils::countASCIIchars(), vmime::end(), charset::getRecommendedEncoding(), getWordAt(), getWordCount(), parserHelpers::isAscii(), parserHelpers::isSpace(), removeAllWords(), and vmime::charsets::US_ASCII.

Referenced by text(), and text().

◆ decodeAndUnfold() [1/4]

shared_ptr< text > decodeAndUnfold ( const parsingContext & ctx,
const string & in )
static

Decode and unfold text (RFC-2047).

Parameters
ctxparsingContext
ininput string
Returns
new text object

References decodeAndUnfold().

◆ decodeAndUnfold() [2/4]

text * decodeAndUnfold ( const parsingContext & ctx,
const string & in,
text * generateInExisting )
static

Decode and unfold text (RFC-2047).

Parameters
ctxparsing context
ininput string
generateInExistingif not NULL, the resulting text will be generated in the specified object instead of a new created object (in this case, the function returns the same pointer). Can be used to avoid copying the resulting object into an existing object.
Returns
new text object or existing object if generateInExisting != NULL

References vmime::copy_vector(), fixBrokenWords(), removeAllWords(), and text().

◆ decodeAndUnfold() [3/4]

shared_ptr< text > decodeAndUnfold ( const string & in)
static

Decode and unfold text (RFC-2047), using the default parsing context.

Parameters
ininput string
Returns
new text object

References decodeAndUnfold(), and parsingContext::getDefaultContext().

Referenced by decodeAndUnfold(), decodeAndUnfold(), decodeAndUnfold(), mailbox::parseImpl(), and mailboxGroup::parseImpl().

◆ decodeAndUnfold() [4/4]

text * decodeAndUnfold ( const string & in,
text * generateInExisting )
static

Decode and unfold text (RFC-2047), using the default parsing context.

Parameters
ininput string
generateInExistingif not NULL, the resulting text will be generated in the specified object instead of a new created object (in this case, the function returns the same pointer). Can be used to avoid copying the resulting object into an existing object.
Returns
new text object or existing object if generateInExisting != NULL

References decodeAndUnfold(), parsingContext::getDefaultContext(), and text().

◆ encodeAndFold()

void encodeAndFold ( const generationContext & ctx,
utility::outputStream & os,
const size_t firstLineOffset,
size_t * lastLineLength,
const int flags ) const

Encode and fold text in respect to RFC-2047.

Parameters
ctxgeneration context
osoutput stream
firstLineOffsetthe first line length (may be useful if the current output line is not empty)
lastLineLengthwill receive the length of the last line written
flagsencoding flags (see EncodeAndFoldFlags)

References getWordAt(), and getWordCount().

Referenced by body::generateImpl(), relay::generateImpl(), generateImpl(), and body::getGeneratedSize().

◆ fixBrokenWords()

void fixBrokenWords ( std::vector< shared_ptr< word > > & words)
staticprotected

Referenced by decodeAndUnfold().

◆ generateImpl()

void generateImpl ( const generationContext & ctx,
utility::outputStream & os,
const size_t curLinePos = 0,
size_t * newLinePos = NULL ) const
protectedvirtual

Implements component.

References encodeAndFold().

◆ getChildComponents()

const std::vector< shared_ptr< component > > getChildComponents ( )
virtual

Return the list of children of this component.

Returns
list of child components

Implements component.

References vmime::copy_vector().

◆ getConvertedText()

const string getConvertedText ( const charset & dest,
const charsetConverterOptions & opts = charsetConverterOptions() ) const

Return the text converted into the specified charset.

The encoded-words are decoded and then converted in the specified destination charset.

Parameters
destoutput charset
optsoptions for charset conversion
Returns
text decoded in the specified charset

Referenced by SMTPCommand::MAIL(), SMTPCommand::RCPT(), and courierMaildirFormat::toModifiedUTF7().

◆ getWholeBuffer()

const string getWholeBuffer ( ) const

Return the unconverted (raw) data of all words.

This is the concatenation of the results returned by getBuffer() on the contained words.

Returns
raw data

Referenced by importanceHelper::getImportanceHeader(), htmlTextPart::parse(), and body::parseImpl().

◆ getWordAt() [1/2]

const shared_ptr< word > getWordAt ( const size_t pos)

Return the word at the specified position.

Parameters
posposition
Returns
word at position 'pos'

Referenced by createFromString(), and encodeAndFold().

◆ getWordAt() [2/2]

const shared_ptr< const word > getWordAt ( const size_t pos) const

Return the word at the specified position.

Parameters
posposition
Returns
word at position 'pos'

◆ getWordCount()

size_t getWordCount ( ) const

Return the number of words in the list.

Returns
number of words

Referenced by createFromString(), encodeAndFold(), and operator==().

◆ getWordList() [1/2]

const std::vector< shared_ptr< word > > getWordList ( )

Return the word list.

Returns
list of words

◆ getWordList() [2/2]

const std::vector< shared_ptr< const word > > getWordList ( ) const

Return the word list.

Returns
list of words

◆ insertWordAfter()

void insertWordAfter ( const size_t pos,
shared_ptr< word > w )

Insert a new word after the specified position.

Parameters
posposition of the word before the new word
wword to insert

◆ insertWordBefore()

void insertWordBefore ( const size_t pos,
shared_ptr< word > w )

Insert a new word before the specified position.

Parameters
posposition at which to insert the new word (0 to insert at the beginning of the list)
wword to insert

◆ isEmpty()

bool isEmpty ( ) const

Tests whether the list of words is empty.

Returns
true if there is no word, false otherwise

Referenced by body::generateImpl(), and body::getGeneratedSize().

◆ newFromString()

shared_ptr< text > newFromString ( const string & in,
const charset & ch )
static

This function can be used to make several encoded words from a text.

All the characters in the text must be in the same specified charset.

Eg: giving:

   <iso-8859-1> "Linux dans un t'el'ephone mobile"
   ("=?iso-8859-1?Q?Linux_dans_un_t=E9l=E9phone_mobile?=")

it will return:

   <us-ascii>   "Linux dans un "
   <iso-8859-1> "t'el'ephone "
   <us-ascii>   "mobile"
   ("Linux dans un =?iso-8859-1?Q?t=E9l=E9phone_?= mobile")
Parameters
ininput string
chinput charset
Returns
new text object

◆ operator!=()

bool operator!= ( const text & t) const

References text().

◆ operator=() [1/2]

text & operator= ( const component & other)

References copyFrom(), and text().

◆ operator=() [2/2]

text & operator= ( const text & other)

References copyFrom(), and text().

◆ operator==()

bool operator== ( const text & t) const

References getWordCount(), and text().

◆ parseImpl()

void parseImpl ( const parsingContext & ctx,
const string & buffer,
const size_t position,
const size_t end,
size_t * newPosition = NULL )
protectedvirtual

◆ removeAllWords()

void removeAllWords ( )

Remove all words from the list.

Referenced by copyFrom(), createFromString(), decodeAndUnfold(), parseImpl(), and ~text().

◆ removeWord()

void removeWord ( const size_t pos)

Remove the word at the specified position.

Parameters
posposition of the word to remove

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