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

📄 imap4r1.c

📁 广泛使用的邮件服务器!同时
💻 C
📖 第 1 页 / 共 5 页
字号:
/* ======================================================================== * Copyright 1988-2008 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:	Interactive Message Access Protocol 4rev1 (IMAP4R1) routines * * Author:	Mark Crispin *		UW Technology *		University of Washington *		Seattle, WA  98195 *		Internet: MRC@CAC.Washington.EDU * * Date:	15 June 1988 * Last Edited:	8 May 2008 * * 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 National Institutes of Health * under grant number RR-00785. */#include <ctype.h>#include <stdio.h>#include <time.h>#include "c-client.h"#include "imap4r1.h"/* Parameters */#define IMAPLOOKAHEAD 20	/* envelope lookahead */#define IMAPUIDLOOKAHEAD 1000	/* UID lookahead */#define IMAPTCPPORT (long) 143	/* assigned TCP contact port */#define IMAPSSLPORT (long) 993	/* assigned SSL TCP contact port */#define MAXCOMMAND 1000		/* RFC 2683 guideline for cmd line length */#define IDLETIMEOUT (long) 30	/* defined in RFC 3501 */#define MAXSERVERLIT 0x7ffffffe	/* maximum server literal size				 * must be smaller than 4294967295				 *//* Parsed reply message from imap_reply */typedef struct imap_parsed_reply {  unsigned char *line;		/* original reply string pointer */  unsigned char *tag;		/* command tag this reply is for */  unsigned char *key;		/* reply keyword */  unsigned char *text;		/* subsequent text */} IMAPPARSEDREPLY;#define IMAPTMPLEN 16*MAILTMPLEN/* IMAP4 I/O stream local data */	typedef struct imap_local {  NETSTREAM *netstream;		/* TCP I/O stream */  IMAPPARSEDREPLY reply;	/* last parsed reply */  MAILSTATUS *stat;		/* status to fill in */  IMAPCAP cap;			/* server capabilities */  char *appendmailbox;		/* mailbox being appended to */  unsigned int uidsearch : 1;	/* UID searching */  unsigned int byeseen : 1;	/* saw a BYE response */				/* got implicit capabilities */  unsigned int gotcapability : 1;  unsigned int sensitive : 1;	/* sensitive data in progress */  unsigned int tlsflag : 1;	/* TLS session */  unsigned int tlssslv23 : 1;	/* TLS using SSLv23 client method */  unsigned int notlsflag : 1;	/* TLS not used in session */  unsigned int sslflag : 1;	/* SSL session */  unsigned int novalidate : 1;	/* certificate not validated */  unsigned int filter : 1;	/* filter SEARCH/SORT/THREAD results */  unsigned int loser : 1;	/* server is a loser */  unsigned int saslcancel : 1;	/* SASL cancelled by protocol */  long authflags;		/* required flags for authenticators */  unsigned long sortsize;	/* sort return data size */  unsigned long *sortdata;	/* sort return data */  struct {    unsigned long uid;		/* last UID returned */    unsigned long msgno;	/* last msgno returned */  } lastuid;  NAMESPACE **namespace;	/* namespace return data */  THREADNODE *threaddata;	/* thread return data */  char *referral;		/* last referral */  char *prefix;			/* find prefix */  char *user;			/* logged-in user */  char *reform;			/* reformed sequence */  char tmp[IMAPTMPLEN];		/* temporary buffer */  SEARCHSET *lookahead;		/* fetch lookahead */} IMAPLOCAL;/* Convenient access to local data */#define LOCAL ((IMAPLOCAL *) stream->local)/* Arguments to imap_send() */typedef struct imap_argument {  int type;			/* argument type */  void *text;			/* argument text */} IMAPARG;/* imap_send() argument types */#define ATOM 0#define NUMBER 1#define FLAGS 2#define ASTRING 3#define LITERAL 4#define LIST 5#define SEARCHPROGRAM 6#define SORTPROGRAM 7#define BODYTEXT 8#define BODYPEEK 9#define BODYCLOSE 10#define SEQUENCE 11#define LISTMAILBOX 12#define MULTIAPPEND 13#define SNLIST 14#define MULTIAPPENDREDO 15/* Append data */typedef struct append_data {  append_t af;  void *data;  char *flags;  char *date;  STRING *message;} APPENDDATA;/* Function prototypes */DRIVER *imap_valid (char *name);void *imap_parameters (long function,void *value);void imap_scan (MAILSTREAM *stream,char *ref,char *pat,char *contents);void imap_list (MAILSTREAM *stream,char *ref,char *pat);void imap_lsub (MAILSTREAM *stream,char *ref,char *pat);void imap_list_work (MAILSTREAM *stream,char *cmd,char *ref,char *pat,		     char *contents);long imap_subscribe (MAILSTREAM *stream,char *mailbox);long imap_unsubscribe (MAILSTREAM *stream,char *mailbox);long imap_create (MAILSTREAM *stream,char *mailbox);long imap_delete (MAILSTREAM *stream,char *mailbox);long imap_rename (MAILSTREAM *stream,char *old,char *newname);long imap_manage (MAILSTREAM *stream,char *mailbox,char *command,char *arg2);long imap_status (MAILSTREAM *stream,char *mbx,long flags);MAILSTREAM *imap_open (MAILSTREAM *stream);IMAPPARSEDREPLY *imap_rimap (MAILSTREAM *stream,char *service,NETMBX *mb,			     char *usr,char *tmp);long imap_anon (MAILSTREAM *stream,char *tmp);long imap_auth (MAILSTREAM *stream,NETMBX *mb,char *tmp,char *usr);long imap_login (MAILSTREAM *stream,NETMBX *mb,char *pwd,char *usr);void *imap_challenge (void *stream,unsigned long *len);long imap_response (void *stream,char *s,unsigned long size);void imap_close (MAILSTREAM *stream,long options);void imap_fast (MAILSTREAM *stream,char *sequence,long flags);void imap_flags (MAILSTREAM *stream,char *sequence,long flags);long imap_overview (MAILSTREAM *stream,overview_t ofn);ENVELOPE *imap_structure (MAILSTREAM *stream,unsigned long msgno,BODY **body,			  long flags);long imap_msgdata (MAILSTREAM *stream,unsigned long msgno,char *section,		   unsigned long first,unsigned long last,STRINGLIST *lines,		   long flags);unsigned long imap_uid (MAILSTREAM *stream,unsigned long msgno);unsigned long imap_msgno (MAILSTREAM *stream,unsigned long uid);void imap_flag (MAILSTREAM *stream,char *sequence,char *flag,long flags);long imap_search (MAILSTREAM *stream,char *charset,SEARCHPGM *pgm,long flags);unsigned long *imap_sort (MAILSTREAM *stream,char *charset,SEARCHPGM *spg,			  SORTPGM *pgm,long flags);THREADNODE *imap_thread (MAILSTREAM *stream,char *type,char *charset,			 SEARCHPGM *spg,long flags);THREADNODE *imap_thread_work (MAILSTREAM *stream,char *type,char *charset,			      SEARCHPGM *spg,long flags);long imap_ping (MAILSTREAM *stream);void imap_check (MAILSTREAM *stream);long imap_expunge (MAILSTREAM *stream,char *sequence,long options);long imap_copy (MAILSTREAM *stream,char *sequence,char *mailbox,long options);long imap_append (MAILSTREAM *stream,char *mailbox,append_t af,void *data);long imap_append_referral (char *mailbox,char *tmp,append_t af,void *data,			   char *flags,char *date,STRING *message,			   APPENDDATA *map,long options);IMAPPARSEDREPLY *imap_append_single (MAILSTREAM *stream,char *mailbox,				     char *flags,char *date,STRING *message);void imap_gc (MAILSTREAM *stream,long gcflags);void imap_gc_body (BODY *body);void imap_capability (MAILSTREAM *stream);long imap_acl_work (MAILSTREAM *stream,char *command,IMAPARG *args[]);IMAPPARSEDREPLY *imap_send (MAILSTREAM *stream,char *cmd,IMAPARG *args[]);IMAPPARSEDREPLY *imap_sout (MAILSTREAM *stream,char *tag,char *base,char **s);long imap_soutr (MAILSTREAM *stream,char *string);IMAPPARSEDREPLY *imap_send_astring (MAILSTREAM *stream,char *tag,char **s,				    SIZEDTEXT *as,long wildok,char *limit);IMAPPARSEDREPLY *imap_send_literal (MAILSTREAM *stream,char *tag,char **s,				    STRING *st);IMAPPARSEDREPLY *imap_send_spgm (MAILSTREAM *stream,char *tag,char *base,				 char **s,SEARCHPGM *pgm,char *limit);char *imap_send_spgm_trim (char *base,char *s,char *text);IMAPPARSEDREPLY *imap_send_sset (MAILSTREAM *stream,char *tag,char *base,				 char **s,SEARCHSET *set,char *prefix,				 char *limit);IMAPPARSEDREPLY *imap_send_slist (MAILSTREAM *stream,char *tag,char *base,				  char **s,char *name,STRINGLIST *list,				  char *limit);void imap_send_sdate (char **s,char *name,unsigned short date);IMAPPARSEDREPLY *imap_reply (MAILSTREAM *stream,char *tag);IMAPPARSEDREPLY *imap_parse_reply (MAILSTREAM *stream,char *text);IMAPPARSEDREPLY *imap_fake (MAILSTREAM *stream,char *tag,char *text);long imap_OK (MAILSTREAM *stream,IMAPPARSEDREPLY *reply);void imap_parse_unsolicited (MAILSTREAM *stream,IMAPPARSEDREPLY *reply);void imap_parse_response (MAILSTREAM *stream,char *text,long errflg,long ntfy);NAMESPACE *imap_parse_namespace (MAILSTREAM *stream,unsigned char **txtptr,				 IMAPPARSEDREPLY *reply);THREADNODE *imap_parse_thread (MAILSTREAM *stream,unsigned char **txtptr);void imap_parse_header (MAILSTREAM *stream,ENVELOPE **env,SIZEDTEXT *hdr,			STRINGLIST *stl);void imap_parse_envelope (MAILSTREAM *stream,ENVELOPE **env,			  unsigned char **txtptr,IMAPPARSEDREPLY *reply);ADDRESS *imap_parse_adrlist (MAILSTREAM *stream,unsigned char **txtptr,			     IMAPPARSEDREPLY *reply);ADDRESS *imap_parse_address (MAILSTREAM *stream,unsigned char **txtptr,			     IMAPPARSEDREPLY *reply);void imap_parse_flags (MAILSTREAM *stream,MESSAGECACHE *elt,		       unsigned char **txtptr);unsigned long imap_parse_user_flag (MAILSTREAM *stream,char *flag);unsigned char *imap_parse_astring (MAILSTREAM *stream,unsigned char **txtptr,			  IMAPPARSEDREPLY *reply,unsigned long *len);unsigned char *imap_parse_string (MAILSTREAM *stream,unsigned char **txtptr,				  IMAPPARSEDREPLY *reply,GETS_DATA *md,				  unsigned long *len,long flags);void imap_parse_body (GETS_DATA *md,char *seg,unsigned char **txtptr,		      IMAPPARSEDREPLY *reply);void imap_parse_body_structure (MAILSTREAM *stream,BODY *body,				unsigned char **txtptr,IMAPPARSEDREPLY *reply);PARAMETER *imap_parse_body_parameter (MAILSTREAM *stream,				      unsigned char **txtptr,				      IMAPPARSEDREPLY *reply);void imap_parse_disposition (MAILSTREAM *stream,BODY *body,			     unsigned char **txtptr,IMAPPARSEDREPLY *reply);STRINGLIST *imap_parse_language (MAILSTREAM *stream,unsigned char **txtptr,				 IMAPPARSEDREPLY *reply);STRINGLIST *imap_parse_stringlist (MAILSTREAM *stream,unsigned char **txtptr,				   IMAPPARSEDREPLY *reply);void imap_parse_extension (MAILSTREAM *stream,unsigned char **txtptr,			   IMAPPARSEDREPLY *reply);void imap_parse_capabilities (MAILSTREAM *stream,char *t);IMAPPARSEDREPLY *imap_fetch (MAILSTREAM *stream,char *sequence,long flags);char *imap_reform_sequence (MAILSTREAM *stream,char *sequence,long flags);/* Driver dispatch used by MAIL */DRIVER imapdriver = {  "imap",			/* driver name */				/* driver flags */  DR_MAIL|DR_NEWS|DR_NAMESPACE|DR_CRLF|DR_RECYCLE|DR_HALFOPEN,  (DRIVER *) NIL,		/* next driver */  imap_valid,			/* mailbox is valid for us */  imap_parameters,		/* manipulate parameters */  imap_scan,			/* scan mailboxes */  imap_list,			/* find mailboxes */  imap_lsub,			/* find subscribed mailboxes */  imap_subscribe,		/* subscribe to mailbox */  imap_unsubscribe,		/* unsubscribe from mailbox */  imap_create,			/* create mailbox */  imap_delete,			/* delete mailbox */  imap_rename,			/* rename mailbox */  imap_status,			/* status of mailbox */  imap_open,			/* open mailbox */  imap_close,			/* close mailbox */  imap_fast,			/* fetch message "fast" attributes */  imap_flags,			/* fetch message flags */  imap_overview,		/* fetch overview */  imap_structure,		/* fetch message envelopes */  NIL,				/* fetch message header */  NIL,				/* fetch message body */  imap_msgdata,			/* fetch partial message */  imap_uid,			/* unique identifier */  imap_msgno,			/* message number */  imap_flag,			/* modify flags */  NIL,				/* per-message modify flags */  imap_search,			/* search for message based on criteria */  imap_sort,			/* sort messages */  imap_thread,			/* thread messages */  imap_ping,			/* ping mailbox to see if still alive */  imap_check,			/* check for new messages */  imap_expunge,			/* expunge deleted messages */  imap_copy,			/* copy messages to another mailbox */  imap_append,			/* append string message to mailbox */  imap_gc			/* garbage collect stream */};				/* prototype stream */MAILSTREAM imapproto = {&imapdriver};				/* driver parameters */static unsigned long imap_maxlogintrials = MAXLOGINTRIALS;static long imap_lookahead = IMAPLOOKAHEAD;static long imap_uidlookahead = IMAPUIDLOOKAHEAD;static long imap_fetchlookaheadlimit = IMAPLOOKAHEAD;static long imap_defaultport = 0;static long imap_sslport = 0;static long imap_tryssl = NIL;static long imap_prefetch = IMAPLOOKAHEAD;static long imap_closeonerror = NIL;static imapenvelope_t imap_envelope = NIL;static imapreferral_t imap_referral = NIL;static char *imap_extrahdrs = NIL;				/* constants */static char *hdrheader[] = {  "BODY.PEEK[HEADER.FIELDS (Newsgroups Content-MD5 Content-Disposition Content-Language Content-Location",  "BODY.PEEK[HEADER.FIELDS (Newsgroups Content-Disposition Content-Language Content-Location",  "BODY.PEEK[HEADER.FIELDS (Newsgroups Content-Language Content-Location",  "BODY.PEEK[HEADER.FIELDS (Newsgroups Content-Location",  "BODY.PEEK[HEADER.FIELDS (Newsgroups"};static char *hdrtrailer ="Followup-To References)]";/* IMAP validate mailbox * Accepts: mailbox name * Returns: our driver if name is valid, NIL otherwise */DRIVER *imap_valid (char *name){  return mail_valid_net (name,&imapdriver,NIL,NIL);}/* IMAP manipulate driver parameters * Accepts: function code *	    function-dependent value * Returns: function-dependent return value */void *imap_parameters (long function,void *value){  switch ((int) function) {  case GET_NAMESPACE:    if (((IMAPLOCAL *) ((MAILSTREAM *) value)->local)->cap.namespace &&	!((IMAPLOCAL *) ((MAILSTREAM *) value)->local)->namespace)      imap_send (((MAILSTREAM *) value),"NAMESPACE",NIL);    value = (void *) &((IMAPLOCAL *) ((MAILSTREAM *) value)->local)->namespace;    break;  case GET_THREADERS:    value = (void *)      ((IMAPLOCAL *) ((MAILSTREAM *) value)->local)->cap.threader;    break;  case SET_FETCHLOOKAHEAD:	/* must use pointer from GET_FETCHLOOKAHEAD */

⌨️ 快捷键说明

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