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 libraries 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 if(-1 == setgid(_originalEgid)) {
53 fprintf(stderr, "Failed to enable group priviledges\n");
58 disableGroupPrivileges(void *)
60 if(-1 == setgid(_originalRgid)) {
61 fprintf(stderr, "Failed to disable group priviledges\n");
66 main (int argc, char **argv)
68 // parse command-line options
73 int aflag = 0, pgflag = 0;
76 // we have to be set-gid to group "mail" when opening and storing
77 // folders. But we don't want to do everything as group mail.
78 // here we record our original gid, and set the effective gid
79 // back the the real gid. We'll set it back when we're dealing
82 _originalEgid = getegid(); // remember effective group ID
83 _originalRgid = getgid(); // remember real group ID
84 disableGroupPrivileges((void *)0); // disable group privileges from
88 * To make DtDts*() function correctly, we have to call
89 * DtInitialize() or DtAppInitialize(). But they require Widget....
90 * Instead, just call Dt_nlInit() that is an internal function of
91 * libDtSvc.a. This is a temporary hack.....
93 _DtEnvControl(DT_ENV_SET);
94 setlocale( LC_ALL, "" );
97 while ((c = getopt(argc, argv, "f:aph?")) != EOF)
102 //printf ("Print each message on its own page\n");
106 //printf ("Strip attachments\n");
110 //printf ("Input file is: %s\n", ffile);
121 fprintf(stderr, "usage: %s [-p] [-a] [-f <filename>] \n", argv[0]);
125 //for ( ; optind < argc; optind++)
126 //(void)printf("%s\n", argv[optind]);
129 // create DtMail session
132 DtMail::Session *session;
136 session = new DtMail::Session (dmxenv, "dtmailpr");
139 if (handleError (dmxenv, "new session") == B_TRUE)
144 fprintf (stderr, "Error opening session...exiting.\n");
148 // Register all callbacks the backend may have to deal with
149 session->registerDisableGroupPrivilegesCallback(disableGroupPrivileges,
151 session->registerEnableGroupPrivilegesCallback(enableGroupPrivileges,
154 // initialize typing system (will go away eventually)
155 DtDtsLoadDataTypes ();
157 // temporary hack, until I'm sure that buffer objects are working
165 static char *tmpdir = new char[MAXPATHLEN+1];
171 DtPERSONAL_TMP_DIRECTORY);
173 name = tempnam(tmpdir, "dtmpr");
174 if ((msgFile = fopen (name, "w+")) == NULL)
180 while ( (n = read (fileno (stdin), buf, BUFSIZ)) > 0)
182 if (write (fileno (msgFile), buf, n) != n)
200 DtMail::MailBox *mailbox = NULL;
202 // try to construct mbox
203 mailbox = session->mailBoxConstruct (
211 if (handleError (dmxenv, "new DtMail::MailBox") == B_TRUE)
214 mbox.name = new char [strlen (name) +1];
215 strcpy (mbox.name, name);
218 mbox.loadMessages ();
222 for (m = 1; m <= mbox.messageCount; m++)
224 mbox.msg[m].getFlags ();
225 mbox.msg[m].display ();
226 if (m < mbox.messageCount) {