1 //  This may look like C code, but it is really -*- C++ -*-
2 
3 //  ------------------------------------------------------------------
4 //  The Goldware Library
5 //  Copyright (C) 1990-1999 Odinn Sorensen
6 //  Copyright (C) 1999-2000 Alexander S. Aganichev
7 //  ------------------------------------------------------------------
8 //  This library is free software; you can redistribute it and/or
9 //  modify it under the terms of the GNU Library General Public
10 //  License as published by the Free Software Foundation; either
11 //  version 2 of the License, or (at your option) any later version.
12 //
13 //  This library is distributed in the hope that it will be useful,
14 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 //  Library General Public License for more details.
17 //
18 //  You should have received a copy of the GNU Library General Public
19 //  License along with this program; if not, write to the Free
20 //  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 //  MA 02111-1307, USA
22 //  ------------------------------------------------------------------
23 //  $Id: gmo_msg.h,v 1.11 2006/05/15 06:20:57 ssianky Exp $
24 //  ------------------------------------------------------------------
25 //  Message structures and classes.
26 //  ------------------------------------------------------------------
27 
28 
29 //  ------------------------------------------------------------------
30 
31 #ifndef __GMB_MSG_H
32 #define __GMB_MSG_H
33 
34 
35 //  ------------------------------------------------------------------
36 
37 #include <gftnall.h>
38 #include <gtimall.h>
39 #include <gvidall.h>
40 #include <gmsgattr.h>
41 
42 #include <vector>
43 
44 
45 //  ------------------------------------------------------------------
46 //  Internet name typedefs
47 
48 typedef char INam[128];
49 
50 
51 //  ------------------------------------------------------------------
52 //  Internet subject typedefs
53 
54 typedef char ISub[1301];
55 
56 
57 //  ------------------------------------------------------------------
58 //  Message modes
59 
60 const uint GMSG_HDR         = 0x0001;
61 const uint GMSG_TXT         = 0x0002;
62 const uint GMSG_HDRTXT      = 0x0003;  // GMSG_HDR|GMSG_TXT
63 const uint GMSG_NEW         = 0x0010;
64 const uint GMSG_UPDATE      = 0x0020;
65 const uint GMSG_DELETE      = 0x0040;
66 const uint GMSG_COPY        = 0x0080;
67 const uint GMSG_MOVE        = 0x0100;
68 const uint GMSG_UNS_NOT_RCV = 0x0200;
69 const uint GMSG_NOLSTUPD    = 0x8000;
70 
71 
72 //  ------------------------------------------------------------------
73 //  Line attributes
74 
75 const uint GLINE_TEAR = 0x0001;
76 const uint GLINE_ORIG = 0x0002;
77 const uint GLINE_HIDD = 0x0004;
78 const uint GLINE_KLUD = 0x0008;
79 const uint GLINE_QUOT = 0x0010;
80 const uint GLINE_HARD = 0x0020;
81 const uint GLINE_WRAP = 0x0040;
82 const uint GLINE_BLOK = 0x0080;
83 const uint GLINE_POSI = 0x0100;
84 const uint GLINE_HIGH = 0x0200;
85 const uint GLINE_TAGL = 0x0400;
86 const uint GLINE_SIGN = 0x0800;
87 const uint GLINE_TXTH = 0x1000;  // text is hiden
88 const uint GLINE_NOAL = 0x2000;  // text is not allocated
89 
90 const uint GLINE_KLUDGE = GLINE_HIDD | GLINE_KLUD;
91 const uint GLINE_ALL    = GLINE_HIDD | GLINE_KLUD | GLINE_QUOT;
92 
93 
94 //  ------------------------------------------------------------------
95 //  Kludge types
96 
97 const uint GKLUD_INTL      = 0x0001;
98 const uint GKLUD_FMPT      = 0x0002;
99 const uint GKLUD_TOPT      = 0x0004;
100 const uint GKLUD_FLAGS     = 0x0008;
101 const uint GKLUD_AREA      = 0x0010;
102 const uint GKLUD_MSGID     = 0x0020;
103 const uint GKLUD_REPLY     = 0x0040;
104 const uint GKLUD_PID       = 0x0080;
105 const uint GKLUD_FWD       = 0x0100;
106 const uint GKLUD_PATH      = 0x0200;
107 const uint GKLUD_SEENBY    = 0x0400;
108 const uint GKLUD_CHARSET   = 0x0800;
109 const uint GKLUD_REPLYTO   = 0x1000;
110 const uint GKLUD_REPLYADDR = 0x2000;
111 const uint GKLUD_KNOWN     = 0x4000;
112 const uint GKLUD_RFC       = 0x8000;
113 
114 
115 //  ------------------------------------------------------------------
116 //  Search locations
117 
118 const uint GFIND_FROM      = 0x0001;
119 const uint GFIND_TO        = 0x0002;
120 const uint GFIND_SUBJECT   = 0x0004;
121 const uint GFIND_BODY      = 0x0008;
122 const uint GFIND_TAGLINE   = 0x0010;
123 const uint GFIND_TEARLINE  = 0x0020;
124 const uint GFIND_ORIGIN    = 0x0040;
125 const uint GFIND_KLUDGES   = 0x0080;
126 const uint GFIND_SIGNATURE = 0x0100;
127 const uint GFIND_HDR       = GFIND_FROM | GFIND_TO | GFIND_SUBJECT;
128 const uint GFIND_HDRTXT    = GFIND_HDR | GFIND_BODY;
129 
130 
131 //  ------------------------------------------------------------------
132 //  Charset encoding formats
133 
134 const int GCHENC_CMP = 0x0001;    // Composed characters
135 const int GCHENC_I51 = 0x0002;    // FSC-51
136 const int GCHENC_MNE = 0x0004;    // K.Simonsen Mnemonic
137 const int GCHENC_QP  = 0x0008;    // Quoted-Printable
138 
139 
140 //  ------------------------------------------------------------------
141 //  Line record
142 
143 class Line {
144 
145 public:
146 
147   vattr color;            // Line color
148   uint  type;             // GLINE_*
149   uint  kludge;           // GKLUD_*
150   std::string txt;             // The line text
151   Line* prev;             // Pointer to previous line
152   Line* next;             // Pointer to next line
153 
Line()154   Line() : txt ("")     { color = BLACK_|_BLACK; type = kludge = 0; prev = next = NULL; }
Line(const char * str)155   Line(const char *str) : txt (str) { color = BLACK_|_BLACK; type = kludge = 0; prev = next = NULL; }
~Line()156   ~Line()              {}
157 
istearline()158   int  istearline()    { return !!(type & GLINE_TEAR); }
isorigin()159   int  isorigin()      { return !!(type & GLINE_ORIG); }
ishidden()160   int  ishidden()      { return !!(type & GLINE_HIDD); }
iskludge()161   int  iskludge()      { return !!(type & GLINE_KLUD); }
isquote()162   int  isquote()       { return !!(type & GLINE_QUOT); }
ishard()163   int  ishard()        { return !!(type & GLINE_HARD); }
iswrapped()164   int  iswrapped()     { return !!(type & GLINE_WRAP); }
isblock()165   int  isblock()       { return !!(type & GLINE_BLOK); }
isposition()166   int  isposition()    { return !!(type & GLINE_POSI); }
ishighlighted()167   int  ishighlighted() { return !!(type & GLINE_HIGH); }
istagline()168   int  istagline()     { return !!(type & GLINE_TAGL); }
istxthidden()169   int  istxthidden()   { return !!(type & GLINE_TXTH); }
isheader()170   int  isheader()      { return !!kludge; }
171 
isallocated()172   int  isallocated()   { return !(type & GLINE_NOAL); }
173 };
174 
175 
176 //  ------------------------------------------------------------------
177 
178 Line* AddLineF(Line*& line, const char* format, ...) __attribute__ ((format (printf, 2, 3)));
179 Line* AddLine(Line* line, const char* buf);
180 Line* AddHexdump(Line*& line, void* data, size_t datalen);
181 
182 
183 //  ------------------------------------------------------------------
184 
185 class gmsg_links
186 {
187 private:
188   uint32_t reply_to;
189   uint32_t reply_first;
190   uint32_t reply_next;
191 
192   std::vector<uint32_t> reply_list;
193 
194 public:
195 
reset()196   void reset()
197   {
198     reply_to = reply_first = reply_next = 0;
199     reply_list.clear();
200   }
201 
list_max()202   int list_max() const             { return reply_list.size(); }
203 
to_set(uint32_t m)204   void to_set(uint32_t m)          { reply_to = m; }
first_set(uint32_t m)205   void first_set(uint32_t m)       { reply_first = m; }
next_set(uint32_t m)206   void next_set(uint32_t m)        { reply_next = m; }
207 
list_set(size_t n,uint32_t m)208   void list_set(size_t n, uint32_t m)
209   {
210     size_t size = reply_list.size();
211     if (n >= size)
212     {
213       for (size_t i = size; i <= n; i++)
214         reply_list.push_back(0);
215     }
216 
217     reply_list[n] = m;
218   }
219 
to()220   uint32_t to() const              { return reply_to; }
first()221   uint32_t first() const           { return reply_first; }
next()222   uint32_t next() const            { return reply_next; }
223 
list(size_t n)224   uint32_t list(size_t n) const
225   {
226     if (n >= reply_list.size())
227       return 0;
228 
229     return reply_list[n];
230   }
231 
232 };
233 
234 
235 //  ------------------------------------------------------------------
236 
237 struct gmsg_jam_fields {
238 
239   int32_t subfieldlen;   // Size of subfields
240 };
241 
242 
243 //  ------------------------------------------------------------------
244 
245 struct gmsg_pcboard_fields {
246 
247   char status;          // Msg header status byte
248   byte exthdrflags;     // Msg extended header flags
249   char password[13];    // Password needed to read the message
250   time32_t reply_written;   // Timestamp of the original
251 };
252 
253 
254 //  ------------------------------------------------------------------
255 
256 struct gmsg_wildcat_fields {
257 
258   char  from_title[11];
259   int32_t  from_userid;
260   char  to_title[11];
261   int32_t  to_userid;
262   char  network[9];
263   char  internal_attach[13];
264   char  external_attach[13];
265   uint32_t next_unread;
266   uint32_t prev_unread;
267   char  reserved[20];
268 };
269 
270 
271 //  ------------------------------------------------------------------
272 
273 struct gmsg_adeptxbbs_fields {
274 
275   uint32_t iflags;       // Internet related flags
276   uint32_t oflags;       // Other network related flags
277 };
278 
279 
280 //  ------------------------------------------------------------------
281 
282 struct gmsg_ezycom_fields {
283 
284   byte extattr;
285 };
286 
287 
288 //  ------------------------------------------------------------------
289 //  Base class
290 
291 class gmsg {
292 
293 public:
294 
295   uint        board;            // Board number (if applicable)
296 
297   uint32_t    msgno;            // Message number
298   gmsg_links  link;             // Message reply links
299 
300   ftn_addr    oorig;            // Original origination address
301   ftn_addr    orig;             // Origination address
302   ftn_domain  odom;             // Originating domain
303 
304   ftn_addr    odest;            // Original destination address
305   ftn_addr    dest;             // Destination address
306   ftn_domain  ddom;             // Destination domain
307 
308   INam        by;               // Who from
309   INam        to;               // Who to
310   ISub        re;               // Subject
311 
312   time32_t      written;          // Timestamp
313   time32_t      arrived;          // Timestamp
314   time32_t      received;         // Timestamp
315 
316   Attr        attr;             // Message attributes
317   uint        cost;             // Cost of msg if Netmail
318   uint        timesread;        // Number of times read
319 
320   ftn_addr    msgid;            // MSGID kludge address
321   char        msgids[201];      // MSGID kludge string
322   char        replys[201];      // REPLY kludge string
323 
324   char        pid[80];          // PID kludge string
325 
326   int32_t        txtstart;         // Text starting position or record
327   int32_t        txtlength;        // Text length or number of records
328   uint        txtblocks;        // Number of msg text blocks
329 
330   char*       txt;              // Message text
331 
332   gmsg_jam_fields       jam;
333   gmsg_pcboard_fields   pcboard;
334   gmsg_wildcat_fields   wildcat;
335   gmsg_adeptxbbs_fields adeptxbbs;
336   gmsg_ezycom_fields    ezycom;
337 
338 };
339 
340 
341 //  ------------------------------------------------------------------
342 
343 #endif
344 
345 //  ------------------------------------------------------------------
346 
347