• Patch: Elm ME+ 2.5 PLalpha51 -> Elm ME+ 2.5 PLalpha52 [3/7] (5/6)

    From Kari Hurtta@21:1/5 to All on Mon Jun 8 19:47:03 2020
    [continued from previous message]

    + goto done;
    +
    + } else if (0 == len) {
    + DPRINT(Debug,14, (&Debug,
    + "left_part_from_devurandom: Got EOF.\n"));
    + retry++;
    + close_devurandom();
    + } else {
    + goto done;
    + }
    +
    + }
    + break;
    +
    + case buffer_bad: {
    + int len;
    +
    + if (-1 == devurandom_fd &&
    + ! open_devurandom()) {
    + DPRINT(Debug,14, (&Debug,
    + "left_part_from_devurandom: devurandom is not open.\n"));
    +
    + goto done;
    + }
    +
    + len = read(devurandom_fd, devurandom_buffer, sizeof devurandom_buffer);
    +
    + if (len > 0) {
    + DPRINT(Debug,14, (&Debug,
    + "left_part_from_devurandom: Got %d bytes.\n",len));
    +
    + devurandom_len = len;
    + devurandom_used = buffer_initialized;
    + retry++;
    + } else if(-1 == len) {
    + int err UNUSED_VAROK = errno;
    +
    + DPRINT(Debug,14,(&Debug,
    + "left_part_from_devurandom: read %s (fd=%d): %s (errno=%d)\n",
    + DEVURANDOM,devurandom_fd,
    + strerror(err),err));
    + goto done;
    +
    + } else if (0 == len) {
    + DPRINT(Debug,14, (&Debug,
    + "left_part_from_devurandom: Got EOF.\n"));
    + retry++;
    + close_devurandom();
    + } else {
    + goto done;
    + }
    + }
    + break;
    + }
    +
    + if (retry > 10) {
    + DPRINT(Debug,14,(&Debug,
    + "left_part_from_devurandom: retry=%d -- failure\n",
    + retry));
    + break;
    + }
    +
    + } while (retry > last_retry && !left_part && msid_stat_none == *ret_p);
    +
    + done:
    + DPRINT(Debug,14, (&Debug,"left_part_from_devurandom="));
    + if (left_part) {
    + DPRINT(Debug,14, (&Debug,"%Q",left_part));
    + } else {
    + DPRINT(Debug,14, (&Debug,"NULL"));
    + }
    + DPRINT(Debug,14, (&Debug,"; *ret_p=%d",*ret_p));
    + switch (*ret_p) {
    + case msid_stat_need_hash: DPRINT(Debug,14, (&Debug," msid_stat_need_hash")); break;
    + case msid_stat_need_restart: DPRINT(Debug,14, (&Debug," msid_stat_need_restart")); break;
    + case msid_stat_none: DPRINT(Debug,14, (&Debug," msid_stat_none")); break;
    + case msid_stat_updated: DPRINT(Debug,14, (&Debug," msid_stat_updated")); break;
    + case msid_stat_no_changes: DPRINT(Debug,14, (&Debug," msid_stat_no_changes")); break;
    + }
    + DPRINT(Debug,14, (&Debug,"\n"));
    +
    + return left_part;
    + }
    +
    + /* Result is malloced */
    + static char * left_part_from_procuuid P_((enum message_id_status *ret_p));
    + static char * left_part_from_procuuid(ret_p)
    + enum message_id_status *ret_p;
    + {
    + char * left_part = NULL;
    + int retry = 0;
    + int last_retry;
    +
    + do {
    + last_retry = retry;
    +
    + DPRINT(Debug,14, (&Debug,"left_part_from_procuuid: procuuid_used=%d ",procuuid_used));
    + switch (procuuid_used) {
    + case buffer_bad: DPRINT(Debug,14, (&Debug," buffer_bad")); break;
    + case buffer_initialized: DPRINT(Debug,14, (&Debug," buffer_initialized procuuid len %d",
    + procuuid_len));
    + if (procuuid_len > 0) {
    + int len = procuuid_len;
    + if (len > sizeof procuuid_buffer)
    + len = sizeof procuuid_buffer;
    + /* Do not debug newline on end of buffer */
    + if (len > 0 && '\n' == procuuid_buffer[len-1])
    + len--;
    +
    + DPRINT(Debug,14, (&Debug," ["));
    + DEBUG_PRINT_BUFFER(Debug,14, len,procuuid_buffer);
    + DPRINT(Debug,14,(&Debug,"]"));
    + }
    + break;
    + case buffer_used: DPRINT(Debug,14, (&Debug," buffer_used")); break;
    + }
    + if (retry) {
    + DPRINT(Debug,14, (&Debug," retry=%d",retry));
    + }
    + DPRINT(Debug,14, (&Debug,"\n"));
    +
    + switch (procuuid_used) {
    + case buffer_initialized:
    +
    + /* Have data */
    + if (procuuid_len == sizeof procuuid_buffer) {
    + DPRINT(Debug,14,(&Debug,
    + "left_part_from_procuuid: have full %d characters on procuuid buffer\n",
    + procuuid_len));
    +
    + if (valid_procuuid(procuuid_buffer,procuuid_len)) {
    + int len = procuuid_len;
    +
    + /* Do not copy newline on end of buffer */
    + if (len > 0 && '\n' == procuuid_buffer[len-1])
    + len--;
    +
    + procuuid_used = buffer_used;
    + left_part = safe_malloc(len+1);
    + if (len)
    + memcpy(left_part,procuuid_buffer,len);
    + left_part[len] = '\0';
    + goto done;
    + } else {
    + DPRINT(Debug,14,(&Debug,
    + "left_part_from_procuuid: buffer not valid"));
    +
    + if (-1 != procuuid_fd ) {
    + DPRINT(Debug,14,(&Debug,", closing procuuid\n"));
    + close_procuuid();
    + } else {
    + DPRINT(Debug,14,(&Debug,"\n"));
    + }
    + procuuid_used = buffer_bad;
    + retry++;
    + }
    +
    + } else if (procuuid_len < sizeof procuuid_buffer) {
    + int need = (sizeof procuuid_buffer) - procuuid_len;
    + int len;
    +
    + DPRINT(Debug,14, (&Debug,
    + "left_part_from_procuuid: have %d characters on procuuid buffer, need %d characters more\n",
    + procuuid_len,need));
    +
    + if (-1 == procuuid_fd &&
    + ! open_procuuid()) {
    +
    + DPRINT(Debug,14,(&Debug,
    + "left_part_from_procuuid: procuuid is not open.\n"));
    + goto done;
    + }
    +
    + len = read(procuuid_fd,
    + procuuid_buffer+procuuid_len,
    + need);
    +
    + if (len > 0) {
    + DPRINT(Debug,14, (&Debug,
    + "left_part_from_procuuid: Got %d characters.\n",len));
    +
    + procuuid_len += len;
    + retry++;
    +
    + } else if (-1 == len) {
    + int err UNUSED_VAROK = errno;
    +
    + DPRINT(Debug,14,(&Debug,
    + "left_part_from_procuuid: read %s (fd=%d): %s (errno=%d)\n",
    + PROCUUID,procuuid_fd,strerror(err),err)); +
    + goto done;
    + } else if (0 == len) {
    + DPRINT(Debug,14,(&Debug,
    + "left_part_from_procuuid: Got EOF.\n"));
    + retry++;
    + close_procuuid();
    +
    + } else {
    + goto done;
    + }
    +
    + } else {
    + DPRINT(Debug,14,(&Debug,
    + "left_part_from_procuuid: have %d characters on procuuid buffer, but buffer is %zu bytes.",
    + procuuid_len,sizeof procuuid_buffer));
    + procuuid_used = buffer_bad;
    +
    + goto done;
    + }
    + break;
    +
    + case buffer_used: {
    + static unsigned char newuuid[PROCUUID_LEN];
    + int len;
    +
    + /* Buffer data is used, read new data and check that it differ
    + from used data */
    +
    + if (-1 == procuuid_fd &&
    + ! open_procuuid()) {
    +
    + DPRINT(Debug,14,(&Debug,
    + "left_part_from_procuuid: procuuid is not open.\n"));
    + goto done;
    + }
    +
    + len = read(procuuid_fd,newuuid, sizeof newuuid);
    +
    + if (len > 0) {
    + int i;
    + int differ = 0;
    +
    + DPRINT(Debug,14, (&Debug,
    + "left_part_from_procuuid: Got %d characters.\n",len));
    +
    + for (i = 0;
    + i < len && i < sizeof newuuid &&
    + i < procuuid_len && i < sizeof procuuid_buffer;
    + i++) {
    + if (newuuid[i] != procuuid_buffer[i])
    + differ++;
    + }
    +
    + if (differ) {
    + DPRINT(Debug,14, (&Debug,
    + "left_part_from_procuuid: %d characters differ from previous procuuid context\n",
    + differ));
    +
    + if (len < sizeof procuuid_buffer) {
    + memcpy(procuuid_buffer,newuuid,len);
    + procuuid_len = len;
    + } else {
    + memcpy(procuuid_buffer,newuuid,sizeof procuuid_buffer); + procuuid_len = sizeof procuuid_buffer;
    + }
    + procuuid_used = buffer_initialized;
    + retry++;
    +
    + } else {
    + DPRINT(Debug,14, (&Debug,
    + "left_part_from_procuuid: Context does not differ from preivious procuuid_buffer\n"));
    + goto done;
    + }
    + } else if (-1 == len) {
    + int err UNUSED_VAROK = errno;
    +
    + DPRINT(Debug,14,(&Debug,
    + "left_part_from_procuuid: read %s (fd=%d): %s (errno=%d)\n",
    + PROCUUID,procuuid_fd,strerror(err),err));
    +
    + goto done;
    + } else if (0 == len) {
    + DPRINT(Debug,14,(&Debug,
    + "left_part_from_procuuid: Got EOF (expected after read).\n"));
    + retry++;
    + close_procuuid();
    + } else {
    + goto done;
    + }
    +
    + }
    + break;
    +
    + case buffer_bad: {
    + int len;
    +
    + if (-1 == procuuid_fd &&
    + ! open_procuuid()) {
    +
    + DPRINT(Debug,14,(&Debug,
    + "left_part_from_procuuid: procuuid is not open.\n"));
    + goto done;
    + }
    +
    + len = read(procuuid_fd,procuuid_buffer, sizeof procuuid_buffer);
    +
    + if (len > 0) {
    + DPRINT(Debug,14, (&Debug,
    + "left_part_from_procuuid: Got %d characters.\n",len));
    +
    + procuuid_len = len;
    + procuuid_used = buffer_initialized;
    + retry++;
    + } else if (-1 == len) {
    + int err UNUSED_VAROK = errno;
    +
    + DPRINT(Debug,14,(&Debug,
    + "left_part_from_procuuid: read %s (fd=%d): %s (errno=%d)\n",
    + PROCUUID,procuuid_fd,strerror(err),err));
    +
    + goto done;
    + } else if (0 == len) {
    + DPRINT(Debug,14,(&Debug,
    + "left_part_from_procuuid: Got EOF (expected after read).\n"));
    + retry++;
    + close_procuuid();
    + } else {
    + goto done;
    + }
    + }
    + break;
    +
    +
    + }
    +
    + if (retry > 10) {
    + DPRINT(Debug,14,(&Debug,
    + "left_part_from_procuuid: retry=%d -- failure\n", + retry));
    + break;
    + }
    +
    + } while (retry > last_retry && !left_part && msid_stat_none == *ret_p);
    +
    + done:
    + DPRINT(Debug,14, (&Debug,"left_part_from_procuuid="));
    + if (left_part) {
    + DPRINT(Debug,14, (&Debug,"%Q",left_part));
    + } else {
    + DPRINT(Debug,14, (&Debug,"NULL"));
    + }
    + DPRINT(Debug,14, (&Debug,"; *ret_p=%d",*ret_p));
    + switch (*ret_p) {
    + case msid_stat_need_hash: DPRINT(Debug,14, (&Debug," msid_stat_need_hash")); break;
    + case msid_stat_need_restart: DPRINT(Debug,14, (&Debug," msid_stat_need_restart")); break;
    + case msid_stat_none: DPRINT(Debug,14, (&Debug," msid_stat_none")); break;
    + case msid_stat_updated: DPRINT(Debug,14, (&Debug," msid_stat_updated")); break;
    + case msid_stat_no_changes: DPRINT(Debug,14, (&Debug," msid_stat_no_changes")); break;
    + }
    + DPRINT(Debug,14, (&Debug,"\n"));
    +
    + return left_part;
    + }
    +
    + enum message_id_status update_message_id(msg_id_res,old_hash,current_hash,info,need_hash,
    + cancel_p)
    + struct message_id ** msg_id_res;
    + struct digest_proc * old_hash;
    + struct digest_proc * current_hash;
    + struct mailer_info * info;
    + const struct digest_proc_type ** need_hash;
    + struct cancel_data ** cancel_p; /* *cancel_p is set if DNS lookup is cancelable */
    + {
    + enum message_id_status ret = msid_stat_none;
    +
    + struct schedule_timelimit now = NO_schedule_timelimit;
    + struct schedule_timelimit default_valid_until = NO_schedule_timelimit;
    + char * A;
    +
    +
    + schedule_set_current_time(&now);
    + A = schedule_timeout_string(&now);
    + if (A) {
    + DPRINT(Debug,14,(&Debug,
    + "update_message_id: now %s\n",
    + A));
    + free(A); A = NULL;
    + }
    +
    + if (default_timeout_sec >= 0) {
    + DPRINT(Debug,14,(&Debug,
    + "update_message_id: default_timeout_sec=%d\n",
    + default_timeout_sec));
    +
    + if (! schedule_have_timelimit(&now)) {
    +
    + DPRINT(Debug,14,(&Debug,
    + "update_message_id: No time\n"));
    +
    + } else if (schedule_set_next_timeout0(&default_valid_until,&now,
    + default_timeout_sec,
    + /* Use time_MAX -1 on failure
    + May fail at Tue Jan 19 03:14:06 2038 */
    + se_use_before_time_MAX)) {
    + A = schedule_timeout_string(&default_valid_until);
    + if (A) {
    + DPRINT(Debug,14,(&Debug,
    + "update_message_id: default valid until %s\n", + A));
    + free(A); A = NULL;
    + }
    + }
    + }
    +
    + if (! message_id_set) {
    + configure_message_id();
    + }
    +
    + DPRINT(Debug,14,(&Debug,
    + "update_message_id: message_id_localspec=%d",
    + message_id_localspec));
    + switch (message_id_localspec) {
    + case msgidlocal_bad: DPRINT(Debug,14,(&Debug," msgidlocal_bad")); break;
    + case msgidlocal_none: DPRINT(Debug,14,(&Debug," msgidlocal_none")); break;
    + case msgidlocal_md5: DPRINT(Debug,14,(&Debug," msgidlocal_md5")); break;
    + case msgidlocal_devurandom: DPRINT(Debug,14,(&Debug," msgidlocal_devurandom")); break;
    + case msgidlocal_procuuid: DPRINT(Debug,14,(&Debug," msgidlocal_procuuid")); break;
    + case NUM_msgidlocal: DPRINT(Debug,14,(&Debug," NUM_msgidlocal")); break;
    + }
    + DPRINT(Debug,14,(&Debug,", message_id_domspec=%d",
    + message_id_domspec));
    + switch (message_id_domspec) {
    + case msgiddom_whitelisted: DPRINT(Debug,14,(&Debug," msgiddom_whitelisted")); break;
    + case msgiddom_literal: DPRINT(Debug,14,(&Debug," msgiddom_literal")); break;
    + case msgiddom_domain: DPRINT(Debug,14,(&Debug," msgiddom_domain")); break;
    + case msgiddom_bad: DPRINT(Debug,14,(&Debug," msgiddom_bad")); break;
    + case msgiddom_default: DPRINT(Debug,14,(&Debug," msgiddom_default")); break;
    + case msgiddom_hostfullname: DPRINT(Debug,14,(&Debug," msgiddom_hostfullname")); break;
    + case msgiddom_maildomain: DPRINT(Debug,14,(&Debug," msgiddom_maildomain")); break;
    + case NUM_msgiddom: DPRINT(Debug,14,(&Debug," NUM_msgiddom")); break;
    + }
    + DPRINT(Debug,14,(&Debug,"\n"));
    +
    + /* This is called if message-id is not check, or when hash changes
    + or mailer is reconnected (which may imply domain name change if
    + msgiddom_default is used
    + */
    +
    + if (* msg_id_res) {
    + const char * old_left_part = message_id_left(* msg_id_res);
    + const char * old_domain_part = message_id_domain(* msg_id_res);
    +
    + if (old_left_part && old_left_part[0]
    + &&
    + old_domain_part && old_domain_part[0]) {
    + int ourdom = 0;
    + int ourleft = 0;
    +
    + /* Check domain name ------------------------------ */
    +
    + switch (message_id_domspec) {
    + case msgiddom_whitelisted:
    + case msgiddom_literal:
    + case msgiddom_domain:
    + if (match_to_domain(dname_domain,old_domain_part))
    + ourdom = 1;
    + break;
    + case msgiddom_default:
    + if (match_to_domain(dname_hostfullname,old_domain_part))
    + ourdom = 1;
    + if (match_to_domain(dname_mailer,old_domain_part))
    + ourdom = 1;
    + if (match_to_domain(dname_maildomain,old_domain_part))
    + ourdom = 1;
    + break;
    + case msgiddom_hostfullname:
    + if (match_to_domain(dname_hostfullname,old_domain_part))
    + ourdom = 1;
    + break;
    + case msgiddom_maildomain:
    + if (match_to_domain(dname_hostfullname,old_domain_part))
    + ourdom = 1;
    + break;
    + case msgiddom_bad:
    + case NUM_msgiddom:
    + DPRINT(Debug,14,(&Debug,
    + "update_message_id: Message-id not generated here\n"));
    +
    + ret = msid_stat_no_changes;
    + goto nochange;
    + }
    +
    + if (fallback_domain) {
    + size_t i;
    +
    + for (i = 0; i < fallback_domain_count; i++) {
    + if (fallback_domain[i]) {
    +
    + if (DOMAIN_INFO_magic != fallback_domain[i]->magic)
    + panic("MAILER PANIC",__FILE__,__LINE__,
    + "update_message_id",
    + "Bad magic number (domain_info)",0);
    +
    + if (fallback_domain[i]->dompart &&
    + 0 == strcmp(fallback_domain[i]->dompart,
    + old_domain_part)) {
    +
    + DPRINT(Debug,14,(&Debug,
    + "update_message_id: old message-id domain %s matches to fallback domain\n",
    + old_domain_part));
    + ourdom = 1;
    + }
    + }
    + }
    + }
    +
    + /* Check local part --------------------------------- */
    +
    + switch (message_id_localspec) {
    +
    + case msgidlocal_md5:
    + if (old_hash) {
    + size_t old_hash_size = len_digest_proc(old_hash);
    + unsigned char * data = safe_malloc(old_hash_size);
    + size_t data_len = result_digest_proc(old_hash,data,old_hash_size);
    +
    + if (data_len) {
    + size_t x;
    + char * old_hash_left;
    +
    + DPRINT(Debug,14,(&Debug,
    + "update_message_id: old_hash len %zu [",
    + data_len));
    + for (x = 0; x < data_len; x++) {
    + DPRINT(Debug,14,(&Debug,"%02x",data[x]));
    + }
    + DPRINT(Debug,14,(&Debug,"]\n"));
    +
    + old_hash_left = octectvalue_to_left(data,data_len);
    + if (old_hash_left) {
    + DPRINT(Debug,14,(&Debug,
    + "update_message_id: left side from old hash is %s",
    + old_hash_left));
    +
    + if (0 == strcmp(old_left_part,old_hash_left)) {
    + DPRINT(Debug,14,(&Debug,
    + ", old message-id left side %s matches to old hash",
    + old_left_part));
    + ourleft = 1;
    + }
    + DPRINT(Debug,14,(&Debug,"\n"));
    +
    + free(old_hash_left);
    + }
    + }
    +
    + free(data);
    + } else {
    + DPRINT(Debug,14,(&Debug,
    + "update_message_id: old_hash not given\n"));
    +
    + }
    + break;
    +
    + case msgidlocal_devurandom:
    + if (devurandom_len > 0 && buffer_used == devurandom_used) {
    + int x;
    + char * old_urandom_left;
    +
    + DPRINT(Debug,14,(&Debug,
    + "update_message_id: devuramdom len %d [", + devurandom_len));
    +
    + for (x = 0; x < devurandom_len; x++) {
    + DPRINT(Debug,14,(&Debug,"%02x",devurandom_buffer[x]));
    + }
    + DPRINT(Debug,14,(&Debug,"]\n"));
    +
    + old_urandom_left = octectvalue_to_left(devurandom_buffer,devurandom_len);
    + if (old_urandom_left) {
    + DPRINT(Debug,14,(&Debug,
    + "update_message_id: left side from old devurandom is %s",
    + old_urandom_left));
    +
    + if (0 == strcmp(old_left_part,old_urandom_left)) {
    + DPRINT(Debug,14,(&Debug,
    + ", old message-id left side %s matches to old devurandom data",
    + old_left_part));
    + ourleft = 1;
    + }
    + DPRINT(Debug,14,(&Debug,"\n"));
    +
    + free(old_urandom_left);
    + }
    +
    + } else {
    + DPRINT(Debug,14,(&Debug,
    + "update_message_id: no used data on devurandom_buffer\n"));
    + }
    + break;
    +
    + case msgidlocal_procuuid:
    + if (procuuid_len > 0 && buffer_used == procuuid_used) {
    + int len = procuuid_len;
    +
    + /* Remove \n if still on buffer */
    + if ('\n' == procuuid_buffer[procuuid_len-1])
    + len = procuuid_len-1;
    +
    + DPRINT(Debug,14,(&Debug,
    + "update_message_id: procuuid len %d (without newline) [%.*s]",
    + len,len,procuuid_buffer));
    +
    + if (0 == strncmp(old_left_part,us2s(procuuid_buffer),len) &&
    + '\0' == old_left_part[len]) {
    + DPRINT(Debug,14,(&Debug,
    + ", old message-id left side %s matches to old procuid",
    + old_left_part));
    + ourleft = 1;
    + }
    + DPRINT(Debug,14,(&Debug,"\n"));
    +
    + } else {
    + DPRINT(Debug,14,(&Debug,
    + "update_message_id: no used data on procuuid_buffer\n"));
    + }
    + break;
    +
    + case msgidlocal_bad:
    + case msgidlocal_none:
    + case NUM_msgidlocal:
    + DPRINT(Debug,14,(&Debug,
    + "update_message_id: Message-id not generated here\n"));
    +
    + ret = msid_stat_no_changes;
    + goto nochange;
    + }
    +
    +
    + /* OK ----------------------------------------------- */
    +
    + if (!ourdom || !ourleft) {
    + DPRINT(Debug,14,(&Debug,
    + "update_message_id: not our"));
    +
    + if (!ourleft) {
    + DPRINT(Debug,14,(&Debug,", old message-id left side %s is not generated here",
    + old_left_part));
    + }
    +
    + if (!ourdom) {
    + DPRINT(Debug,14,(&Debug,", old message-id domain %s is not generated here",
    + old_domain_part));
    + }
    +
    + DPRINT(Debug,14,(&Debug,"\n"));
    +
    + ret = msid_stat_no_changes;
    + goto nochange;
    + }
    +
    + }
    + }
    +
    +
    + switch (message_id_localspec) {
    +
    + char * left_part;
    + char * domain_part;
    +
    + case msgidlocal_md5:
    + if (!current_hash) {
    + DPRINT(Debug,14, (&Debug, "update_message_id: hash needed\n"));
    + ret = msid_stat_need_hash;
    + if (need_hash) {
    + *need_hash = md5_available();
    + if (!*need_hash) {
    + DPRINT(Debug,14, (&Debug, "update_message_id: MD5 not available\n"));
    + }
    + }
    + goto nochange;
    + }
    +
    + if (0) {
    + case msgidlocal_devurandom:
    +
    + if (! local_devurandom_supported()) {
    + lib_error(CATGETS(elm_msg_cat, MeSet, MeMsgIDUnSupKw,
    + "Message-ID keyword %s unsupported."),
    + MSG_ID_localspec[message_id_localspec]);
    + message_id_localspec = msgidlocal_bad;
    + goto failure;
    + }
    +
    + }
    +
    + if (0) {
    + case msgidlocal_procuuid:
    + if (! local_procuuid_supported()) {
    + lib_error(CATGETS(elm_msg_cat, MeSet, MeMsgIDUnSupKw,
    + "Message-ID keyword %s unsupported."),
    + MSG_ID_localspec[message_id_localspec]);
    + message_id_localspec = msgidlocal_bad;
    + goto failure;
    + }
    + }
    +
    + left_part = NULL;
    + domain_part = NULL;
    +
    + switch (message_id_domspec) {
    + const char * dom;
    + char * tempdom;
    + int q;
    +
    + case msgiddom_domain:
    +
    + tempdom = get_msg_domain(dname_domain);
    + if (tempdom) {
    + DPRINT(Debug,14, (&Debug,
    + "update_message_id: domain part candinate %s\n",
    + tempdom));
    +
    + domain_part = check_msg_domain(dname_domain,tempdom,cancel_p,
    + &now,&default_valid_until);
    + if (domain_part) {
    + DPRINT(Debug,14, (&Debug,
    + "update_message_id: domain part %s succeed as %s\n",
    + tempdom,domain_part));
    +
    + free(tempdom); tempdom = NULL;
    + goto found_domain;
    + } else if (cancel_p && *cancel_p && is_canceled(*cancel_p)) {
    + DPRINT(Debug,7,(&Debug,
    + "update_message_id: %s: DNS lookup canceled\n",
    + tempdom));
    + free(tempdom); tempdom = NULL;
    + goto cleanup;
    + }
    +
    + free(tempdom); tempdom = NULL;
    +
    + }
    + break;
    +
    + case msgiddom_hostfullname:
    +
    + if (hostfullname[0]) {
    + DPRINT(Debug,14, (&Debug, "update_message_id: domain part candinate %s\n",
    + hostfullname));
    +
    + domain_part = check_msg_domain(dname_hostfullname,hostfullname,cancel_p,
    + &now,&default_valid_until);
    + if (domain_part) {
    + DPRINT(Debug,14, (&Debug,
    + "update_message_id: domain part %s succeed as %s\n",
    + hostfullname,domain_part));
    + goto found_domain;
    +
    + } else if (cancel_p && *cancel_p && is_canceled(*cancel_p)) {
    + DPRINT(Debug,7,(&Debug,
    + "update_message_id: %s: DNS lookup canceled\n",
    + hostfullname));
    + goto cleanup;
    + }
    + }
    + break;
    +
    + case msgiddom_maildomain:
    + dom = useful_mailname();
    + if (dom) {
    + DPRINT(Debug,14, (&Debug,
    + "update_message_id: domain part candinate %s\n",
    + dom));
    +
    + domain_part = check_msg_domain(dname_maildomain,dom,cancel_p,
    + &now,&default_valid_until);
    + if (domain_part) {
    + DPRINT(Debug,14, (&Debug, "update_message_id: domain part %s succeed as %s\n",
    + dom,domain_part));
    + goto found_domain;
    + } else if (cancel_p && *cancel_p && is_canceled(*cancel_p)) {
    + DPRINT(Debug,7,(&Debug,
    + "update_message_id: %s: DNS lookup canceled\n",
    + dom));
    + goto cleanup;
    + }
    + }
    + break;
    +
    + case msgiddom_default:
    +
    + /* 1) hostname */
    +
    + if (hostfullname[0]) {
    + DPRINT(Debug,14, (&Debug,
    + "update_message_id: domain part candinate %s\n",
    + hostfullname));
    +
    + domain_part = check_msg_domain(dname_hostfullname,hostfullname,cancel_p,
    + &now,&default_valid_until);
    + if (domain_part) {
    + DPRINT(Debug,14, (&Debug,
    + "update_message_id: domain part %s succeed as %s\n",
    + hostfullname,domain_part));
    + goto found_domain;
    +
    + } else if (cancel_p && *cancel_p && is_canceled(*cancel_p)) {
    + DPRINT(Debug,7,(&Debug, "update_message_id: %s: DNS lookup canceled\n",
    + hostfullname));
    + goto cleanup;
    + }
    + }
    +
    + /* 2) interface address from mailer */
    +
    + q = query_mailer_info(info,MI_REMOTE_MAILER);
    + DPRINT(Debug,14, (&Debug,
    + "update_message_id: MI_REMOTE_MAILER gives %d\n",q));
    + if (q) {
    + char * *domlist = NULL;
    + size_t domlist_len = 0;
    +
    +
    + /* Get name from local addess of connection */
    + domlist = query_s_mailer_info(&domlist_len,
    + info,MI_con_name_local,cancel_p); +
    + if (domlist) {
    + int ok = 0;
    + size_t x;
    +
    + DPRINT(Debug,14, (&Debug,
    + "update_message_id: Got %zu mailer addresses for MI_con_name_local\n",
    + domlist_len));
    +
    + tempdom = get_msg_domain(dname_mailer);
    +
    + if (tempdom) {
    + size_t i;
    +
    + DPRINT(Debug,14, (&Debug,
    + "update_message_id: Checking if cached %s is one of mailer local addresses",
    + tempdom));
    +
    + for (i = 0; i < domlist_len; i++) {
    + if (domlist[i]) {
    + if (0 == strcmp(domlist[i],tempdom)) {
    + DPRINT(Debug,14, (&Debug,"; found from index #%zu",
    + i));
    + ok = 1;
    + break;
    + }
    + }
    + }
    +
    + if (!ok) {
    + DPRINT(Debug,14, (&Debug,"; not found"));
    + }
    + DPRINT(Debug,14, (&Debug,"\n"));
    +
    + if (ok) {
    + DPRINT(Debug,14, (&Debug,
    + "update_message_id: domain part candinate %s from local address of mailer connection\n",
    + tempdom));
    +
    + domain_part = check_msg_domain(dname_mailer,tempdom,cancel_p,
    + &now,&default_valid_until);
    + if (domain_part) {
    + DPRINT(Debug,14, (&Debug,
    + "update_message_id: domain part %s succeed as %s\n",
    + tempdom,domain_part));
    +
    + free_domlist(&domlist,&domlist_len);
    + free(tempdom);
    +
    + goto found_domain;
    +
    + } else if (cancel_p && *cancel_p && is_canceled(*cancel_p)) {
    + DPRINT(Debug,7,(&Debug,
    + "update_message_id: %s: DNS lookup canceled\n",
    + tempdom));
    +
    + free_domlist(&domlist,&domlist_len);
    + free(tempdom); tempdom = NULL;
    +
    + goto cleanup;
    + }
    + }
    +
    + free(tempdom); tempdom = NULL;
    + }
    +
    + DPRINT(Debug,14, (&Debug,
    + "update_message_id: Checking mailer local addresses\n"));
    +
    + for (x = 0; x < domlist_len; x++) {
    + if (domlist[x]) {
    + DPRINT(Debug,14, (&Debug,
    + "update_message_id: domain part candinate %s from local address #%zu of mailer connection\n",
    + domlist[x],x));
    +
    +
    + domain_part = check_msg_domain(dname_mailer,domlist[x],cancel_p,
    + &now,&default_valid_until);
    + if (domain_part) {
    + DPRINT(Debug,14, (&Debug,
    + "update_message_id: domain part %s succeed as %s\n",
    + domlist[x],domain_part)); +
    + free_domlist(&domlist,&domlist_len);
    + goto found_domain;
    +
    + } else if (cancel_p && *cancel_p && is_canceled(*cancel_p)) {
    + DPRINT(Debug,7,(&Debug,
    + "update_message_id: %s: DNS lookup canceled\n",
    + domlist[x]));
    +
    + free_domlist(&domlist,&domlist_len);
    + goto cleanup;
    + }
    + }
    + }
    +
    + free_domlist(&domlist,&domlist_len);
    +
    + } else if (cancel_p && *cancel_p && is_canceled(*cancel_p)) {
    + DPRINT(Debug,7,(&Debug, "update_message_id: lookup canceled\n"));
    + goto cleanup;
    + }
    + }
    +
    + /* 3) maildomain */
    +
    + dom = useful_mailname();
    + if (dom) {
    + DPRINT(Debug,14, (&Debug,
    + "update_message_id: domain part candinate %s\n",
    + dom));
    +
    + domain_part = check_msg_domain(dname_maildomain,dom,cancel_p,
    + &now,&default_valid_until);
    + if (domain_part) {
    + DPRINT(Debug,14, (&Debug,
    + "update_message_id: domain part %s succeed as %s\n",
    + dom,domain_part));
    + goto found_domain;
    +
    + } else if (cancel_p && *cancel_p && is_canceled(*cancel_p)) {
    + DPRINT(Debug,7,(&Debug,
    + "update_message_id: %s: DNS lookup canceled\n",
    + dom));
    + goto cleanup;
    + }
    +
    + }
    + break;
    +
    + if (0) {
    + case msgiddom_whitelisted:
    + case msgiddom_literal:
    + domain_part = get_msg_domain(dname_domain);
    + if (domain_part) {
    + DPRINT(Debug,14, (&Debug, "update_message_id: domain part %s\n",
    + domain_part));
    +
    + /* No checks needed */
    + goto found_domain;
    + }
    + }
    +
    + case msgiddom_bad:
    + case NUM_msgiddom:
    + DPRINT(Debug,14, (&Debug, "update_message_id: Message-id domain not available\n"));
    +
    + goto cleanup;
    + }
    +
    + if (!domain_part && fallback_domain) {
    + size_t i;
    +
    + for (i = 0; i < fallback_domain_count && !domain_part; i++) {
    + if (fallback_domain[i]) {
    +
    + if (DOMAIN_INFO_magic != fallback_domain[i]->magic)
    + panic("MAILER PANIC",__FILE__,__LINE__,
    + "update_message_id",
    + "Bad magic number (domain_info)",0);
    +
    + if (fallback_domain[i]->dompart) {
    + DPRINT(Debug,14, (&Debug,
    + "update_message_id: domain part candinate %s (fallback)\n",
    + fallback_domain[i]->dompart));
    +
    +
    + domain_part = check_msg_domain0(fallback_domain[i],
    + fallback_domain[i]->dompart,
    + cancel_p,
    + &now,
    + &default_valid_until); + if (domain_part) {
    + DPRINT(Debug,14, (&Debug,
    + "update_message_id: domain part %s succeed as %s\n",
    + fallback_domain[i]->dompart,domain_part));
    + goto found_domain;
    + } else if (cancel_p && *cancel_p && is_canceled(*cancel_p)) {
    + DPRINT(Debug,7,(&Debug,
    + "update_message_id: %s: DNS lookup canceled\n",
    + fallback_domain[i]->dompart));
    + goto cleanup;
    + }
    + }
    + }
    + }
    + }
    +
    + found_domain:
    + if (domain_part) {
    +
    + switch (message_id_localspec) {
    + case msgidlocal_md5:
    + if (current_hash) {
    + size_t buffer_len = len_digest_proc(current_hash); + unsigned char * buffer = safe_zero_alloc(buffer_len);
    + size_t hash_len = result_digest_proc(current_hash,
    + buffer,buffer_len);
    +
    + if (hash_len) {
    + size_t x;
    +
    + DPRINT(Debug,14,(&Debug,
    + "update_message_id: hash len %zu [",
    + hash_len));
    +
    + for (x = 0; x < hash_len; x++) {
    + DPRINT(Debug,14,(&Debug,"%02x",buffer[x]));
    + }
    + DPRINT(Debug,14,(&Debug,"]\n"));
    +
    + left_part = octectvalue_to_left(buffer,hash_len);
    + }
    +
    + free(buffer); buffer = NULL;
    + } else {
    + DPRINT(Debug,14, (&Debug,
    + "update_message_id: NO hash\n"));
    + }
    + break;
    +
    + case msgidlocal_devurandom:
    +
    + left_part = left_part_from_devurandom(&ret);
    + break;
    +
    + case msgidlocal_procuuid:
    +
    + left_part = left_part_from_procuuid(&ret);
    + break;
    +
    + case msgidlocal_bad:
    + case msgidlocal_none:
    + case NUM_msgidlocal:
    + break;
    + }
    +
    + if (left_part) {
    + struct message_id * id = new_message_id(left_part,domain_part,NULL);
    +
    + DPRINT(Debug,14,(&Debug,
    + "update_message_id: left part %s\n",left_part));
    +
    + if (id) {
    +
    + if (* msg_id_res)
    + free_message_id(msg_id_res);
    +
    + * msg_id_res = id;
    + ret = msid_stat_updated;
    +
    + }
    + } else {
    + DPRINT(Debug,14, (&Debug,
    + "update_message_id: message-id left part is not available\n"));
    +
    + }
    +
    + } else {
    + DPRINT(Debug,14, (&Debug,
    + "update_message_id: message-id domain is not available\n"));
    + }
    +
    + cleanup:
    + if (left_part)
    + free(left_part);
    + if (domain_part)
    + free(domain_part);
    +
    +
    + if (msid_stat_none == ret) {
    + failure:
    + case NUM_msgidlocal:
    + case msgidlocal_bad:
    + case msgidlocal_none:
    + DPRINT(Debug,14, (&Debug, "update_message_id: Message-id not available\n"));
    +
    + if (* msg_id_res)
    + ret = msid_stat_no_changes;
    + }
    + break;
    + }
    +
    + nochange:
    +
    + DPRINT(Debug,14, (&Debug, "update_message_id=%d",ret));
    + switch (ret) {
    + case msid_stat_need_hash: DPRINT(Debug,14, (&Debug, " msid_stat_need_hash")); break;

    [continued in next message]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)