⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mtest.c

📁 广泛使用的邮件服务器!同时
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ======================================================================== * Copyright 1988-2007 University of Washington * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * *  * ======================================================================== *//* * Program:	Mail library test program * * Author:	Mark Crispin *		Networks and Distributed Computing *		Computing & Communications *		University of Washington *		Administration Building, AG-44 *		Seattle, WA  98195 *		Internet: MRC@CAC.Washington.EDU * * Date:	8 July 1988 * Last Edited:	5 November 2007 * * This original version of this file is * Copyright 1988 Stanford University * and was developed in the Symbolic Systems Resources Group of the Knowledge * Systems Laboratory at Stanford University in 1987-88, and was funded by the * Biomedical Research Technology Program of the NationalInstitutes of Health * under grant number RR-00785. */#include <stdio.h>#include <ctype.h>#include <signal.h>#include "c-client.h"#include "imap4r1.h"/* Excellent reasons to hate ifdefs, and why my real code never uses them */#ifndef unix# define unix 0#endif#if unix# define UNIXLIKE 1# define MACOS 0# include <pwd.h>#else# define UNIXLIKE 0# ifdef noErr#  define MACOS 1#  include <Memory.h># else#  define MACOS 0# endif#endifchar *curhst = NIL;		/* currently connected host */char *curusr = NIL;		/* current login user */char personalname[MAILTMPLEN];	/* user's personal name */static char *hostlist[] = {	/* SMTP server host list */  "mailhost",  "localhost",  NIL};static char *newslist[] = {	/* Netnews server host list */  "news",  NIL};int main (void);void mm (MAILSTREAM *stream,long debug);void overview_header (MAILSTREAM *stream,unsigned long uid,OVERVIEW *ov,		      unsigned long msgno);void header (MAILSTREAM *stream,long msgno);void display_body (BODY *body,char *pfx,long i);void status (MAILSTREAM *stream);void prompt (char *msg,char *txt);void smtptest (long debug);/* Main program - initialization */int main (){  MAILSTREAM *stream = NIL;  void *sdb = NIL;  char *s,tmp[MAILTMPLEN];  long debug;#include "linkage.c"#if MACOS  {    size_t *base = (size_t *) 0x000908;				/* increase stack size on a Mac */    SetApplLimit ((Ptr) (*base - (size_t) 65535L));  }#endif  curusr = cpystr (((s = myusername ()) && *s) ? s : "somebody");#if UNIXLIKE  {    char *suffix;    struct passwd *pwd = getpwnam (curusr);    if (pwd) {      strcpy (tmp,pwd->pw_gecos);				/* dyke out the office and phone poop */      if (suffix = strchr (tmp,',')) suffix[0] = '\0';      strcpy (personalname,tmp);/* make a permanent copy of it */    }    else personalname[0] = '\0';  }#else  personalname[0] = '\0';#endif  curhst = cpystr (mylocalhost ());  puts ("MTest -- C client test program");  if (!*personalname) prompt ("Personal name: ",personalname);				/* user wants protocol telemetry? */  prompt ("Debug protocol (y/n)?",tmp);  ucase (tmp);  debug = (tmp[0] == 'Y') ? T : NIL;  do {    prompt ("Mailbox ('?' for help): ",tmp);    if (!strcmp (tmp,"?")) {      puts ("Enter INBOX, mailbox name, or IMAP mailbox as {host}mailbox");      puts ("Known local mailboxes:");      mail_list (NIL,NIL,"%");      if (s = sm_read (&sdb)) {	puts ("Local subscribed mailboxes:");	do (mm_lsub (NIL,NIL,s,NIL));	while (s = sm_read (&sdb));      }      puts ("or just hit return to quit");    }    else if (tmp[0]) stream = mail_open (stream,tmp,debug ? OP_DEBUG : NIL);  } while (!stream && tmp[0]);  mm (stream,debug);		/* run user interface if opened */#if MACOS				/* clean up resolver */  if (resolveropen) CloseResolver ();#endif  return NIL;}/* MM command loop * Accepts: MAIL stream */void mm (MAILSTREAM *stream,long debug){  void *sdb = NIL;  char cmd[MAILTMPLEN];  char *s,*arg;  unsigned long i;  unsigned long last = 0;  BODY *body;  status (stream);		/* first report message status */  while (stream) {    prompt ("MTest>",cmd);	/* prompt user, get command */				/* get argument */    if (arg = strchr (cmd,' ')) *arg++ = '\0';    switch (*ucase (cmd)) {	/* dispatch based on command */    case 'B':			/* Body command */      if (arg) last = atoi (arg);      else if (!last) {	puts ("?Missing message number");	break;      }      if (last && (last <= stream->nmsgs)) {	mail_fetchstructure (stream,last,&body);	if (body) display_body (body,NIL,(long) 0);	else puts ("%No body information available");      }      else puts ("?Bad message number");      break;    case 'C':			/* Check command */      mail_check (stream);      status (stream);      break;    case 'D':			/* Delete command */      if (arg) last = atoi (arg);      else {	if (last == 0) {	  puts ("?Missing message number");	  break;	}	arg = cmd;	sprintf (arg,"%lu",last);      }      if (last && (last <= stream->nmsgs))	mail_setflag (stream,arg,"\\DELETED");      else puts ("?Bad message number");      break;    case 'E':			/* Expunge command */      mail_expunge (stream);      last = 0;      break;    case 'F':			/* Find command */      if (!arg) {	arg = "%";	if (s = sm_read (&sdb)) {	  puts ("Local network subscribed mailboxes:");	  do if (*s == '{') (mm_lsub (NIL,NIL,s,NIL));	  while (s = sm_read (&sdb));	}      }      puts ("Subscribed mailboxes:");      mail_lsub (((arg[0] == '{') && (*stream->mailbox == '{')) ? stream : NIL,		 NIL,arg);      puts ("Known mailboxes:");      mail_list (((arg[0] == '{') && (*stream->mailbox == '{')) ? stream : NIL,		 NIL,arg);      break;    case 'G':      mail_gc (stream,GC_ENV|GC_TEXTS|GC_ELT);      break;    case 'H':			/* Headers command */      if (arg) {	if (!(last = atoi (arg))) {	  mail_search (stream,arg);	  for (i = 1; i <= stream->nmsgs; ++i)	    if (mail_elt (stream,i)->searched) header (stream,i);	  break;	}      }      else if (last == 0) {	puts ("?Missing message number");	break;      }      if (last && (last <= stream->nmsgs)) header (stream,last);      else puts ("?Bad message number");      break;    case 'L':			/* Literal command */      if (arg) last = atoi (arg);      else if (!last) {	puts ("?Missing message number");	break;      }      if (last && (last <= stream->nmsgs))	puts (mail_fetch_message (stream,last,NIL,NIL));      else puts ("?Bad message number");      break;    case 'M':      mail_status (NIL,arg ? arg : stream->mailbox,		   SA_MESSAGES|SA_RECENT|SA_UNSEEN|SA_UIDNEXT|SA_UIDVALIDITY);      break;    case 'N':			/* New mailbox command */      if (!arg) {	puts ("?Missing mailbox");	break;      }				/* get the new mailbox */      while (!(stream = mail_open (stream,arg,debug))) {	prompt ("Mailbox: ",arg);	if (!arg[0]) break;      }      last = 0;      status (stream);      break;    case 'O':			/* Overview command */      if (!arg) {	puts ("?Missing UID");	break;      }      mail_fetch_overview (stream,arg,overview_header);      break;    case 'P':			/* Ping command */      mail_ping (stream);      status (stream);      break;    case 'Q':			/* Quit command */      mail_close (stream);      stream = NIL;      break;    case 'S':			/* Send command */      smtptest (debug);      break;    case '\0':			/* null command (type next message) */      if (!last || (last++ >= stream->nmsgs)) {	puts ("%No next message");	break;      }    case 'T':			/* Type command */      if (arg) last = atoi (arg);      else if (!last) {	puts ("?Missing message number");	break;      }      if (last && (last <= stream->nmsgs)) {	STRINGLIST *lines = mail_newstringlist ();	STRINGLIST *cur = lines;	cur->text.size = strlen ((char *) (cur->text.data = (unsigned char *)					   cpystr ("Date")));	cur = cur->next = mail_newstringlist ();	cur->text.size = strlen ((char *) (cur->text.data = (unsigned char *)					   cpystr ("From")));	cur = cur->next = mail_newstringlist ();	cur->text.size = strlen ((char *) (cur->text.data = (unsigned char *)					   cpystr (">From")));	cur = cur->next = mail_newstringlist ();	cur->text.size = strlen ((char *) (cur->text.data = (unsigned char *)					   cpystr ("Subject")));	cur = cur->next = mail_newstringlist ();	cur->text.size = strlen ((char *) (cur->text.data = (unsigned char *)					   cpystr ("To")));	cur = cur->next = mail_newstringlist ();	cur->text.size = strlen ((char *) (cur->text.data = (unsigned char *)					   cpystr ("cc")));	cur = cur->next = mail_newstringlist ();	cur->text.size = strlen ((char *) (cur->text.data = (unsigned char *)					   cpystr ("Newsgroups")));	printf ("%s",mail_fetchheader_full (stream,last,lines,NIL,NIL));	puts (mail_fetchtext (stream,last));	mail_free_stringlist (&lines);      }      else puts ("?Bad message number");      break;    case 'U':			/* Undelete command */      if (arg) last = atoi (arg);      else {	if (!last) {	  puts ("?Missing message number");	  break;	}	arg = cmd;	sprintf (arg,"%lu",last);      }      if (last > 0 && last <= stream->nmsgs)	mail_clearflag (stream,arg,"\\DELETED");      else puts ("?Bad message number");      break;    case 'X':			/* Xit command */      mail_expunge (stream);      mail_close (stream);      stream = NIL;      break;    case '+':      mail_debug (stream); debug = T;      break;    case '-':      mail_nodebug (stream); debug = NIL;      break;    case '?':			/* ? command */      puts ("Body, Check, Delete, Expunge, Find, GC, Headers, Literal,");      puts (" MailboxStatus, New Mailbox, Overview, Ping, Quit, Send, Type,");      puts ("Undelete, Xit, +, -, or <RETURN> for next message");      break;    default:			/* bogus command */      printf ("?Unrecognized command: %s\n",cmd);      break;    }  }}/* MM display header * Accepts: IMAP2 stream *	    message number */void overview_header (MAILSTREAM *stream,unsigned long uid,OVERVIEW *ov,		      unsigned long msgno){  if (ov) {    unsigned long i;    char *t,tmp[MAILTMPLEN];    ADDRESS *adr;    MESSAGECACHE *elt = mail_elt (stream,msgno);    MESSAGECACHE selt;    tmp[0] = elt->recent ? (elt->seen ? 'R': 'N') : ' ';    tmp[1] = (elt->recent | elt->seen) ? ' ' : 'U';    tmp[2] = elt->flagged ? 'F' : ' ';    tmp[3] = elt->answered ? 'A' : ' ';    tmp[4] = elt->deleted ? 'D' : ' ';    mail_parse_date (&selt,ov->date);    sprintf (tmp+5,"%4lu) ",elt->msgno);    mail_date (tmp+11,&selt);    tmp[17] = ' ';    tmp[18] = '\0';    memset (tmp+18,' ',(size_t) 20);    tmp[38] = '\0';		/* tie off with null */				/* get first from address from envelope */    for (adr = ov->from; adr && !adr->host; adr = adr->next);    if (adr) {			/* if a personal name exists use it */      if (!(t = adr->personal))	sprintf (t = tmp+400,"%s@%s",adr->mailbox,adr->host);      memcpy (tmp+18,t,(size_t) min (20,(long) strlen (t)));    }    strcat (tmp," ");    if (i = elt->user_flags) {      strcat (tmp,"{");      while (i) {	strcat (tmp,stream->user_flags[find_rightmost_bit (&i)]);	if (i) strcat (tmp," ");      }      strcat (tmp,"} ");    }    sprintf (tmp + strlen (tmp),"%.25s (%lu chars)",	     ov->subject ? ov->subject : " ",ov->optional.octets);    puts (tmp);  }  else printf ("%%No overview for UID %lu\n",uid);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -