/* Write RFC822 address with 1522 decoding of personal name * and optional quoting. * * The idea is that there are some places where we'd just like to display * the personal name as is before applying confusing quoting. However, * we do want to be careful not to break things that should be quoted so * we'll only use this where we are sure. Quoting may look ugly but it * doesn't usually break anything. */ void rfc822_write_address_decode(char *dest, size_t destlen, struct mail_address *adr, int do_quote) { RFC822BUFFER buf; extern const char *rspecials; ADDRESS *copy, *a; /* * We want to print the adr list after decoding it. C-client knows * how to parse and print, so we want to use that. But c-client * doesn't decode. So we make a copy of the address list, decode * things there, and let c-client print that. */ copy = copyaddrlist(adr); for(a = copy; a; a = a->next){ if(a->host){ /* ordinary address? */ if(a->personal && *a->personal){ unsigned char *p; p = rfc1522_decode_to_utf8((unsigned char *) tmp_20k_buf, SIZEOF_20KBUF, a->personal); if(p && (char *) p != a->personal){ fs_give((void **) &a->personal); a->personal = cpystr((char *) p); } } } else if(a->mailbox && *a->mailbox){ /* start of group? */ unsigned char *p; p = rfc1522_decode_to_utf8((unsigned char *) tmp_20k_buf, SIZEOF_20KBUF, a->mailbox); if(p && (char *) p != a->mailbox){ fs_give((void **) &a->mailbox); a->mailbox = cpystr((char *) p); } } } buf.end = (buf.beg = buf.cur = dest) + destlen; buf.f = rfc822_dummy_soutr; *buf.cur = '\0'; buf.s = NIL; (void) rfc822_output_address_list(&buf, copy, 0, do_quote ? rspecials : rspecials_minus_quote_and_dot); *buf.cur = '\0'; if(copy) mail_free_address(©); }
/* * 1522 decode the personal name portion of addr and return an allocated * copy of the resulting address string. */ char * decode_fullname_of_addrstring(char *addr, int verbose) { char *pers_decoded, *tmp_a_string, *ret = NULL; ADDRESS *adr; static char *fakedomain = "@"; RFC822BUFFER rbuf; size_t len; tmp_a_string = cpystr(addr ? addr : ""); adr = NULL; rfc822_parse_adrlist(&adr, tmp_a_string, fakedomain); fs_give((void **)&tmp_a_string); if(!adr) return(cpystr("")); if(adr->personal && adr->personal[0]){ pers_decoded = cpystr((char *)rfc1522_decode_to_utf8((unsigned char *)tmp_20k_buf, SIZEOF_20KBUF, adr->personal)); fs_give((void **)&adr->personal); adr->personal = pers_decoded; } len = est_size(adr); ret = (char *) fs_get(len * sizeof(char)); ret[0] = '\0'; rbuf.f = dummy_soutr; rbuf.s = NULL; rbuf.beg = ret; rbuf.cur = ret; rbuf.end = ret+len-1; rfc822_output_address_list(&rbuf, adr, 0L, NULL); *rbuf.cur = '\0'; mail_free_address(&adr); return(ret); }
/* * This function does white pages lookups. * * Args string -- the string to use in the lookup * * Returns NULL -- lookup failed * Address -- A single address is returned if lookup was successfull. */ ADDRESS * wp_lookups(char *string, WP_ERR_S *wp_err, int recursing) { ADDRESS *ret_a = NULL; char ebuf[200]; #ifdef ENABLE_LDAP LDAP_SERV_RES_S *free_when_done = NULL; LDAPLookupStyle style; LDAP_CHOOSE_S *winning_e = NULL; LDAP_SERV_S *info = NULL; static char *fakedomain = "@"; char *tmp_a_string; int auwe_rv = 0; /* * Runtime ldap lookup of addrbook entry. */ if(!strncmp(string, RUN_LDAP, LEN_RL)){ LDAP_SERV_RES_S *head_of_result_list; info = break_up_ldap_server(string+LEN_RL); head_of_result_list = ldap_lookup(info, "", NULL, wp_err, 1); if(head_of_result_list){ if(!wp_exit) auwe_rv = ask_user_which_entry(head_of_result_list, string, &winning_e, wp_err, wp_err->wp_err_occurred ? DisplayIfOne : DisplayIfTwo); if(auwe_rv != -5) free_when_done = head_of_result_list; } else{ wp_err->wp_err_occurred = 1; if(wp_err->error){ q_status_message(SM_ORDER, 3, 5, wp_err->error); display_message('x'); fs_give((void **)&wp_err->error); } /* try using backup email address */ if(info && info->mail && *info->mail){ tmp_a_string = cpystr(info->mail); rfc822_parse_adrlist(&ret_a, tmp_a_string, fakedomain); fs_give((void **)&tmp_a_string); wp_err->error = cpystr(_("Directory lookup failed, using backup email address")); } else{ /* * Do this so the awful LDAP: ... string won't show up * in the composer. This shouldn't actually happen in * real life, so we're not too concerned about it. If we * were we'd want to recover the nickname we started with * somehow, or something like that. */ ret_a = mail_newaddr(); ret_a->mailbox = cpystr("missing-username"); wp_err->error = cpystr(_("Directory lookup failed, no backup email address available")); } q_status_message(SM_ORDER, 3, 5, wp_err->error); display_message('x'); } } else{ style = F_ON(F_COMPOSE_REJECTS_UNQUAL, ps_global) ? DisplayIfOne : DisplayIfTwo; auwe_rv = ldap_lookup_all(string, as.n_serv, recursing, style, NULL, &winning_e, wp_err, &free_when_done); } if(winning_e && auwe_rv != -5){ ret_a = address_from_ldap(winning_e); if(pith_opt_save_ldap_entry && ret_a && F_ON(F_ADD_LDAP_TO_ABOOK, ps_global) && !info) (*pith_opt_save_ldap_entry)(ps_global, winning_e, 1); fs_give((void **)&winning_e); } /* Info's only set in the RUN_LDAP case */ if(info){ if(ret_a && ret_a->host){ ADDRESS *backup = NULL; if(info->mail && *info->mail) rfc822_parse_adrlist(&backup, info->mail, fakedomain); if(!backup || !address_is_same(ret_a, backup)){ if(wp_err->error){ q_status_message(SM_ORDER, 3, 5, wp_err->error); display_message('x'); fs_give((void **)&wp_err->error); } snprintf(ebuf, sizeof(ebuf), _("Warning: current address different from saved address (%s)"), info->mail); wp_err->error = cpystr(ebuf); q_status_message(SM_ORDER, 3, 5, wp_err->error); display_message('x'); } if(backup) mail_free_address(&backup); } free_ldap_server_info(&info); } if(free_when_done) free_ldap_result_list(&free_when_done); #endif /* ENABLE_LDAP */ if(ret_a){ if(ret_a->mailbox){ /* indicates there was a MAIL attribute */ if(!ret_a->host || !ret_a->host[0]){ if(ret_a->host) fs_give((void **)&ret_a->host); ret_a->host = cpystr("missing-hostname"); wp_err->wp_err_occurred = 1; if(wp_err->error) fs_give((void **)&wp_err->error); wp_err->error = cpystr(_("Missing hostname in LDAP address")); q_status_message(SM_ORDER, 3, 5, wp_err->error); display_message('x'); } if(!ret_a->mailbox[0]){ if(ret_a->mailbox) fs_give((void **)&ret_a->mailbox); ret_a->mailbox = cpystr("missing-username"); wp_err->wp_err_occurred = 1; if(wp_err->error) fs_give((void **)&wp_err->error); wp_err->error = cpystr(_("Missing username in LDAP address")); q_status_message(SM_ORDER, 3, 5, wp_err->error); display_message('x'); } } else{ wp_err->wp_err_occurred = 1; if(wp_err->error) fs_give((void **)&wp_err->error); snprintf(ebuf, sizeof(ebuf), _("No email address available for \"%s\""), (ret_a->personal && *ret_a->personal) ? ret_a->personal : "selected entry"); wp_err->error = cpystr(ebuf); q_status_message(SM_ORDER, 3, 5, wp_err->error); display_message('x'); mail_free_address(&ret_a); ret_a = NULL; } } return(ret_a); }