2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $TOG: main.C /main/7 1998/10/26 17:19:37 mgreess $ */
30 #include <sys/param.h>
31 // #include <Dt/DtNlUtils.h>
35 void Dt_nlInit( void );
39 #include <Dt/EnvControlP.h>
40 #include <Dt/DtPStrings.h>
46 gid_t _originalEgid; // startup effective gid
47 gid_t _originalRgid; // startup real gid
50 enableGroupPrivileges(void *)
52 (void) setgid(_originalEgid);
56 disableGroupPrivileges(void *)
58 (void) setgid(_originalRgid);
62 main (int argc, char **argv)
64 // parse command-line options
69 int aflag = 0, pgflag = 0;
72 // we have to be set-gid to group "mail" when opening and storing
73 // folders. But we don't want to do everything as group mail.
74 // here we record our original gid, and set the effective gid
75 // back the the real gid. We'll set it back when we're dealing
78 _originalEgid = getegid(); // remember effective group ID
79 _originalRgid = getgid(); // remember real group ID
80 disableGroupPrivileges((void *)0); // disable group privileges from
84 * To make DtDts*() function correctly, we have to call
85 * DtInitialize() or DtAppInitialize(). But they require Widget....
86 * Instead, just call Dt_nlInit() that is an internal function of
87 * libDtSvc.a. This is a temporary hack.....
89 _DtEnvControl(DT_ENV_SET);
90 setlocale( LC_ALL, "" );
93 while ((c = getopt(argc, argv, "f:aph?")) != EOF)
98 //printf ("Print each message on its own page\n");
102 //printf ("Strip attachments\n");
106 //printf ("Input file is: %s\n", ffile);
117 fprintf(stderr, "usage: %s [-p] [-a] [-f <filename>] \n", argv[0]);
121 //for ( ; optind < argc; optind++)
122 //(void)printf("%s\n", argv[optind]);
125 // create DtMail session
128 DtMail::Session *session;
132 session = new DtMail::Session (dmxenv, "dtmailpr");
135 if (handleError (dmxenv, "new session") == B_TRUE)
140 fprintf (stderr, "Error opening session...exiting.\n");
144 // Register all callbacks the backend may have to deal with
145 session->registerDisableGroupPrivilegesCallback(disableGroupPrivileges,
147 session->registerEnableGroupPrivilegesCallback(enableGroupPrivileges,
150 // initialize typing system (will go away eventually)
151 DtDtsLoadDataTypes ();
153 // temporary hack, until I'm sure that buffer objects are working
161 static char *tmpdir = new char[MAXPATHLEN+1];
167 DtPERSONAL_TMP_DIRECTORY);
169 name = tempnam(tmpdir, "dtmpr");
170 if ((msgFile = fopen (name, "w+")) == NULL)
176 while ( (n = read (fileno (stdin), buf, BUFSIZ)) > 0)
178 if (write (fileno (msgFile), buf, n) != n)
196 DtMail::MailBox *mailbox = NULL;
198 // try to construct mbox
199 mailbox = session->mailBoxConstruct (
207 if (handleError (dmxenv, "new DtMail::MailBox") == B_TRUE)
210 mbox.name = new char [strlen (name) +1];
211 strcpy (mbox.name, name);
214 mbox.loadMessages ();
218 for (m = 1; m <= mbox.messageCount; m++)
220 mbox.msg[m].getFlags ();
221 mbox.msg[m].display ();
222 if (m < mbox.messageCount) {