/*
* Interactive Mail Access Protocol 2 (IMAP2) test program
*
* Mark Crispin, SUMEX Computer Project, 8 July 1988
*
* Copyright (c) 1988 Stanford University
*
*/
char selected[MAXMESSAGES]; /* T if message selected */
char *curhst = NIL; /* currently connected host */
char *curusr = NIL; /* current login user */
char personalname[256]; /* user's personal name */
/* Main program - initialization */
main ()
{
IMAPSTREAM *stream;
char tmp[256];
int debug = NIL;
printf ("MTest -- IMAP2/SMTP C client test program\n");
/* user wants protocol telemetry? */
prompt ("Debug protocol (y/n)?",tmp);
ucase (tmp);
if (tmp[0] == 'Y') debug = T;
prompt ("Mailbox: ",tmp); /* get mailbox to open */
/* open mailbox, no recycle stream */
stream = map_open (tmp,NIL,debug);
if (stream) {
prompt ("Personal name: ",personalname);
mm (stream,debug); /* run user interface if opened */
}
}
/* MM command loop
* Accepts: IMAP2 stream
*/
void mm (stream,debug)
IMAPSTREAM *stream;
int debug;
{
char cmd[256];
char *arg;
int i;
int last;
last = 0;
mm_status (stream); /* first report message status */
while (T) {
prompt ("MTest>",cmd); /* prompt user */
/* get command */
if (islower (cmd[0])) cmd[0] = toupper (cmd[0]);
switch (cmd[0]) {
case 'C': /* Check command */
map_checkmailbox (stream);
mm_status (stream);
break;
case 'D': /* Delete command */
arg = (char *) strchr (cmd,' ');
if (arg) {
++arg;
last = atoi (arg);
}
else {
if (last == 0 ) {
printf ("?Missing message number\n");
break;
}
arg = cmd;
sprintf (arg,"%d",last);
}
if (last > 0 && last <= stream->nmsgs)
map_setflag (stream,arg,"\\DELETED");
else printf ("?Bad message number\n");
break;
case 'E': /* Expunge command */
map_expungemailbox (stream);
last = 0;
break;
case 'H': /* Headers command */
arg = (char *) strchr (cmd,' ');
if (arg) {
++arg;
if (!(last = atoi (arg))) {
memset (selected,NIL,stream->nmsgs);
map_search (stream,arg);
for (i = 0; i < stream->nmsgs; ++i)
if (selected[i]) mm_header (stream,i+1);
break;
}
}
else if (last == 0) {
printf ("?Missing message number\n");
break;
}
if (last > 0 && last <= stream->nmsgs) mm_header (stream,last);
else printf ("?Bad message number\n");
break;
case 'N': /* New mailbox command */
arg = (char *) strchr (cmd,' ');
if (!arg) {
printf ("?Missing mailbox\n");
break;
}
++arg;
/* get the new mailbox */
stream = map_open (arg,stream,debug);
if (!stream) return; /* lost */
last = 0;
mm_status (stream);
break;
case 'Q': /* Quit command */
map_close (stream);
return;
case 'S': /* Send command */
smtptest (debug);
break;
case 'T': /* Type command */
arg = (char *) strchr (cmd,' ');
if (arg) {
++arg;
last = atoi (arg);
}
else if (last == 0 ) {
printf ("?Missing message number\n");
break;
}
if (last > 0 && last <= stream->nmsgs)
printf ("%s\n",map_fetchmessage (stream,last));
else printf ("?Bad message number\n");
break;
case 'U': /* Undelete command */
arg = (char *) strchr (cmd,' ');
if (arg) {
++arg;
last = atoi (arg);
}
else {
if (last == 0 ) {
printf ("?Missing message number\n");
break;
}
arg = cmd;
sprintf (arg,"%d",last);
}
if (last > 0 && last <= stream->nmsgs)
map_clearflag (stream,arg,"\\DELETED");
else printf ("?Bad message number\n");
break;
case 'X': /* Xit command */
map_expungemailbox (stream);
map_close (stream);
return;
case '+':
map_debug (stream); debug = T;
break;
case '-':
map_nodebug (stream); debug = NIL;
break;
case '?': /* ? command */
printf ("%s %s\n%s\n",
"Check, Delete, Expunge, Headers, New Mailbox,",
"Quit, Send, Type, Undelete, Xit",
" or <RETURN> for next message");
break;
case '\0': /* null command (type next message) */
if (last > 0 && last < stream->nmsgs)
printf ("%s\n",map_fetchmessage (stream,++last));
else printf ("%%No next message\n");
break;
default: /* bogus command */
printf ("?Unrecognized command: %s\n",cmd);
break;
}
}
}
/* MM status report
* Accepts: IMAP2 stream
*/
void mm_status (stream)
IMAPSTREAM *stream;
{
int i;
char date[50];
rfc822_date (date);
printf ("%s\nMailbox: {%s}%s, %d messages, %d recent\n",date,
tcp_host (stream->tcpstream),stream->mailbox,
stream->nmsgs,stream->recent);
if (stream->userFlags[0]) {
printf ("Keywords:");
for (i = 0; i <= NUSERFLAGS; ++i)
if (stream->userFlags[i]) printf (" %s",stream->userFlags[i]);
printf ("\n");
}
}
/* MM display header
* Accepts: IMAP2 stream
* message number
*/