diff options
Diffstat (limited to 'pith/reply.c')
-rw-r--r-- | pith/reply.c | 277 |
1 files changed, 264 insertions, 13 deletions
diff --git a/pith/reply.c b/pith/reply.c index 636afa4..666d3e1 100644 --- a/pith/reply.c +++ b/pith/reply.c @@ -47,6 +47,8 @@ static char rcsid[] = "$Id: reply.c 1074 2008-06-04 00:08:43Z hubert@u.washingto #include "../pith/mailcmd.h" #include "../pith/margin.h" #include "../pith/smime.h" +#include "../pith/copyaddr.h" +#include "../pith/rules.h" /* @@ -864,8 +866,27 @@ char * reply_quote_str(ENVELOPE *env) { char *prefix, *repl, *p, buf[MAX_PREFIX+1], pbf[MAX_SUBSTITUTION+1]; + char reply_string[MAX_PREFIX+1]; + + { RULE_RESULT *rule; + rule = get_result_rule(V_REPLY_INDENT_RULES, FOR_COMPOSE , env); + if (rule){ + strncpy(reply_string,rule->result,sizeof(reply_string)); + reply_string[sizeof(reply_string)-1] = '\0'; + if (rule->result) + fs_give((void **)&rule->result); + fs_give((void **)&rule); + } + else + if ((ps_global->VAR_REPLY_STRING) && (ps_global->VAR_REPLY_STRING[0])){ + strncpy(reply_string,ps_global->VAR_REPLY_STRING, sizeof(reply_string)-1); + reply_string[sizeof(reply_string)-1] = '\0'; + } + else + strncpy(reply_string,"> ",sizeof("> ")); + } - strncpy(buf, ps_global->VAR_REPLY_STRING, sizeof(buf)-1); + strncpy(buf, reply_string, sizeof(buf)-1); buf[sizeof(buf)-1] = '\0'; /* set up the prefix to quote included text */ @@ -917,10 +938,29 @@ reply_quote_str(ENVELOPE *env) int reply_quote_str_contains_tokens(void) { - return(ps_global->VAR_REPLY_STRING && ps_global->VAR_REPLY_STRING[0] && - (strstr(ps_global->VAR_REPLY_STRING, from_token) || - strstr(ps_global->VAR_REPLY_STRING, nick_token) || - strstr(ps_global->VAR_REPLY_STRING, init_token))); + char *reply_string; + + reply_string = (char *) malloc( 80*sizeof(char)); + { RULE_RESULT *rule; + rule = get_result_rule(V_REPLY_INDENT_RULES, FOR_COMPOSE, NULL); + if (rule){ + reply_string = cpystr(rule->result); + if (rule->result) + fs_give((void **)&rule->result); + fs_give((void **)&rule); + } + else + if ((ps_global->VAR_REPLY_STRING) && (ps_global->VAR_REPLY_STRING[0])){ + strncpy(reply_string,ps_global->VAR_REPLY_STRING, sizeof(reply_string)-1); + reply_string[sizeof(reply_string)-1] = '\0'; + } + else + reply_string = cpystr("> "); + } + return(reply_string && reply_string[0] && + (strstr(reply_string, from_token) || + strstr(reply_string, nick_token) || + strstr(reply_string, init_token))); } @@ -1486,6 +1526,10 @@ get_addr_data(ENVELOPE *env, IndexColType type, char *buf, size_t maxlen) buf[0] = '\0'; switch(type){ + case iFfrom: + addr = env && env->sparep ? env->sparep : NULL; + break; + case iFrom: addr = env ? env->from : NULL; break; @@ -1898,21 +1942,193 @@ get_reply_data(ENVELOPE *env, ACTION_S *role, IndexColType type, char *buf, size break; + case iProcid: + if(ps_global->procid){ + strncpy(buf, ps_global->procid, maxlen); + buf[maxlen] = '\0'; + } + break; + + case iRole: + if (ps_global->role){ + strncpy(buf, ps_global->role, maxlen); + buf[maxlen] = '\0'; + } + break; + + case iRoleNick: + if(role && role->nick){ + strncpy(buf, role->nick, maxlen); + buf[maxlen] = '\0'; + } + break; + + case iPkey: + if(ps_global->pressed_key){ + strcpy(buf, ps_global->pressed_key); + buf[maxlen] = '\0'; + } + break; + + case iScreen: + if(ps_global->screen_name){ + strncpy(buf, ps_global->screen_name, maxlen); + buf[maxlen] = '\0'; + } + break; + + case iFfrom: case iFrom: case iTo: case iCc: case iSender: case iRecips: case iInit: + if (env) get_addr_data(env, type, buf, maxlen); break; - case iRoleNick: - if(role && role->nick){ - strncpy(buf, role->nick, maxlen); - buf[maxlen] = '\0'; + case iFolder: + if(ps_global->cur_folder){ + strncpy(buf,ps_global->cur_folder, maxlen); + buf[maxlen] = '\0'; + } + break; + + case iCollection: + if(ps_global->context_current->nickname){ + strncpy(buf,ps_global->context_current->nickname, maxlen); + buf[maxlen] = '\0'; + } + break; + + case iFlag: + {MAILSTREAM *stream = ps_global->mail_stream; + MSGNO_S *msgmap = NULL; + long msgno; + MESSAGECACHE *mc; + strncpy(buf, "_FLAG_", maxlen); /* default value */ + if (stream){ + msgmap = sp_msgmap(stream); + msgno = mn_m2raw(msgmap, rules_cursor_pos(stream)); + if (msgno > 0L) mc = stream ? mail_elt(stream, msgno) : NULL; + if (mc) + sprintf(buf,"%s%s%s%s",mc->flagged ? "*" : "", + mc->recent ? (mc->seen ? "R" : "N") : (mc->seen) ? "R" : "U", + mc->answered ? "A" : "", + mc->deleted ? "D" : "" ); + } + buf[maxlen] = '\0'; + } + break; + + case iAltAddress: + if(ps_global->VAR_ALT_ADDRS != NULL + && ps_global->VAR_ALT_ADDRS[0] != NULL){ + size_t len; + int i, j; + + for(i = 0, len = 0; len < maxlen && ps_global->VAR_ALT_ADDRS[i]; i++){ + for(j = 0; len < maxlen && ps_global->VAR_ALT_ADDRS[i][j] != '\0'; j++){ + if(ps_global->VAR_ALT_ADDRS[i][j] == ';') + buf[len++] = '\\'; + buf[len++] = ps_global->VAR_ALT_ADDRS[i][j]; + } + if(len < maxlen){ + if(ps_global->VAR_ALT_ADDRS[i+1] != NULL) + buf[len++] = ';'; + else + buf[len++] = '\0'; + } + } + buf[maxlen] = '\0'; } break; + + case iNick: + case iFccFrom: + case iFccSender: + if (env){ + ADDRESS *tmp_adr; + + switch(type){ + case iNick: + tmp_adr = env->from ? copyaddr(env->from) + : env->sender ? copyaddr(env->sender) : NULL; + break; + case iFccFrom: + tmp_adr = env->from ? copyaddr(env->from) : NULL; + break; + case iFccSender: + tmp_adr = env->sender ? copyaddr(env->sender) : NULL; + break; + default: alpine_panic("Unhandled Rules case (01)"); + } + if(type == iNick) + get_nickname_from_addr(tmp_adr, buf, maxlen); + else + get_fcc_from_addr(tmp_adr, buf, maxlen); + mail_free_address(&tmp_adr); + } + break; + + case iAddressSender: + case iAddressCc: + case iAddressRecip: + case iAddressTo: + case iFadd: + { + int plen = 0; /* partial length */ + ADDRESS *sparep2 = (type == iAddressTo || type == iAddressRecip) + ? ((env && env->to) + ? copyaddrlist(env->to) + : NULL) + : (type == iAddressCc) + ? ((env && env->cc) + ? copyaddrlist(env->cc) + : NULL) + : (type == iAddressSender) + ? ((env && env->sender) + ? copyaddr(env->sender) + : NULL) + : ((env && env->sparep) + ? copyaddr((ADDRESS *)env->sparep) + : NULL); + ADDRESS *sparep; + + if (type == iAddressRecip){ + ADDRESS *last_to = NULL; + + for(last_to = sparep2;last_to && last_to->next; last_to= last_to->next); + + /* Make the end of To list point to cc list */ + if(last_to) + last_to->next = (env && env->cc ? copyaddrlist(env->cc) : NULL); + + } + sparep = sparep2; + for(; sparep ; sparep = sparep->next) + if(sparep && sparep->mailbox && sparep->mailbox[0] && + (plen ? plen + 1 : plen) + strlen(sparep->mailbox) <= maxlen){ + if (plen == 0) + strcpy(buf, sparep->mailbox); + else{ + strcat(buf, " "); + strcat(buf, sparep->mailbox); + } + if(sparep->host && + sparep->host[0] && + sparep->host[0] != '.' && + strlen(buf) + strlen(sparep->host) + 1 <= maxlen){ + strcat(buf, "@"); + strcat(buf, sparep->host); + } + plen = strlen(buf); + } + mail_free_address(&sparep2); + } + + break; case iNewLine: if(maxlen >= strlen(NEWLINE)){ @@ -1941,6 +2157,11 @@ get_reply_data(ENVELOPE *env, ACTION_S *role, IndexColType type, char *buf, size break; + case iLcc: /* fake it, there are not enough spare pointers */ + if (env && env->date) + sprintf(buf,"%s",env->date); + break; + case iNews: case iCurNews: get_news_data(env, type, buf, maxlen); @@ -1990,6 +2211,14 @@ get_reply_data(ENVELOPE *env, ACTION_S *role, IndexColType type, char *buf, size break; + case iOpeningText: + case iOpeningTextNQ: + if(env && env->sparep){ + strncpy(buf, ((SPAREP_S *)env->sparep)->value, maxlen); + buf[maxlen] = '\0'; + } + break; + case iSubject: case iShortSubject: if(env && env->subject){ @@ -2052,7 +2281,18 @@ reply_delimiter(ENVELOPE *env, ACTION_S *role, gf_io_t pc) if(!env) return; - strncpy(buf, ps_global->VAR_REPLY_INTRO, MAX_DELIM); + { RULE_RESULT *rule; + rule = get_result_rule(V_REPLY_LEADIN_RULES, FOR_REPLY_INTRO, env); + if(rule){ + strncpy(buf, rule->result, MAX_DELIM); + if (rule->result) + fs_give((void **)&rule->result); + fs_give((void **)&rule); + } + else + strncpy(buf, ps_global->VAR_REPLY_INTRO, MAX_DELIM); + } + buf[MAX_DELIM] = '\0'; /* preserve exact default behavior from before */ if(!strcmp(buf, DEFAULT_REPLY_INTRO)){ @@ -2311,6 +2551,7 @@ forward_subject(ENVELOPE *env, int flags) { size_t l; char *p, buftmp[MAILTMPLEN]; + RULE_RESULT *rule; if(!env) return(NULL); @@ -2318,9 +2559,19 @@ forward_subject(ENVELOPE *env, int flags) dprint((9, "checking subject: \"%s\"\n", env->subject ? env->subject : "NULL")); - if(env->subject && env->subject[0]){ /* add (fwd)? */ - snprintf(buftmp, sizeof(buftmp), "%s", env->subject); - buftmp[sizeof(buftmp)-1] = '\0'; + buftmp[0] = '\0'; + ps_global->procid = cpystr("fwd-subject"); + if (rule = get_result_rule(V_FORWARD_RULES,FOR_COMPOSE, env)){ + snprintf(buftmp, sizeof(buftmp), "%s", rule->result); + fs_give((void **)&rule->result); + fs_give((void **)&rule); + } + else if(env->subject) + snprintf(buftmp, sizeof(buftmp), "%s", env->subject); + buftmp[sizeof(buftmp)-1] = '\0'; + fs_give((void **)&ps_global->procid); + + if(buftmp[0]){ /* add (fwd)? */ /* decode any 8bit (copy to the temp buffer if decoding doesn't) */ if(rfc1522_decode_to_utf8((unsigned char *) tmp_20k_buf, SIZEOF_20KBUF, buftmp) == (unsigned char *) buftmp) |