1 //=============================================================================
2 // File: fieldbdy.h
3 // Contents: Declarations for DwFieldBody
4 // Maintainer: Doug Sauder <dwsauder@fwb.gulf.net>
5 // WWW: http://www.fwb.gulf.net/~dwsauder/mimepp.html
6 // $Revision: 1.6 $
7 // $Date: 1997/09/27 11:55:22 $
8 //
9 // Copyright (c) 1996, 1997 Douglas W. Sauder
10 // All rights reserved.
11 //
12 // IN NO EVENT SHALL DOUGLAS W. SAUDER BE LIABLE TO ANY PARTY FOR DIRECT,
13 // INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
14 // THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF DOUGLAS W. SAUDER
15 // HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16 //
17 // DOUGLAS W. SAUDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
18 // NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19 // PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
20 // BASIS, AND DOUGLAS W. SAUDER HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
21 // SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
22 //
23 //=============================================================================
24
25 #ifndef DW_FIELDBDY_H
26 #define DW_FIELDBDY_H
27
28 #include <iostream>
29
30 #ifndef DW_CONFIG_H
31 #include <mimelib/config.h>
32 #endif
33
34 #ifndef DW_STRING_H
35 #include <mimelib/string.h>
36 #endif
37
38 #ifndef DW_MSGCMP_H
39 #include <mimelib/msgcmp.h>
40 #endif
41
42 //=============================================================================
43 //+ Name DwFieldBody -- Class representing a MIME header field body
44 //+ Description
45 //. {\tt DwFieldBody} represents the field-body element in the BNF grammar
46 //. specified by RFC-822. It is an abstract base class that defines the
47 //. interface common to all structured field bodies.
48 //.
49 //. In the tree (broken-down) representation of a message, a {\tt DwFieldBody}
50 //. object may be either a leaf node, having a parent but no child nodes, or
51 //. an intermediate node, having a parent and one or more child nodes. The
52 //. parent node is the {\tt DwField} object that contains it. Child nodes,
53 //. if present, depend on the particular subclass of {\tt DwFieldBody} that
54 //. is instantiated. A {\tt DwAddressList} object, for example, has
55 //. {\tt DwAddress} objects as its child nodes.
56 //.
57 //. Since {\tt DwFieldBody} is an abstract base class, you cannot create
58 //. instances of it directly. Normally, objects of classes derived from
59 //. {\tt DwFieldBody} are obtained by calling convenience member functions
60 //. in the class {\tt DwHeaders}.
61 //.
62 //. Some MIME parsers are broken in that they do not handle the folding of
63 //. some fields properly. {\tt DwFieldBody} folds its string representation
64 //. by default. You can disable folding, however, by calling the
65 //. {\tt SetFolding()} member function. To determine if folding is enabled,
66 //. call {\tt IsFolding()}.
67 //=============================================================================
68 // Last updated 1997-08-24
69 //+ Noentry ~DwFieldBody mLineOffset mDoFolding _PrintDebugInfo
70
71
72 class DW_EXPORT DwFieldBody : public DwMessageComponent {
73
74 friend class DwField;
75
76 public:
77
78 DwFieldBody();
79 DwFieldBody(const DwFieldBody& aFieldBody);
80 DwFieldBody(const DwString& aStr, DwMessageComponent* aParent=0);
81 //. The first constructor is the default constructor, which sets the
82 //. {\tt DwFieldBody} object's string representation to the empty
83 //. string and sets its parent to {\tt NULL}.
84 //.
85 //. The second constructor is the copy constructor, which performs a
86 //. deep copy of {\tt aFieldBody}.
87 //. The parent of the new {\tt DwFieldBody} object is set to {\tt NULL}.
88 //.
89 //. The third constructor copies {\tt aStr} to the {\tt DwFieldBody}
90 //. object's string representation and sets {\tt aParent} as its parent.
91 //. The virtual member function {\tt Parse()} should be called immediately
92 //. after this constructor in order to parse the string representation.
93 //. Unless it is {\tt NULL}, {\tt aParent} should point to an object of
94 //. a class derived from {\tt DwField}.
95
96 virtual ~DwFieldBody();
97
98 const DwFieldBody& operator = (const DwFieldBody& aFieldBody);
99 //. This is the assignment operator, which performs a deep copy of
100 //. {\tt aFieldBody}. The parent node of the {\tt DwFieldBody} object
101 //. is not changed.
102
103 void SetOffset(int aOffset);
104 //. Sets the offset to {\tt aOffset}. The offset is used when folding
105 //. lines. It indicates how much the first line should be offset to
106 //. account for the field name, colon, and initial white space.
107
108 void SetFolding(DwBool aTrueOrFalse);
109 //. Enables ({\tt aTrueOrFalse = DwTrue}) or disables
110 //. ({\tt aTrueOrFalse = DwFalse}) the folding of fields. The default
111 //. is to fold fields. Unfortunately, some parsers are broke and
112 //. do not handle folded lines properly. This function allows a kludge
113 //. to deal with these broken parsers.
114
115 DwBool IsFolding() const;
116 //. Returns a boolean indicating if folding of fields is enabled.
117
118 protected:
119
120 int mLineOffset;
121 DwBool mDoFolding;
122
123 private:
124
125 static const char* const sClassName;
126
127 public:
128
129 virtual void PrintDebugInfo(ostream& aStrm, int aDepth=0) const;
130 //. This virtual function, inherited from {\tt DwMessageComponent},
131 //. prints debugging information about this object to {\tt aStrm}.
132 //. It will also call {\tt PrintDebugInfo()} for any of its child
133 //. components down to a level of {\tt aDepth}.
134 //.
135 //. This member function is available only in the debug version of
136 //. the library.
137
138 virtual void CheckInvariants() const;
139 //. Aborts if one of the invariants of the object fails. Use this
140 //. member function to track down bugs.
141 //.
142 //. This member function is available only in the debug version of
143 //. the library.
144
145 protected:
146
147 void _PrintDebugInfo(ostream& aStrm) const;
148
149 };
150
151
SetOffset(int aOffset)152 inline void DwFieldBody::SetOffset(int aOffset)
153 {
154 mLineOffset = aOffset;
155 }
156
157
SetFolding(DwBool aTrueOrFalse)158 inline void DwFieldBody::SetFolding(DwBool aTrueOrFalse)
159 {
160 mDoFolding = aTrueOrFalse;
161 }
162
163
IsFolding()164 inline DwBool DwFieldBody::IsFolding() const
165 {
166 return mDoFolding;
167 }
168
169 #endif
170