1 /* $TOG: main.C /main/7 1998/10/26 17:19:37 mgreess $ */
9 // #include <Dt/DtNlUtils.h>
13 void Dt_nlInit( void );
17 #include <Dt/EnvControlP.h>
18 #include <Dt/DtPStrings.h>
24 gid_t _originalEgid; // startup effective gid
25 gid_t _originalRgid; // startup real gid
28 enableGroupPrivileges(void *)
30 (void) setgid(_originalEgid);
34 disableGroupPrivileges(void *)
36 (void) setgid(_originalRgid);
40 main (int argc, char **argv)
42 // parse command-line options
47 int aflag = 0, pgflag = 0;
50 // we have to be set-gid to group "mail" when opening and storing
51 // folders. But we don't want to do everything as group mail.
52 // here we record our original gid, and set the effective gid
53 // back the the real gid. We'll set it back when we're dealing
56 _originalEgid = getegid(); // remember effective group ID
57 _originalRgid = getgid(); // remember real group ID
58 disableGroupPrivileges((void *)0); // disable group privileges from
62 * To make DtDts*() function correctly, we have to call
63 * DtInitialize() or DtAppInitialize(). But they require Widget....
64 * Instead, just call Dt_nlInit() that is an internal function of
65 * libDtSvc.a. This is a temporary hack.....
67 _DtEnvControl(DT_ENV_SET);
68 setlocale( LC_ALL, "" );
71 while ((c = getopt(argc, argv, "f:aph?")) != EOF)
76 //printf ("Print each message on its own page\n");
80 //printf ("Strip attachments\n");
84 //printf ("Input file is: %s\n", ffile);
95 fprintf(stderr, "usage: %s [-p] [-a] [-f <filename>] \n", argv[0]);
99 //for ( ; optind < argc; optind++)
100 //(void)printf("%s\n", argv[optind]);
103 // create DtMail session
106 DtMail::Session *session;
110 session = new DtMail::Session (dmxenv, "dtmailpr");
113 if (handleError (dmxenv, "new session") == B_TRUE)
118 fprintf (stderr, "Error opening session...exiting.\n");
122 // Register all callbacks the backend may have to deal with
123 session->registerDisableGroupPrivilegesCallback(disableGroupPrivileges,
125 session->registerEnableGroupPrivilegesCallback(enableGroupPrivileges,
128 // initialize typing system (will go away eventually)
129 DtDtsLoadDataTypes ();
131 // temporary hack, until I'm sure that buffer objects are working
139 static char *tmpdir = new char[MAXPATHLEN+1];
145 DtPERSONAL_TMP_DIRECTORY);
147 name = tempnam(tmpdir, "dtmpr");
148 if ((msgFile = fopen (name, "w+")) == NULL)
154 while ( (n = read (fileno (stdin), buf, BUFSIZ)) > 0)
156 if (write (fileno (msgFile), buf, n) != n)
174 DtMail::MailBox *mailbox = NULL;
176 // try to construct mbox
177 mailbox = session->mailBoxConstruct (
185 if (handleError (dmxenv, "new DtMail::MailBox") == B_TRUE)
188 mbox.name = new char [strlen (name) +1];
189 strcpy (mbox.name, name);
192 mbox.loadMessages ();
196 for (m = 1; m <= mbox.messageCount; m++)
198 mbox.msg[m].getFlags ();
199 mbox.msg[m].display ();
200 if (m < mbox.messageCount) {