Add missing license headers on *.hh files and others
[oweals/cde.git] / cde / programs / dtmail / include / DtMail / DtMail.hh
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*
24  *+SNOTICE
25  *
26  *
27  *      $TOG: DtMail.hh /main/18 1998/11/10 17:02:07 mgreess $
28  *
29  *      RESTRICTED CONFIDENTIAL INFORMATION:
30  *      
31  *      The information in this document is subject to special
32  *      restrictions in a confidential disclosure agreement bertween
33  *      HP, IBM, Sun, USL, SCO and Univel.  Do not distribute this
34  *      document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
35  *      Sun's specific written approval.  This documment and all copies
36  *      and derivative works thereof must be returned or destroyed at
37  *      Sun's request.
38  *
39  *      Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
40  *
41  *+ENOTICE
42  */
43 #ifndef I_HAVE_NO_IDENT
44 #endif
45
46 #ifndef _DTMAIL_HH
47 #define _DTMAIL_HH
48
49 #include <stdio.h>
50 #include <stdarg.h>
51 #if defined(sun) || defined(__FreeBSD__)
52 #include <iconv.h>
53 #endif
54 #include <sys/stat.h>
55 /*#include <nl_types.h>*/
56 #include <DtMail/DtMailError.hh>
57 #include <DtMail/DtMailProps.h>
58 #include <DtMail/DtMailTypes.h>
59 #include <DtMail/DtVirtArray.hh>
60 #include <DtMail/DtLanguages.hh>
61 #include <Tt/tttk.h>
62 #include <fcntl.h>
63
64 // Define a type for the handler used in RFCTransport::launchSendmail
65 typedef void SubProcessFinishedProc (int pid, int status, void *data);
66
67 //
68 // Gorp to get mailrc to work
69 //
70 #define HSHSIZE 40
71 #define MAILRC_NOFILE          20      /* this define is here for      */
72                                 /* compatibility purposes only  */
73                                 /* and will be removed in a     */
74                                 /* later release                */
75
76 #ifdef __osf__
77     struct hash;
78     struct var;
79 #endif
80
81 // enums cannot be declared inside of classes because the enum scope rules
82 // changed from V2 to V3 compilers causing incompatibilities
83 //
84 enum DtmFileLocality {
85   Dtm_FL_UNKNOWN,               // cannot determine file locality
86   Dtm_FL_LOCAL,                 // file is local to this system (eg ufs)
87   Dtm_FL_LOCAL_AND_REMOTE,      // file is remote with local copy (eg cachefs)
88   Dtm_FL_REMOTE                 // file is remote (e.g. nfs)
89 };
90
91 class DtMail {
92   public:
93     
94     // Returns the minor code set by a DtMail routine. This method
95     // should only be called if error._major is not NO_EXCEPTION.
96     //
97     //  Parameters:
98     //    error - The environment returned from any DtMail method.
99     //
100     //  Returns - The error code as defined in DtMailError.h
101     //
102     static DTMailError_t getMinorCode(DtMailEnv & error);
103     
104     // Returns the internationalized error text for an error. This
105     // method should only be called if error._major is not NO_EXCEPTION.
106     //
107     // Parameters:
108     //  error - The environment returned from any DtMail method.
109     //
110     // Returns - The error text string. This string is valid until
111     //    error.clear() is called on the error.
112     //
113     static const char * getErrorString(DtMailEnv & error);
114
115     // Determine locality of referenced path object
116     // This is not part of the public interface, do not call
117     // as a client of this class.
118     static enum DtmFileLocality DetermineFileLocality(const char * path);
119
120     class MailBox;
121     class Message;
122     class Transport;
123
124     class MailRc;
125
126     class Session : public DtCPlusPlusAllocator {
127       public:
128             Session(DtMailEnv &, const char * app_name);
129             ~Session(void);
130             
131             const char ** enumerateImpls(DtMailEnv & error);
132             void setDefaultImpl(DtMailEnv & error, const char * impl);
133             const char * getDefaultImpl(DtMailEnv & error);
134             void queryImpl(DtMailEnv & error,
135                            const char * impl,
136                            const char * capability,
137                            ...);
138             void queryImplV(DtMailEnv & error,
139                             const char * impl,
140                             const char * capability,
141                             va_list args);
142
143             // Create a mail box object, after selecting an implementation.
144             MailBox * mailBoxConstruct(DtMailEnv & error,
145                                        DtMailObjectSpace space,
146                                        void * arg,
147                                        DtMailCallback open_callback,
148                                        void * client_data,
149                                        const char * impl = NULL);
150
151             Message * messageConstruct(DtMailEnv & error,
152                                        DtMailObjectSpace space,
153                                        void * arg,
154                                        DtMailCallback open_callback,
155                                        void * client_data,
156                                        const char * impl = NULL);
157
158             // Create a transport object after selecting an implementation.
159             Transport * transportConstruct(DtMailEnv & error,
160                                            const char * impl,
161                                            DtMailStatusCallback call_back,
162                                            void * client_data);
163
164             // Retrieve a copy of the MailRc handle.
165             MailRc * mailRc(DtMailEnv & error);
166
167             // The following methods set up the polling requirements for
168             // the DtMail library.
169             //
170             DtMailBoolean pollRequired(DtMailEnv & error);
171
172             int eventFileDesc(DtMailEnv & error);
173
174             void poll(DtMailEnv & error);
175
176             // The expandPath method will turn a relative path, with
177             // variable's into an absolute path, relative to the current
178             // network node.
179             //
180             char * expandPath(DtMailEnv & error, const char * path);
181             char * getRelativePath(DtMailEnv & error, const char * path);
182
183             // Accessors to session data.
184             const char * appName(void) const { return _app_name; }
185             char * ttChannel(void) const { return _tt_channel; }
186             int ttFile(void) const { return _tt_fd; }
187
188             // Meta factory type. This method gives access to the
189             // factory and the implementations specific query
190             // mechanisms.
191             typedef void * (*MetaImplFactory)(const char * operation);
192
193             // The setError method needs to be here so it can be accessed
194             // by the drivers.
195             //
196             void setError(DtMailEnv & error, const DTMailError_t);
197
198             // Add an event routine.
199             void addEventRoutine(DtMailEnv &,
200                                  DtMailEventFunc,
201                                  void * client_data,
202                                  time_t interval);
203
204             // Remove an event routine.
205             void removeEventRoutine(DtMailEnv &,
206                                     DtMailEventFunc,
207                                     void * client_data);
208
209             // Push some data into the event queue.
210             //
211             void writeEventData(DtMailEnv & error,
212                                 const void * buf,
213                                 const unsigned long size);
214
215             // These routines check the list to make sure the created
216             // object is still valid. This is used by the event handlers
217             // to make sure events don't appear for deleted objects.
218             //
219             DtMailBoolean validObjectKey(DtMailObjectKey);
220             DtMailObjectKey newObjectKey(void);
221             void removeObjectKey(DtMailObjectKey);
222
223             // This method allows the client to register a busy callback.
224             // Any time the library is going to be busy for a while, it will
225             // call this handler to set the app state to busy, and unbusy
226             // the app when it is done. This is an optional interface.
227             //
228             typedef void (*BusyApplicationCallback)(DtMailEnv &error,
229                                                     DtMailBusyState busy_state,
230                                                     void * client_data);
231             void registerBusyCallback(DtMailEnv &,
232                                       BusyApplicationCallback,
233                                       void * client_data);
234
235 #ifdef DEAD_WOOD
236             void unregisterBusyCallback(DtMailEnv &);
237 #endif /* DEAD_WOOD */
238
239             void setBusyState(DtMailEnv &, DtMailBusyState busy_state);
240
241             void setAutoSaveFlag(DtMailBoolean flag);
242             DtMailBoolean getAutoSaveFlag();
243
244             // These methods allow disabling and enabling of group privileges
245             //
246             typedef void (*DisableGroupPrivilegesCallback)(void * client_data);
247             typedef void (*EnableGroupPrivilegesCallback)(void * client_data);
248       
249             void registerDisableGroupPrivilegesCallback(
250                                         DisableGroupPrivilegesCallback,
251                                         void * client_data);
252             void registerEnableGroupPrivilegesCallback(
253                                         EnableGroupPrivilegesCallback,
254                                         void * client_data);
255       
256             void disableGroupPrivileges(void);
257             void enableGroupPrivileges(void);
258         
259             // This method allows the client to register a callback that
260             // can be called to return the last time() an interactive X
261             // event was processed.
262             // Any time the library is about to be busy for a while, it
263             // may call this handler to get the time() that the last
264             // interactive X event was processed. It was very recent, the
265             // library may wish to delay the busy event for a while.
266             //
267             typedef long (*LastInteractiveEventTimeCallback)(void * client_data);
268       
269             void registerLastInteractiveEventTimeCallback(
270                                         LastInteractiveEventTimeCallback,
271                                         void * client_data);
272       
273             long lastInteractiveEventTime(void);
274       
275                 // For CHARSET
276         int OpenLcxDb(void);
277         void DtXlateStdToOpLocale(char *op, char *std, char *dflt,
278                      char **ret);
279         void DtXlateOpToStdLocale(char *op, char *opLoc, char **retLoc,
280                      char **ret_retLang, char **retSet);
281         void DtXlateStdToOpCodeset(char *op, char *std, char *dflt,
282                      char **ret);
283         void DtXlateMimeToIconv(const char *, const char *, const char *,
284                      char **, char **);
285         void DtXlateLocaleToMime(const char *, const char *,
286                      const char *, char **);
287
288         char *csToConvName(char *);
289         char *locToConvName();
290         char *targetConvName();
291         char *targetTagName();
292         char *targetTagName(char *);
293                 int csConvert(char **, unsigned long &, int, char *, char *);
294         // End of For CHARSET
295
296           private:
297             unsigned long       _object_signature;
298             void                *_obj_mutex;
299             char *              _tt_channel;
300             int                 _tt_fd;
301             int                 _event_fd[2];
302             char                *_app_name;
303             MailRc *            _mail_rc;
304             DtMailBoolean       _canAutoSave;
305             
306             /* Implementation structure. */
307             struct Impls {
308               char              *impl_name;
309               MetaImplFactory   impl_meta_factory;
310               void              *impl_lib;
311             };
312             
313             Impls               *_impls;
314             const char  **_impl_names; // Used to return names from enumerate.
315             int         _num_impls;
316             int         _default_impl;
317             
318             struct EventRoutine : public DtCPlusPlusAllocator {
319               DtMailEventFunc   routine;
320               void *            client_data;
321               time_t            interval;
322               time_t            last_ran;
323             };
324
325             DtVirtArray<EventRoutine *>         _events;
326             DtVirtArray<DtMailObjectKey>        _valid_keys;
327             DtMailObjectKey                     _cur_key;
328
329             void buildImplTable(DtMailEnv & error);
330             void buildTypeTable(DtMailEnv & error);
331             int lookupImpl(const char * impl);
332
333             BusyApplicationCallback     _busy_cb;
334             void *                      _busy_cb_data;
335
336             DisableGroupPrivilegesCallback      _disableGroupPrivileges_cb;
337             void *                              _disableGroupPrivileges_cb_data;
338
339             EnableGroupPrivilegesCallback       _enableGroupPrivileges_cb;
340             void *                              _enableGroupPrivileges_cb_data;
341
342             LastInteractiveEventTimeCallback    _interactive_time_cb;
343             void *                              _interactive_time_cb_data;
344         };
345
346 //==================NEW MAILRC CLASS
347     class MailRc {
348         
349       public:
350             
351             MailRc(DtMailEnv &, Session *);
352             
353             ~MailRc();
354             
355             int  encryptedLength(int length);
356             void encryptValue(char *to, char *from, int length);
357             int  decryptValue(char *to, char *from, int length);
358
359             void getValue(
360                         DtMailEnv &,
361                         const char * var, const char ** value,
362                         DtMailBoolean decrypt = DTM_FALSE);
363             void setValue(
364                         DtMailEnv &,
365                         const char * var, const char * value,
366                         DtMailBoolean encrypt = DTM_FALSE);
367             void removeValue(DtMailEnv &, const char * var);
368
369             const char * getAlias(DtMailEnv &, const char * name);
370             typedef void (*hm_callback)(char * key, void * value,
371                                         void * client_data);
372             void getAliasList(hm_callback stuffing_func, void *client_data);
373             void setAlias(DtMailEnv &, const char * name, const char * value);
374             void removeAlias(DtMailEnv &, const char * name);
375             DtVirtArray<char *> *getAliasList();
376
377             DtMailBoolean ignore(DtMailEnv &, const char *name);
378             void addIgnore(DtMailEnv &, const char * name);
379             void removeIgnore(DtMailEnv &, const char * name);
380             DtVirtArray<char *> *getIgnoreList();
381
382             const char * getAlternates(DtMailEnv &);
383             void setAlternate(DtMailEnv &, const char * alt);
384             void removeAlternate(DtMailEnv &, const char * alt);
385
386             void update(DtMailEnv &);
387             
388             
389             // Methods below this line are not part of the public interface.
390             // They must be declared public due to implementation restrictions.
391             // DO NOT CALL THESE AS A CLIENT OF THIS CLASS.
392             //
393             int load(char *filename, char* line);
394             void init_globals();
395             static void add_alias(char *name, char *value);
396             static void mt_assign(char *name,char * val);
397             static int mt_deassign(char *s);
398             static void mt_puthash(
399                                 char *name,
400                                 char * val,
401                                 struct var **hasharray);
402             static void mt_scan(FILE * outf);
403             static char *vcopy(char *str);
404             static int group(char **argv, DtMail::MailRc *);
405             static void wgroup(const char *, char **, FILE *);
406             static void ngroup(char * key, void * value, void * client_data);
407             static void nalias(char * key, void * data, void * client_data);
408             static void nignorelist(char *key, void *data, void *client_data);
409             static int unset(char **arglist, DtMail::MailRc *);
410             static void wunset(
411                                 const char * verbatim,
412                                 char ** arglist,
413                                 FILE * outf);
414             static int set(char **arglist, DtMail::MailRc *);
415             static void wset(const char *, char **, FILE *);
416             static int source(char **arglist, DtMail::MailRc *);
417             static void wsource(const char *, char **, FILE *);
418             static int ifcmd(char **arglist, DtMail::MailRc *);
419             static void wifcmd(const char *, char **, FILE *);
420             static int elsecmd(char **arglist, DtMail::MailRc *);
421             static void welsecmd(const char *, char **, FILE *);
422             static int endifcmd(char **arglist, DtMail::MailRc *);
423             static void wendifcmd(const char *, char **, FILE *);
424             static int igfield(char **list, DtMail::MailRc *);
425             static void wigfield(const char *, char **, FILE *);
426             static void nigfield(char * key, void * value, void * client_data);
427             static int clearaliases(char **list, DtMail::MailRc *);
428             static void wclearaliases(const char *, char **, FILE *);
429
430             static void *hm_alloc();
431             static void *hm_test(struct hash **table, char *key);
432             static void hm_delete(struct hash **table, char *key);
433             static void hm_add(struct hash **table, 
434                                char *key, 
435                                void *value, 
436                                int size);
437             static void hm_mark(struct hash **table, char * key);
438             static int hm_ismarked(struct hash **table, char * key);
439             static void hm_scan(
440                                 struct hash **table,
441                                 hm_callback,
442                                 void * client_data);
443             static void free_hash(struct hash *h);
444             static int hash_index(char *key);
445             static void add_ignore(char *name);
446             static void add_alternates(char *name);
447             static int alternates(char **namelist, DtMail::MailRc *);
448             static void walternates(const char *, char **, FILE *);
449             static void nalternates(
450                                 char * key,
451                                 void * value,
452                                 void * client_data);
453             
454             static char *nullfield;
455             static Boolean clearAliases;
456             
457             struct globals {
458             char *g_myname;
459             void *g_ignore;             /* hash list of ignored fields */
460             void *g_retain;             /* hash list of retained fields */
461             void *g_alias;              /* hash list of alias names */
462             void *g_alternates; /* hash list of alternate names */
463             int g_nretained;    /* the number of retained fields */
464             };  
465             
466             static struct globals glob;
467             
468             /* Pointer to active var list */
469             static struct   var *variables[HSHSIZE]; 
470
471             DTMailError_t getParseError(void) { return _parseError; }
472
473           protected:
474             void updateByLine(FILE * in, FILE * out);
475             void outputLine(
476                         const char * verbatim,
477                         const char * parseable,
478                         FILE * out);
479             int commands(char* line);
480             int execute(char linebuf[]);
481             int readline(FILE *ibuf, char *linebuf);
482             void unstack();
483             int isprefix(char *as1, char *as2);
484             void *lex(char word[]);
485             int getrawlist(char line[], char ** argv, int argc);
486             void freerawlist(char **argv);
487             char *mt_value(char name[]);
488             char *expand(char *);
489             int getfolderdir(char *, size_t);
490             static int hash(char *name);
491             static void vfree(char *cp);
492             
493           private:
494             
495             DTMailError_t                       _parseError;
496             FILE *input;
497             int sourcing;
498             int cond;
499             int  ssp;               /* Top of file stack */
500             char *alternate_list;
501             char *_mailrc_name;
502             
503             static struct var *lookup(char *name, struct var **hasharray);
504             
505             
506             struct sstack {
507             FILE    *s_file;                /* File we were in. */
508             int     s_cond;                 /* Saved state of conditionals */
509             };
510             
511             struct sstack sstack[MAILRC_NOFILE];
512         
513         
514     };
515
516     
517     class Envelope;
518     class BodyPart;
519
520     class Message : public DtCPlusPlusAllocator {
521       public:
522             virtual ~Message(void);
523             
524             virtual Envelope * getEnvelope(DtMailEnv &) = 0;
525             
526             // This should only be used when you REALLY need to know
527             // how many body parts are present before actually traversing
528             // the body parts (i.e. like when writing a MIME format message).
529             virtual int getBodyCount(DtMailEnv &) = 0;
530             
531             virtual BodyPart * getFirstBodyPart(DtMailEnv &) = 0;
532             virtual BodyPart * getNextBodyPart(DtMailEnv &,
533                                                BodyPart * last) = 0;
534             
535             virtual BodyPart * newBodyPart(DtMailEnv &,
536                                            BodyPart * after) = 0;
537             
538 #ifdef DEAD_WOOD
539             virtual void newBodyPartOrder(DtMailEnv &,
540                                           BodyPart * new_order,
541                                           const int bodypart_count) = 0;
542 #endif /* DEAD_WOOD */
543
544             virtual void setFlag(DtMailEnv &,
545                                  const DtMailMessageState) = 0;
546
547             virtual void resetFlag(DtMailEnv &,
548                                    const DtMailMessageState) = 0;
549
550             virtual DtMailBoolean flagIsSet(DtMailEnv &,
551                                             const DtMailMessageState) = 0;
552
553             virtual time_t getDeleteTime(DtMailEnv &) = 0;
554
555             virtual void toBuffer(DtMailEnv & error, DtMailBuffer &) = 0;
556
557             virtual const char * impl(DtMailEnv & error) = 0;
558
559             // The mail box method is used by the components of
560             // the message object to determine which mail box the
561             // belong to, and in turn which session.
562             //
563             MailBox * mailBox(void);
564             Session * session(void);
565
566             
567           protected:
568             Message(DtMailEnv &,
569                     MailBox * parent);
570             
571             MailBox *           _parent;
572             Session *           _session;
573             Envelope *          _envelope;
574             void *              _obj_mutex;
575         };
576
577     class Envelope : public DtCPlusPlusAllocator {
578       public:
579             virtual DtMailHeaderHandle getFirstHeader(
580                                                 DtMailEnv &,
581                                                 char ** name,
582                                                 DtMailValueSeq & value) = 0;
583
584             virtual DtMailHeaderHandle getNextHeader(
585                                                  DtMailEnv &,
586                                                  DtMailHeaderHandle last,
587                                                  char ** name,
588                                                  DtMailValueSeq & value) = 0;
589
590             virtual void getHeader(DtMailEnv &,
591                                    const char * name,
592                                    const DtMailBoolean abstract,
593                                    DtMailValueSeq & value) = 0;
594
595             virtual void setHeaderSeq(DtMailEnv &, 
596                                       const char * header_name, 
597                                       const DtMailValueSeq & val) = 0;
598
599             // The last parameter is left to the client to provide
600             // because it can not be done in a type safe manner.
601             //
602             virtual void setHeader(DtMailEnv &, 
603                                    const char * header_name, 
604                                    const DtMailBoolean replace,
605                                    const char *) = 0;
606
607             virtual void removeHeader(DtMailEnv &,
608                                       const char * header_name) = 0;
609     //
610     // fix for the defect 177527
611     // when a reply-to field is in a message headers, the reply-to is
612     // going to be displayed as the send in RMW's msg list scrolled window
613     // instead of the real sender. The following three public methods are
614     // going to access _use_reply_to.
615     //
616     virtual void setUseReplyTo(void)  = 0;
617     virtual void unsetUseReplyTo(void) = 0;
618     virtual DtMailBoolean getUseReplyTo(void) = 0;
619
620
621           protected:
622             Envelope(DtMailEnv & error, Message * parent);
623
624         friend Message::~Message(void);
625             virtual ~Envelope(void); // Only called from Message destructor.
626
627             void *      _obj_mutex;
628             Message *   _parent;
629         };
630     
631     class BodyPart : public DtCPlusPlusAllocator {
632       public:
633
634             virtual void lockContents(DtMailEnv &, const DtMailLock) = 0;
635             virtual void unlockContents(DtMailEnv &) = 0;
636
637             virtual void getContents(DtMailEnv &,
638                                      const void ** contents,
639                                      unsigned long * length,
640                                      char ** type,
641                                      char ** name,
642                                      int * mode,
643                                      char ** description) = 0;
644             
645             virtual void getContentType(DtMailEnv &,
646                                      char ** content_type) = 0;
647             
648             virtual void setContents(DtMailEnv &,
649                                      const void * contents,
650                                      const unsigned long length,
651                                      const char * type,
652                                      const char * name,
653                                      const int mode,
654                                      const char * description) = 0;
655
656             virtual void setFlag(DtMailEnv &,
657                                  DtMailBodyPartState) = 0;
658
659             virtual void resetFlag(DtMailEnv &,
660                                    DtMailBodyPartState) = 0;
661             
662             virtual DtMailBoolean flagIsSet(DtMailEnv &,
663                                             DtMailBodyPartState) = 0;
664
665             virtual time_t getDeleteTime(DtMailEnv &) = 0;
666
667                 virtual void getHeader(DtMailEnv &,
668                 const char * name,
669                 const DtMailBoolean abstract,
670                 DtMailValueSeq & value) = 0;
671
672         // For CHARSET
673         //-------------------------------------------
674         // These methods are duplicated in class BodyPart
675         // (also being implemented in class Session) because
676         // RFCFormat and RFCBodyPart need to access them. 
677         // Duplicating routines like what is being done here is a workaround
678         // for an implementation bug/hole because there is no class where global
679         // routines can be defined (and be accessed by any class).
680         // class Session is not a proper place to put (global) methods because
681         // not every class can get at Session.
682         // RFCFormat accesses these routines through its private Session handle.
683         // RFCBodyPart does not have a Session handle. 
684         // Hence the need to duplicate the following routines.
685
686         virtual int OpenLcxDb(void) = 0;
687         virtual void DtXlateStdToOpLocale(char *op, char *std, char *dflt,
688                      char **ret) = 0;
689         virtual void DtXlateOpToStdLocale(char *op, char *opLoc, char **retLoc,
690                      char **ret_retLang, char **retSet) = 0;
691         virtual void DtXlateMimeToIconv(const char *, const char *,
692                      const char *, char **, char **) = 0;
693         virtual void DtXlateLocaleToMime(const char *, const char *,
694                      const char *, char **) = 0;
695  
696         virtual char *csToConvName(char *) = 0;
697         virtual char *locToConvName() = 0;
698         virtual char *targetConvName() = 0;
699         virtual char *targetTagName() = 0;
700         virtual int csConvert(char **, unsigned long &, int,
701                     char *, char *) = 0;
702         //-------------------------------------------
703
704                 virtual char *csFromContentType(DtMailValueSeq & value) = 0;
705         // End of For CHARSET
706
707 #ifdef DEAD_WOOD
708             virtual DtMailChecksumState checksum(DtMailEnv &) = 0;
709 #endif /* DEAD_WOOD */
710
711           protected:
712             BodyPart(DtMailEnv &, Message * parent);
713
714         friend Message::~Message(void);
715             virtual ~BodyPart(void); // Only called from Message destructor.
716
717             void *      _obj_mutex;
718             Message *   _parent;
719         };
720
721     
722     // The MailBox encapsulates the concept of a mail box as a container.
723     // This class should be used for manipulating mail containers.
724     
725     class MailBox : public DtCPlusPlusAllocator {
726       public:
727             
728             // Create a MailBox. The constructor simply initializes the
729             // instance and sets the appropriate meta handlers for mail
730             // containers.
731             //
732             // Errors:
733             //   None.
734             //
735             MailBox(DtMailEnv &,
736                     Session * session,
737                     DtMailObjectSpace space,
738                     void * arg,
739                     DtMailCallback cb,
740                     void * clientData);
741             
742             // Returns DTM_TRUE if the is mail box is writable and DTM_FALSE
743             // if the mail box is read only.
744             //
745             DtMailBoolean       mailBoxWritable(DtMailEnv &);
746
747             // Destroy a MailBox. The destructor will close the open mail
748             // container, and any embedded containers.
749             //
750             virtual ~MailBox(void);
751             
752             static void appendCB(DtMailEnv&, char*, int, void *clientData);
753             virtual void append(DtMailEnv &error, char *buf, int len) = 0;
754
755             // Create a named mail container in the file system. The
756             // container will be truncated if it already exists, otherwise
757             // it will be created. The mode in this case will be set to
758             // DTMAIL_DEFAULT_CREATE_MODE, the default for mail.
759             //
760             // Errors:
761             //  DTME_ObjectInvalid - The instance was not proprerly initialized.
762             //  DTME_BadArg - The file_name parameter was invalid.
763             //  DTME_ObjectInUse - This object already has an open container.
764             //  DTME_ObjectCreationFailed - A required object could not
765             //       be created.
766             //
767             virtual void create(DtMailEnv &,
768                                 mode_t mode = DTMAIL_DEFAULT_CREATE_MODE) = 0;
769             
770             // Open a named mail container in the file system. The container
771             // must exist, and be readable (at least) by the user.
772             // If the container is writable by the user it will be opened
773             // for update.
774             //
775             // Parameters:
776             //  auto_create - Create the container if it doesn't exist, using
777             //        MailBox::create.
778             //
779             // Errors:
780             //  DTME_ObjectInvalid - The instance was not proprerly initialized.
781             //  DTME_BadArg - The file_name parameter was invalid.
782             //  DTME_ObjectInUse - This object already has an open container.
783             //  DTME_ObjectCreationFailed - A required object could not
784             //       be created.
785             //  DTME_NoSuchFile - The file doesn't exist & auto_create is false.
786             //  DTME_NotMailBox - The object is a container, but not a mail box.
787             //  DTME_NoMemory - A memory allocation failed.
788             //
789             virtual void open(DtMailEnv & error,
790                               DtMailBoolean auto_create = DTM_TRUE,
791                               int open_mode = DTMAIL_DEFAULT_OPEN_MODE,
792                               mode_t create_mode = DTMAIL_DEFAULT_CREATE_MODE,
793                               DtMailBoolean lock_flag = DTM_TRUE,
794                               DtMailBoolean auto_parse = DTM_TRUE) = 0;
795
796             // (Un)locks an open mailbox.
797             virtual void lock() = 0;
798             virtual void unlock() = 0;
799             virtual void save() = 0;
800
801 #ifdef DEAD_WOOD
802             virtual int messageCount(DtMailEnv & error) = 0;
803 #endif /* DEAD_WOOD */
804
805             virtual DtMailMessageHandle getFirstMessageSummary(
806                                         DtMailEnv & error,
807                                         const DtMailHeaderRequest & header_list,
808                                         DtMailHeaderLine & header_line) = 0;
809             
810             virtual DtMailMessageHandle getNextMessageSummary(
811                                         DtMailEnv & error,
812                                         DtMailMessageHandle last,
813                                         const DtMailHeaderRequest & header_list,
814                                         DtMailHeaderLine & header_line) = 0;
815
816             virtual void getMessageSummary(
817                                         DtMailEnv & error,
818                                         DtMailMessageHandle handle,
819                                         const DtMailHeaderRequest &,
820                                         DtMailHeaderLine &) = 0;
821
822             virtual void clearMessageSummary(
823                                         DtMailHeaderLine &) = 0;
824
825             virtual Message * getMessage(
826                                         DtMailEnv & error,
827                                         DtMailMessageHandle message_handle) = 0;
828             
829             virtual Message * getFirstMessage(DtMailEnv &) = 0;
830             
831             virtual Message * getNextMessage(DtMailEnv &, Message * last) = 0;
832             
833             virtual Message * newMessage(DtMailEnv &) = 0;
834
835             virtual void copyMessage(DtMailEnv &, Message *) = 0;
836
837             virtual void copyMailBox(DtMailEnv &, MailBox *) = 0;
838
839             virtual void disableMailRetrieval() = 0;
840             virtual void enableMailRetrieval() = 0;
841             virtual void checkForMail(
842                         DtMailEnv &,
843                         const DtMailBoolean already_locked = DTM_FALSE) = 0;
844
845             virtual void createMailRetrievalAgent(char *password = NULL) = 0;
846             virtual void deleteMailRetrievalAgent() = 0;
847             virtual void updateMailRetrievalPassword(char *password = NULL) = 0;
848
849             virtual void expunge(DtMailEnv &) = 0;
850
851             virtual const char * impl(DtMailEnv & error) = 0;
852
853             // This method is typically used to propagate the session
854             // to embedded objects, such as Messages which may need to
855             // acquire the session to which it belongs.
856             //
857             virtual Session * session(void);
858             
859             virtual void callCallback(DtMailCallbackOp, void *) = 0;
860             virtual void startAutoSave(
861                                 DtMailEnv & error,
862                                 DtMailBoolean start=DTM_TRUE) = 0;
863             typedef void (*err_func)(char *,Boolean,void *);
864             void registerErrMsgFunc(err_func,void * client_data);
865             void unregisterErrMsgFunc(DtMailEnv &);
866             void showError(char *);
867
868             void hideAccessEvents(DtMailBoolean onoff)
869                         {_hide_access_events = onoff;}
870              
871             DtMailObjectKey getObjectKey(void)
872                         {return _key;}
873
874           private:
875             err_func                    _errmsg_func;
876             void *                      _err_data;
877
878
879           protected:
880             DtMailBoolean       _hide_access_events;
881
882             DtMailObjectKey     _key;
883             Session             *_session;
884             void                *_arg;
885             DtMailObjectSpace   _space;
886             DtMailCallback      _callback;
887             void                *_cb_data;
888             void                *_obj_mutex;
889             DtMailBoolean       _mail_box_writable;
890             mode_t              _default_mode;  // Default mode for file.
891         };
892     
893     class Transport : public DtCPlusPlusAllocator {
894       public:
895             virtual DtMailOperationId submit(
896                                         DtMailEnv &,
897                                         Message * msg,
898                                         DtMailBoolean log_msg = DTM_FALSE) = 0;
899
900             // SendMsgDialog initiates a send.  It needs to set information
901             // needed to exec sendmail by calling these init functions.
902             // getSendmailReturnProc returns a handler so that SendMsgDialog
903             // can use it in XtAppAddInput.
904             virtual void initTransportData(int fds[2],
905                 SubProcessFinishedProc proc, void *ptr) = 0;
906             virtual void *getSendmailReturnProc(void) = 0;
907
908
909             virtual void callCallback(DtMailOperationId, void * arg);
910
911           protected:
912             Transport(DtMailEnv &, Session *, DtMailStatusCallback, void *);
913             virtual ~Transport(void);
914
915             DtMailObjectKey             _key;
916             Session *                   _session;
917             DtMailStatusCallback        _callback;
918             void *                      _cb_data;
919             void *                      _obj_mutex;
920         };
921
922   private:
923     
924 friend class MailBox;
925 friend class Message;
926 friend class Envelope;
927 friend class BodyPart;
928 friend class Transport;
929 friend class EmbeddedMessage;
930 friend class FileMessage;
931 friend class FileShare;
932 friend class Session;
933     static void setError(
934                         Session &,
935                         DtMailEnv & error,
936                         DTMailError_t minor_code);
937 };
938
939 #if defined(sun) || defined(__FreeBSD__)
940 template <typename T>
941 size_t iconv (iconv_t i, const T inbuf, size_t* inleft,
942                char** outbuf, size_t* outleft)
943 {
944     return iconv(i, const_cast<T>(inbuf), inleft, outbuf, outleft);
945 };
946 #endif
947
948 #endif