📄 imap4r1.c
字号:
fatal ("SET_FETCHLOOKAHEAD not permitted"); case GET_FETCHLOOKAHEAD: value = (void *) &((IMAPLOCAL *) ((MAILSTREAM *) value)->local)->lookahead; break; case SET_MAXLOGINTRIALS: imap_maxlogintrials = (long) value; break; case GET_MAXLOGINTRIALS: value = (void *) imap_maxlogintrials; break; case SET_LOOKAHEAD: imap_lookahead = (long) value; break; case GET_LOOKAHEAD: value = (void *) imap_lookahead; break; case SET_UIDLOOKAHEAD: imap_uidlookahead = (long) value; break; case GET_UIDLOOKAHEAD: value = (void *) imap_uidlookahead; break; case SET_IMAPPORT: imap_defaultport = (long) value; break; case GET_IMAPPORT: value = (void *) imap_defaultport; break; case SET_SSLIMAPPORT: imap_sslport = (long) value; break; case GET_SSLIMAPPORT: value = (void *) imap_sslport; break; case SET_PREFETCH: imap_prefetch = (long) value; break; case GET_PREFETCH: value = (void *) imap_prefetch; break; case SET_CLOSEONERROR: imap_closeonerror = (long) value; break; case GET_CLOSEONERROR: value = (void *) imap_closeonerror; break; case SET_IMAPENVELOPE: imap_envelope = (imapenvelope_t) value; break; case GET_IMAPENVELOPE: value = (void *) imap_envelope; break; case SET_IMAPREFERRAL: imap_referral = (imapreferral_t) value; break; case GET_IMAPREFERRAL: value = (void *) imap_referral; break; case SET_IMAPEXTRAHEADERS: imap_extrahdrs = (char *) value; break; case GET_IMAPEXTRAHEADERS: value = (void *) imap_extrahdrs; break; case SET_IMAPTRYSSL: imap_tryssl = (long) value; break; case GET_IMAPTRYSSL: value = (void *) imap_tryssl; break; case SET_FETCHLOOKAHEADLIMIT: imap_fetchlookaheadlimit = (long) value; break; case GET_FETCHLOOKAHEADLIMIT: value = (void *) imap_fetchlookaheadlimit; break; case SET_IDLETIMEOUT: fatal ("SET_IDLETIMEOUT not permitted"); case GET_IDLETIMEOUT: value = (void *) IDLETIMEOUT; break; default: value = NIL; /* error case */ break; } return value;}/* IMAP scan mailboxes * Accepts: mail stream * reference * pattern to search * string to scan */void imap_scan (MAILSTREAM *stream,char *ref,char *pat,char *contents){ imap_list_work (stream,"SCAN",ref,pat,contents);}/* IMAP list mailboxes * Accepts: mail stream * reference * pattern to search */void imap_list (MAILSTREAM *stream,char *ref,char *pat){ imap_list_work (stream,"LIST",ref,pat,NIL);}/* IMAP list subscribed mailboxes * Accepts: mail stream * reference * pattern to search */void imap_lsub (MAILSTREAM *stream,char *ref,char *pat){ void *sdb = NIL; char *s,mbx[MAILTMPLEN]; /* do it on the server */ imap_list_work (stream,"LSUB",ref,pat,NIL); if (*pat == '{') { /* if remote pattern, must be IMAP */ if (!imap_valid (pat)) return; ref = NIL; /* good IMAP pattern, punt reference */ } /* if remote reference, must be valid IMAP */ if (ref && (*ref == '{') && !imap_valid (ref)) return; /* kludgy application of reference */ if (ref && *ref) sprintf (mbx,"%s%s",ref,pat); else strcpy (mbx,pat); if (s = sm_read (&sdb)) do if (imap_valid (s) && pmatch (s,mbx)) mm_lsub (stream,NIL,s,NIL); while (s = sm_read (&sdb)); /* until no more subscriptions */}/* IMAP find list of mailboxes * Accepts: mail stream * list command * reference * pattern to search * string to scan */void imap_list_work (MAILSTREAM *stream,char *cmd,char *ref,char *pat, char *contents){ MAILSTREAM *st = stream; int pl; char *s,prefix[MAILTMPLEN],mbx[MAILTMPLEN]; IMAPARG *args[4],aref,apat,acont; if (ref && *ref) { /* have a reference? */ if (!(imap_valid (ref) && /* make sure valid IMAP name and open stream */ ((stream && LOCAL && LOCAL->netstream) || (stream = mail_open (NIL,ref,OP_HALFOPEN|OP_SILENT))))) return; /* calculate prefix length */ pl = strchr (ref,'}') + 1 - ref; strncpy (prefix,ref,pl); /* build prefix */ prefix[pl] = '\0'; /* tie off prefix */ ref += pl; /* update reference */ } else { if (!(imap_valid (pat) && /* make sure valid IMAP name and open stream */ ((stream && LOCAL && LOCAL->netstream) || (stream = mail_open (NIL,pat,OP_HALFOPEN|OP_SILENT))))) return; /* calculate prefix length */ pl = strchr (pat,'}') + 1 - pat; strncpy (prefix,pat,pl); /* build prefix */ prefix[pl] = '\0'; /* tie off prefix */ pat += pl; /* update reference */ } LOCAL->prefix = prefix; /* note prefix */ if (contents) { /* want to do a scan? */ if (LEVELSCAN (stream)) { /* make sure permitted */ args[0] = &aref; args[1] = &apat; args[2] = &acont; args[3] = NIL; aref.type = ASTRING; aref.text = (void *) (ref ? ref : ""); apat.type = LISTMAILBOX; apat.text = (void *) pat; acont.type = ASTRING; acont.text = (void *) contents; imap_send (stream,cmd,args); } else mm_log ("Scan not valid on this IMAP server",ERROR); } else if (LEVELIMAP4 (stream)){/* easy if IMAP4 */ args[0] = &aref; args[1] = &apat; args[2] = NIL; aref.type = ASTRING; aref.text = (void *) (ref ? ref : ""); apat.type = LISTMAILBOX; apat.text = (void *) pat; /* referrals armed? */ if (LOCAL->cap.mbx_ref && mail_parameters (stream,GET_IMAPREFERRAL,NIL)) { /* yes, convert LIST -> RLIST */ if (!compare_cstring (cmd,"LIST")) cmd = "RLIST"; /* and convert LSUB -> RLSUB */ else if (!compare_cstring (cmd,"LSUB")) cmd = "RLSUB"; } imap_send (stream,cmd,args); } else if (LEVEL1176 (stream)) {/* convert to IMAP2 format wildcard */ /* kludgy application of reference */ if (ref && *ref) sprintf (mbx,"%s%s",ref,pat); else strcpy (mbx,pat); for (s = mbx; *s; s++) if (*s == '%') *s = '*'; args[0] = &apat; args[1] = NIL; apat.type = LISTMAILBOX; apat.text = (void *) mbx; if (!(strstr (cmd,"LIST") &&/* if list, try IMAP2bis, then RFC-1176 */ strcmp (imap_send (stream,"FIND ALL.MAILBOXES",args)->key,"BAD")) && !strcmp (imap_send (stream,"FIND MAILBOXES",args)->key,"BAD")) LOCAL->cap.rfc1176 = NIL; /* must be RFC-1064 */ } LOCAL->prefix = NIL; /* no more prefix */ /* close temporary stream if we made one */ if (stream != st) mail_close (stream);}/* IMAP subscribe to mailbox * Accepts: mail stream * mailbox to add to subscription list * Returns: T on success, NIL on failure */long imap_subscribe (MAILSTREAM *stream,char *mailbox){ MAILSTREAM *st = stream; long ret = ((stream && LOCAL && LOCAL->netstream) || (stream = mail_open (NIL,mailbox,OP_HALFOPEN|OP_SILENT))) ? imap_manage (stream,mailbox,LEVELIMAP4 (stream) ? "Subscribe" : "Subscribe Mailbox",NIL) : NIL; /* toss out temporary stream */ if (st != stream) mail_close (stream); return ret;}/* IMAP unsubscribe to mailbox * Accepts: mail stream * mailbox to delete from manage list * Returns: T on success, NIL on failure */long imap_unsubscribe (MAILSTREAM *stream,char *mailbox){ MAILSTREAM *st = stream; long ret = ((stream && LOCAL && LOCAL->netstream) || (stream = mail_open (NIL,mailbox,OP_HALFOPEN|OP_SILENT))) ? imap_manage (stream,mailbox,LEVELIMAP4 (stream) ? "Unsubscribe" : "Unsubscribe Mailbox",NIL) : NIL; /* toss out temporary stream */ if (st != stream) mail_close (stream); return ret;}/* IMAP create mailbox * Accepts: mail stream * mailbox name to create * Returns: T on success, NIL on failure */long imap_create (MAILSTREAM *stream,char *mailbox){ return imap_manage (stream,mailbox,"Create",NIL);}/* IMAP delete mailbox * Accepts: mail stream * mailbox name to delete * Returns: T on success, NIL on failure */long imap_delete (MAILSTREAM *stream,char *mailbox){ return imap_manage (stream,mailbox,"Delete",NIL);}/* IMAP rename mailbox * Accepts: mail stream * old mailbox name * new mailbox name * Returns: T on success, NIL on failure */long imap_rename (MAILSTREAM *stream,char *old,char *newname){ return imap_manage (stream,old,"Rename",newname);}/* IMAP manage a mailbox * Accepts: mail stream * mailbox to manipulate * command to execute * optional second argument * Returns: T on success, NIL on failure */long imap_manage (MAILSTREAM *stream,char *mailbox,char *command,char *arg2){ MAILSTREAM *st = stream; IMAPPARSEDREPLY *reply; long ret = NIL; char mbx[MAILTMPLEN],mbx2[MAILTMPLEN]; IMAPARG *args[3],ambx,amb2; imapreferral_t ir = (imapreferral_t) mail_parameters (stream,GET_IMAPREFERRAL,NIL); ambx.type = amb2.type = ASTRING; ambx.text = (void *) mbx; amb2.text = (void *) mbx2; args[0] = &ambx; args[1] = args[2] = NIL; /* require valid names and open stream */ if (mail_valid_net (mailbox,&imapdriver,NIL,mbx) && (arg2 ? mail_valid_net (arg2,&imapdriver,NIL,mbx2) : &imapdriver) && ((stream && LOCAL && LOCAL->netstream) || (stream = mail_open (NIL,mailbox,OP_HALFOPEN|OP_SILENT)))) { if (arg2) args[1] = &amb2; /* second arg present? */ if (!(ret = (imap_OK (stream,reply = imap_send (stream,command,args)))) && ir && LOCAL->referral) { long code = -1; switch (*command) { /* which command was it? */ case 'S': code = REFSUBSCRIBE; break; case 'U': code = REFUNSUBSCRIBE; break; case 'C': code = REFCREATE; break; case 'D': code = REFDELETE; break; case 'R': code = REFRENAME; break; default: fatal ("impossible referral command"); } if ((code >= 0) && (mailbox = (*ir) (stream,LOCAL->referral,code))) ret = imap_manage (NIL,mailbox,command,(*command == 'R') ? (mailbox + strlen (mailbox) + 1) : NIL); } mm_log (reply->text,ret ? NIL : ERROR); /* toss out temporary stream */ if (st != stream) mail_close (stream); } return ret;}/* IMAP status * Accepts: mail stream * mailbox name * status flags * Returns: T on success, NIL on failure */long imap_status (MAILSTREAM *stream,char *mbx,long flags){ IMAPARG *args[3],ambx,aflg; char tmp[MAILTMPLEN]; NETMBX mb; unsigned long i; long ret = NIL; MAILSTREAM *tstream = NIL; /* use given stream if (rev1 or halfopen) and right host */ if (!((stream && (LEVELIMAP4rev1 (stream) || stream->halfopen) && mail_usable_network_stream (stream,mbx)) || (stream = tstream = mail_open (NIL,mbx,OP_HALFOPEN|OP_SILENT)))) return NIL; /* parse mailbox name */ mail_valid_net_parse (mbx,&mb); args[0] = &ambx;args[1] = NIL;/* set up first argument as mailbox */ ambx.type = ASTRING; ambx.text = (void *) mb.mailbox; if (LEVELIMAP4rev1 (stream)) {/* have STATUS command? */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -