MIMEState.h
上传用户:weiyuanprp
上传日期:2020-05-20
资源大小:1169k
文件大小:5k
源码类别:

传真(Fax)编程

开发平台:

C/C++

  1. /* $Id: MIMEState.h,v 1.3 2008/02/07 18:26:39 faxguy Exp $ */
  2. /*
  3.  * Copyright (c) 1990-1996 Sam Leffler
  4.  * Copyright (c) 1991-1996 Silicon Graphics, Inc.
  5.  * HylaFAX is a trademark of Silicon Graphics
  6.  *
  7.  * Permission to use, copy, modify, distribute, and sell this software and 
  8.  * its documentation for any purpose is hereby granted without fee, provided
  9.  * that (i) the above copyright notices and this permission notice appear in
  10.  * all copies of the software and related documentation, and (ii) the names of
  11.  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  12.  * publicity relating to the software without the specific, prior written
  13.  * permission of Sam Leffler and Silicon Graphics.
  14.  * 
  15.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  16.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  17.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  18.  * 
  19.  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  20.  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  21.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  22.  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  23.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  24.  * OF THIS SOFTWARE.
  25.  */
  26. #ifndef _MIMEState_
  27. #define _MIMEState_
  28. /*
  29.  * MIME Decoder Support.
  30.  */
  31. #include "Str.h"
  32. enum Encoding { // content-transfer-encoding
  33.     ENC_7BIT, // 7-bit data
  34.     ENC_QPRINT, // quoted-printable text
  35.     ENC_BASE64, // base64-encoded data
  36.     ENC_8BIT, // 8-bit data
  37.     ENC_BINARY, // ``binary'' data
  38.     ENC_UUENCODE // uuencode'd data
  39. };
  40. enum Charset { // charset
  41.     CS_USASCII, // us-ascii
  42.     CS_ISO8859_1, // iso-8859-1
  43.     CS_ISO8859_2, // iso-8859-2
  44.     CS_ISO8859_3, // iso-8859-3
  45.     CS_ISO8859_4, // iso-8859-4
  46.     CS_ISO8859_5, // iso-8859-5
  47.     CS_ISO8859_6, // iso-8859-6
  48.     CS_ISO8859_7, // iso-8859-7
  49.     CS_ISO8859_8, // iso-8859-8
  50.     CS_ISO8859_9 // iso-8859-9
  51. };
  52. class fxStackBuffer;
  53. class MsgFmt;
  54. class MIMEState {
  55. private:
  56.     MIMEState* parent;
  57.     fxStr type; // content type
  58.     fxStr subtype; // content subtype
  59.     fxStr desc; // content description
  60.     fxStr cid; // content ID
  61.     fxStr disp; // content disposition
  62.     fxStr boundary; // multipart boundary marker
  63.     u_int blen; // adjusted boundary length
  64.     bool lastPart; // true if last multipart boundary seen
  65.     Encoding encode; // content transfer encoding
  66.     Charset charset; // text character set
  67.     static bool parseToken(const char*&, const char delimeter, fxStr& result);
  68.     void parseParameters(const char*);
  69. protected:
  70.     virtual bool setParameter(const fxStr& param, const fxStr& value);
  71.     bool getQuotedPrintableLine(FILE* fd, fxStackBuffer& buf);
  72.     bool getBase64Line(FILE* fd, fxStackBuffer& buf);
  73.     bool getUUDecodeLine(FILE* fd, fxStackBuffer& buf);
  74. public:
  75.     MIMEState(const char* type, const char* subtype);
  76.     MIMEState(MIMEState& parent);
  77.     MIMEState(MIMEState& parent, const char* type, const char* subtype);
  78.     virtual ~MIMEState();
  79.     u_int lineno; // input line number
  80.     bool external; // true if part was formatted externally
  81.     bool parse(const MsgFmt&, fxStr& emsg);
  82.     const fxStr& getType(void) const;
  83.     const fxStr& getSubType(void) const;
  84.     bool isParent(const char* type) const;
  85.     bool isParent(const char* type, const char* subtype) const;
  86.     const fxStr& getDescription(void) const;
  87.     const fxStr& getContentID(void) const;
  88.     const fxStr& getDisposition(void) const;
  89.     virtual void setEncoding(const char*);
  90.     Encoding getEncoding(void) const;
  91.     virtual void setCharset(const char*);
  92.     Charset getCharset(void) const;
  93.     void setBoundary(const char*);
  94.     const fxStr& getBoundary(void) const;
  95.     virtual bool getLine(FILE*, fxStackBuffer&);
  96.     bool isLastPart(void) const;
  97.     virtual void trace(FILE*);
  98. };
  99. inline Charset MIMEState::getCharset(void) const { return charset; }
  100. inline Encoding MIMEState::getEncoding(void) const { return encode; }
  101. inline const fxStr& MIMEState::getBoundary(void) const { return boundary; }
  102. inline bool MIMEState::isLastPart(void) const { return lastPart; }
  103. inline bool MIMEState::isParent(const char* t) const
  104.     { return (parent && parent->type == t); }
  105. inline bool MIMEState::isParent(const char* t, const char* st) const
  106.     { return (parent && parent->type == t && parent->subtype == st); }
  107. inline const fxStr& MIMEState::getType(void) const { return type; }
  108. inline const fxStr& MIMEState::getSubType(void) const { return subtype; }
  109. inline const fxStr& MIMEState::getDescription(void) const { return desc; }
  110. inline const fxStr& MIMEState::getContentID(void) const { return cid; }
  111. inline const fxStr& MIMEState::getDisposition(void) const { return disp; }
  112. #endif /* _MIMEState_ */