/
muaimf.h
185 lines (150 loc) · 3.41 KB
/
muaimf.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
Copyright (C) 2016-2017 Claude SIMON (http://zeusw.org/epeios/contact.html).
This file is part of 'MMUAq' software.
'MMUAq' is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
'MMUAq' is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with 'MMUAq'. If not, see <http://www.gnu.org/licenses/>.
*/
// MUA Internet Mail Format (RFC 5322)
#ifndef MUAIMF_INC_
# define MUAIMF_INC_
# ifdef XXX_DBG
# define MUAIMF__DBG
# endif
# include "muabsc.h"
# include "lstbch.h"
# include "lstcrt.h"
namespace muaimf {
qENUM( Field ) {
fSubject,
f_FirstOptional,
fTo = f_FirstOptional,
fFrom,
fMessageId,
fDate,
f_amount,
f_Unknown, // Not a known field.
f_Undefined
};
const char *GetLabel( eField Field );
eField GetField( const str::dString &Label );
// NOT thread-safe.
const char *GetWording( eField Field );
qROW( SRow_ ); // String row.
class sField_ {
public:
eField Field;
sSRow_
Name,
Body;
void reset( bso::sBool P = true )
{
Field = f_Undefined;
Name = Body = qNIL;
}
qCDTOR( sField_ );
void Init( void )
{
Field = f_Undefined;
Name = Body = qNIL;
}
};
qROW( FRow ); // Field row.
typedef bch::qBUNCHdl( sFRow ) dFRows;
qW( FRows );
typedef lstbch::qLBUNCHd( sField_, sFRow ) dFields_;
typedef lstcrt::qLMCRATEd( str::dString, sSRow_ ) dStrings_;
class dFields
{
private:
sSRow_ Append_( const str::dString &Entry )
{
sSRow_ Row = Strings.New();
Strings( Row ).Init( Entry );
Strings.Flush();
return Row;
}
public:
struct s {
dStrings_::s Strings;
dFields_::s Fields;
};
dStrings_ Strings;
dFields_ Fields;
dFields( s &S )
: Strings( S.Strings ),
Fields( S.Fields )
{}
void reset( bso::sBool P = true )
{
tol::reset( P, Strings, Fields );
}
void plug( qASd *AS )
{
tol::plug( AS, Strings, Fields );
}
dFields &operator =(const dFields &F)
{
Strings = F.Strings;
Fields = F.Fields;
return *this;
}
void Init( void )
{
tol::Init( Strings, Fields );
}
sFRow Append(
const str::dString &Name,
const str::dString &Body );
void Search(
eField Field,
dFRows &Rows ) const;
sFRow Search( eField Field ) const;
eField GetField( sFRow Row ) const
{
return Fields( Row ).Field;
}
const str::dString &GetName(
sFRow Row,
str::dString &Value ) const
{
Strings.Recall( Fields( Row ).Name, Value );
return Value;
}
const str::dString &GetBody(
sFRow Row,
str::dString &Value ) const
{
Strings.Recall( Fields( Row ).Body, Value );
return Value;
}
qNAV( Fields., sFRow );
};
qW( Fields );
typedef dFields dHeader;
qW( Header );
const str::dString &GetField(
eField Field,
fdr::rRDriver &Driver,
str::dString &Body );
void Fill(
flw::rRFlow &Flow,
dFields &Fields );
void Fill(
fdr::rRDriver &Driver,
dFields &Fields );
void Dump(
const dFields &Fields,
txf::rWFlow Flow );
void Dump(
const dFields &Fields,
fdr::rWDriver &Driver );
}
#endif