Comparing files a.a and DNEWSWEB.C
***** a.a
        , I_DUMP
        , I_LATEST_IP
};
***** DNEWSWEB.C
        , I_DUMP
};
*****

***** a.a
        ,"dump"
        ,"latest_ip"
        , NULL
***** DNEWSWEB.C
        ,"dump"
        , NULL
*****

***** a.a
static char ltemplate[BFSZ];
static char auth_username[BFSZ]="";
static int body_lines;
***** DNEWSWEB.C
static char ltemplate[BFSZ];
static int body_lines;
*****

***** a.a
        char bf[BFSZ];
        if (strlen(dom)>0) sprintf(bf,"%s %s",user,dom);
        else sprintf(bf,"%s",user); /* brian - get rid of the space at the end of a utag */
        if (ini_true(I_IGNORE_ADDRESS)) {
***** DNEWSWEB.C
        char bf[BFSZ];
        sprintf(bf,"%s %s",user,dom);
        if (ini_true(I_IGNORE_ADDRESS)) {
*****

***** a.a
            var_set("total",bf);
            strcpy(bf,tpl_groups);
            s = tpl_replace_vars(bf);
***** DNEWSWEB.C
            var_set("total",bf);
            ncpy(bf,tpl_groups,4000);
            s = tpl_replace_vars(bf);
*****

***** a.a
                var_set("total",bf);
                ncpy(bf,tpl_groups,4000);
                s = tpl_replace_vars(bf);
***** DNEWSWEB.C
                var_set("total",bf);
                strcpy(bf,tpl_groups);
                s = tpl_replace_vars(bf);
*****

***** a.a
int do_latest_authent(void) {
        char dom[BFSZ];
        char user[BFSZ];
        char pass[BFSZ];
        char fromip[BFSZ];
        char bf[BFSZ];

        if (strlen(auth_username)==0) return FALSE;
        ncpy(user,auth_username,BFSZ-10);

        ncpy(pass,ini_get(I_TELLNEWS_PASS),BFSZ-10);
        if (strlen(pass)==0) return FALSE;

        ncpy(dom,ini_get(I_NEWSHOST),BFSZ-10);
        ncpy(fromip,ini_get(I_LATEST_IP),BFSZ-10);
        if (strlen(fromip)>0) ncpy(dom,fromip,BFSZ-10);
        
        if (strlen(dom)==0) ncpy(dom,"(none)",BFSZ-10);
        imsg("do_latest_authent: Authenticating Domain (%s) User (%s) \n",dom,user);
        sprintf(bf,"xdauthent %s %s %s\015\012",dom,user,pass); nntp_write_s(chan,bf,strlen(bf)); 
        imsg("do_latest_authent: xdauthent %s %s %s\n",dom,user,pass); 
        return read_status(); 
}
***** DNEWSWEB.C
int group_readonly(char *group) {
    char bf[BFSZ];
    int ret=FALSE;
    sprintf(bf,"post\r\n"); nntp_write_s(chan,bf,strlen(bf)); 
    if (!read_status()) emsg("problem trying assess group postability\n");
    else {
        sprintf(bf,"Newsgroups: %s\r\n",group); nntp_write_s(chan,bf,strlen(bf));
        sprintf(bf,"From: can.i@post\r\n",group); nntp_write_s(chan,bf,strlen(bf));
        sprintf(bf,"Subject: testing postability\r\n.\r\n",group); nntp_write_s(chan,bf,strlen(bf));
        read_status();
        ret=(atoi(nntp_status)==480);
    }
    if (instr!=NULL) {
            str_free(instr); /*brian789*/
            instr=NULL;
    }
    return ret;
}
*****

***** a.a

int group_readonly(char *group) {
    char bf[BFSZ];
    int ret=FALSE;
    sprintf(bf,"post\r\n"); nntp_write_s(chan,bf,strlen(bf)); 
    if (!read_status()) emsg("problem trying assess group postability\n");
    else {
        sprintf(bf,"Newsgroups: %s\r\n",group); nntp_write_s(chan,bf,strlen(bf));
        sprintf(bf,"From: can.i@post\r\n",group); nntp_write_s(chan,bf,strlen(bf));
        sprintf(bf,"Subject: testing postability\r\n.\r\n",group); nntp_write_s(chan,bf,strlen(bf));
        read_status();
        ret=(atoi(nntp_status)==480);
    }
    if (instr!=NULL) {
            str_free(instr); /*brian789*/
            instr=NULL;
    }
    return ret;
}

void f_follow(int follow)
***** DNEWSWEB.C

void f_follow(int follow)
*****

***** a.a
    ncpy(group,query_find("group"),BFSZ-1);
    imsg("r_raw() group=%s item=%d \n",group,item);
    if (!group_allow(group)) return;
***** DNEWSWEB.C
    ncpy(group,query_find("group"),BFSZ-1);
    imsg("r_article() group=%s item=%d \n",group,item);
    if (!group_allow(group)) return;
*****

***** a.a
        set_id();
        do_content();
        tpl_show("login.tpl");
***** DNEWSWEB.C
        set_id();
        tpl_show("login.tpl");
*****

***** a.a
        ncpy(bf,s1,s2-s1+1);
        sprintf(bf2,"<a%s%s href=\"%s\">%s</a>",(strlen(ini_get(I_LINK_ADD))>0)?" ":"",ini_get(I_LINK_ADD),bf,bf);
        memmove(s1+strlen(bf2),s2+1,strlen(s2+1)+1);
***** DNEWSWEB.C
        ncpy(bf,s1,s2-s1+1);
        sprintf(bf2,"<a %s href=\"%s\">%s</a>",ini_get(I_LINK_ADD),bf,bf);
        memmove(s1+strlen(bf2),s2+1,strlen(s2+1)+1);
*****

***** a.a
}
char *decode_base64text(char *s) {
        static char bf[2000];
                char *c,*d;
                int n = decode_base64(s,bf);
                bf[n] = 0;
                /* cleverly go thru and turn \r\n into just \n for decoded text messages so
                that messages encoded with both don't stuff up the formatting when we display
                the text */
                for(c=d=bf;*c!=0;c++,d++) {
                        if (((c[0]=='\r')||(c[0]=='\n'))&&((c[1]=='\r')||(c[1]=='\n'))) {c++; *d='\n';}
                        else *d=(*c=='\r')?'\n':*c; 
                };
                *d=0;
        return bf;
};
/* quoted printable decoder - stolen from ralph, but it seems to work :-) */
char hexbyte(char *s)
{
        char bf[3];
        int x;
        strncpy(bf,s,2);
        bf[2] = 0;
        sscanf(bf,"%x",&x);
        return (char) x;
}

static char qeol[2]="\n";
char *decode_quote_eol(void){
        return qeol;
}

char *decode_quote(char *s){
        static char bf[2000];
***** DNEWSWEB.C
}
char *decode_quote(char *s)
{
        static char bf[2000];
*****

***** a.a
        int i;
        int truncated=FALSE;
        char *out=bf;
***** DNEWSWEB.C
        int i;
        char *out=bf;
*****

***** a.a
                        *out++ = *s;
                } else if (*s=='=') {
                        if (s[1]==0) { truncated=TRUE; continue;}
                        if (s[1]=='\n' || s[1]=='\r') { if (s[2]==0) truncated=TRUE; continue;}
                        *out++ = hexbyte(s+1);
                        s+=2;
                } else *out++ = *s;
        }
***** DNEWSWEB.C
                        *out++ = *s;
                } else if (strncmp(s,"=3D",3)==0) *out++ = '=';
                else if (*s=='=') *out++ = '\n';
                else *out++ = *s;
        }
*****

***** a.a
        *out++ = 0;
        if (truncated) qeol[0]=0; else qeol[0]='\n';
        return bf;
***** DNEWSWEB.C
        *out++ = 0;
        return bf;
*****

***** a.a
}
/* Chris's testing? quoted printable decoder - broken!
char *decode_quote(char *s)
{
        static char bf[2000];
        int i;
***** DNEWSWEB.C
}
char *wrap_encode(char *s);
char *text_encode(char *s)
{
        int noencode=FALSE;
        static char bf[2010];
        int i;
*****

***** a.a
        for (i=0; i<2000 && *s!=0;i++,s++) {
                if (*s<0) {
***** DNEWSWEB.C
        for (i=0; i<2000 && *s!=0;i++,s++) {
                if (noencode) {
                        if (*s==27) {
                                if (strncmp(s+1,"(B",2)==0) noencode = FALSE;
                        }
                        *out++ = *s;
                        continue;
                }
                if (*s<0) {
*****

***** a.a
                        *out++ = *s;
                } else if (strncmp(s,"=3D",3)==0) *out++ = '=';
                else if (*s=='=') *out++ = '\n';
                else *out++ = *s;
***** DNEWSWEB.C
                        *out++ = *s;
                } else if (*s=='<') { strcpy(out,"&lt;"); out += strlen(out); }
                else if (*s=='>') { strcpy(out,"&gt;"); out += strlen(out); }
                else if (*s=='&') { strcpy(out,"&amp;"); out += strlen(out); }
                else if (*s==27) {
                        if (strncmp(s+1,"$B",2)==0) noencode = TRUE;
                        *out++ = *s;
                }
                else *out++ = *s;
*****

***** a.a
        *out++ = 0;
        return bf;
}
*/

char *wrap_encode(char *s);
char *text_encode(char *s)
{
        int noencode=FALSE;
        static char bf[2010];
        int i;
***** DNEWSWEB.C
        *out++ = 0;
        return ref_encode(wrap_encode(bf));
}
char *wrap_encode(char *s)
{
        static char bf[4000];
        int i;
*****

***** a.a
        char *out=bf;
        for (i=0; i<2000 && *s!=0;i++,s++) {
                if (noencode) {
                        if (*s==27) {
                                if (strncmp(s+1,"(B",2)==0) noencode = FALSE;
                        }
                        *out++ = *s;
                        continue;
                }
                if (*s<0) {
                        *out++ = *s++;
                        *out++ = *s;
                } else if (*s=='<') { strcpy(out,"&lt;"); out += strlen(out); }
                else if (*s=='>') { strcpy(out,"&gt;"); out += strlen(out); }
                else if (*s=='&') { strcpy(out,"&amp;"); out += strlen(out); }
                else if (*s==27) {
                        if (strncmp(s+1,"$B",2)==0) noencode = TRUE;
                        *out++ = *s;
                }
                else *out++ = *s;
        }
***** DNEWSWEB.C
        char *out=bf;
        int len;
        int w = atoi(ini_get(I_WRAP_TEXT));
        if (w==0) return s;
        dmsg("Wrap text at %d\n",w);
        len = 0;
        for (i=0; (i<2000) && (*s!=0);i++,s++,len++) {
                if (*s=='\n') len = 0;
                if (*s=='\r') len = 0;
                if ((*s=='\n') || (s[1]==0)) if (ini_true(I_ADD_BR)) {
                        strcpy(out,"<br>"); out+= strlen(out);
                }
                if (len>w) {
                        if (xisspace(*s)) {
                                if (ini_true(I_ADD_BR)) {
                                        strcpy(out,"<br>"); out+= strlen(out);
                                }
                                *out++ = '\n';
                                len = 0;
                                continue;
                        }
                } 
                *out++ = *s;
        }
*****

***** a.a
        *out++ = 0;
        return ref_encode(wrap_encode(bf));
}
char *wrap_encode(char *s)
{
        static char bf[4000];
        int i;
        char *out=bf;
        int len;
        int w = atoi(ini_get(I_WRAP_TEXT));
        if (w==0) return s;
        dmsg("Wrap text at %d\n",w);
        len = 0;
        for (i=0; (i<2000) && (*s!=0);i++,s++,len++) {
                if (*s=='\n') len = 0;
                if (*s=='\r') len = 0;
                if ((*s=='\n') || (s[1]==0)) if (ini_true(I_ADD_BR)) {
                        strcpy(out,"<br>"); out+= strlen(out);
                }
                if (len>w) {
                        if (xisspace(*s)) {
                                if (ini_true(I_ADD_BR)) {
                                        strcpy(out,"<br>"); out+= strlen(out);
                                }
                                *out++ = '\n';
                                len = 0;
                                continue;
                        }
                } 
                *out++ = *s;
        }
        *out++ = 0;
        return bf;
***** DNEWSWEB.C
        *out++ = 0;
        return bf;
*****

***** a.a
          case T_NORM:
                if (strncmp(bf,"%%auth_username%%",17)==0) {
                        s = bf+17;
                        s2 = strstr(s,"%%");
                        if (s2==NULL) return bf;
                        ncpy(auth_username,s,s2-s);
                        return "";
                }
                else if (strncmp(bf,"%%body_lines%%",14)==0) {
                        s = bf+14;
***** DNEWSWEB.C
          case T_NORM:
                if (strncmp(bf,"%%body_lines%%",14)==0) {
                        s = bf+14;
*****

***** a.a
    if (!open_status()) {zmsg("tpl_show_latest1: News host not responding: %s",nntp_status); return;}
    if (strlen(auth_username)>0) {
        /* authenticate using the username defined in latest.tpl.
        e.g. %%auth_username%%fred%% issue xdauthent domain fred tellnews_pass
        */
        if (!do_latest_authent()) {
            zmsg("tpl_show_latest2: News host authentication failed: %s",nntp_status);
            return;
        }
    }
    if (items_per_group==0) items_per_group = 1;
***** DNEWSWEB.C
    if (!open_status()) {zmsg("tpl_show_latest1: News host not responding: %s",nntp_status); return;}
    /*if (!do_authent()) {zmsg("tpl_show_latest2: News host authentication failed: %s",nntp_status); return;}*/
    if (items_per_group==0) items_per_group = 1;
*****

***** a.a
            /* set variables involving group/item numbers */
            sprintf(temp,"%s?cmd=xover&group=%s&utag=%s",path_script,towww(groups[i].name),utage);
            var_set("group_ref",temp);
***** DNEWSWEB.C
            /* set variables involving group/item numbers */
            sprintf(temp,"%s?cmd=xover&group=%s",path_script,towww(groups[i].name));
            var_set("group_ref",temp);
*****

***** a.a
            var_set("item",value_encode(item4));
            sprintf(temp,"%s?cmd=article&group=%s&item=%s&utag=%s",path_script,towww(groups[i].name),value_encode(item4),utage)

            var_set("item_ref",temp);
***** DNEWSWEB.C
            var_set("item",value_encode(item4));
            sprintf(temp,"%s?cmd=article&group=%s&item=%s",path_script,towww(groups[i].name),value_encode(item4));
            var_set("item_ref",temp);
*****

***** a.a
                        if (strlen(mimeboundary)!=0) if (strstr(s,mimeboundary)!=NULL) goto skipit;                        
                        /* brian - removed rfc1522 encoding only applies in headers
                        if (ini_true(I_NON_ASCII)) printf("%s",rfc1522s(quote_encode(s)));
                        else*/
                        printf("%s\n",quote_encode(s));
skipit:                 s = get_line(instr);
***** DNEWSWEB.C
                        if (strlen(mimeboundary)!=0) if (strstr(s,mimeboundary)!=NULL) goto skipit;                        
                        if (ini_true(I_NON_ASCII)) printf("%s",rfc1522s(quote_encode(s)));
                        else printf("%s\n",quote_encode(s));
skipit:                 s = get_line(instr);
*****

***** a.a
        int israw = FALSE;
        char custom_href[BFSZ];
        char *t;
        int isbase64text=FALSE;
        
        /* get any cutomisation to put in the <a href's */
        ncpy(custom_href,"",0);
        if (strlen(ini_get(I_LINK_ADD))>0) {
            t=strchr(ini_get(I_LINK_ADD),'%');
            if (t==NULL) sprintf(custom_href," %.500s",ini_get(I_LINK_ADD));
            else emsg("tpl_show_item: dnewsweb.ini LINK_ADD setting invalid remove %%\n");
        }
        
        if (strstr(content_type(),"text")!=NULL) isbase64text=TRUE;

        if (b_item>=0) item = b_item;
***** DNEWSWEB.C
        int israw = FALSE;
        if (b_item>=0) item = b_item;
*****

***** a.a
        if (strlen(mime)>0) if (strlen(boundary)>0) multi = TRUE;
                
                if (!multi) if (strstr(encoding,"base64")!=NULL) {
                        /* not all that is base64 coded is an image! */
                        if (!isbase64text) {
                           printf("<img src=\"%s/%s?cmd=article&group=%s&item=%d&part=99&utag=%s\"><br>",path_script,attach_nam
,towww(group),item,utage);
                           goto endbit;
                        }
        }
***** DNEWSWEB.C
        if (strlen(mime)>0) if (strlen(boundary)>0) multi = TRUE;

        if (!multi) if (strstr(encoding,"base64")!=NULL) {
                printf("<img src=\"%s/%s?cmd=article&group=%s&item=%d&part=99&utag=%s\"><br>",path_script,attach_name,towww(gro
p),item,utage);
                goto endbit;
        }
*****

***** a.a
                                imsg("show attachment part=%d\n",got);
                                printf("<P><a%s href=\"%s/%s?cmd=article&group=%s&item=%d&part=%d&utag=%s&/%s\">%s</a><P>",cust
m_href,path_script,attach_name,towww(group),item,got,utage,attach_name,attach_name);
                        }
***** DNEWSWEB.C
                                imsg("show attachment part=%d\n",got);
                           printf("<P><a href=\"%s/%s?cmd=article&group=%s&item=%d&part=%d&utag=%s&/%s\">%s</a><P>",path_script
attach_name,towww(group),item,got,utage,attach_name,attach_name);
                        }
*****

***** a.a
finished_uu_munging:   /* brian */
                       if(!uucontent) if (istext) {  /*brian - was ishtml*/
                                if (isquoted) {
                                    /*imsg("DECODING quoted_printable data '%s'\n",s);*/
                                    printf("%s",decode_quote(s));
                                    /*imsg("DECODED quoted_printable data '%s'\n",decode_quote(s));*/
                                }
                                else if (isbase64) printf("%s",decode_base64s(s));
***** DNEWSWEB.C
finished_uu_munging:   /* brian */
                       if(!uucontent) if (ishtml) {
                                if (isquoted) printf("%s",decode_quote(s));
                                else if (isbase64) printf("%s",decode_base64s(s));
*****

***** a.a
        uucount = 0;
        isquoted = strstr(encoding,"quoted-printable")!=NULL;
        isbase64 = strstr(encoding,"base64")!=NULL;
munged_uuencoding: /* brian */
***** DNEWSWEB.C
        uucount = 0;
munged_uuencoding: /* brian */
*****

***** a.a
                          } else {
                                imsg("Looked like mime but wasn't %s\n",i_content);       
                          }
***** DNEWSWEB.C
                          } else {
                                imsg("LOoked like mime but wasn't %s\n",i_content);       
                          }
*****

***** a.a
                            else {
                                if (ini_true(I_NON_ASCII)) printf("<a%s href=\"%s/%s?uucount=%d&cmd=article&group=%s&item=%d&pa
t=%d&utag=%s&/%s\">%s</a><p>",custom_href,path_script,attach_name,uucount,towww(group),item,got,utage,attach_name,rfc1522s(atta
h_name));
                                else printf("<a%s href=\"%s/%s?uucount=%d&cmd=article&group=%s&item=%d&part=%d&utag=%s&/%s\">%s
/a><p>",custom_href,path_script,attach_name,uucount,towww(group),item,got,utage,attach_name,attach_name);
                            }
***** DNEWSWEB.C
                            else {
                                if (ini_true(I_NON_ASCII))
                                    printf("<a href=\"%s/%s?uucount=%d&cmd=article&group=%s&item=%d&part=%d&utag=%s&/%s\">%s</a
<p>",path_script,attach_name,uucount,towww(group),item,got,utage,attach_name,rfc1522s(attach_name));
                                else
                                    printf("<a href=\"%s/%s?uucount=%d&cmd=article&group=%s&item=%d&part=%d&utag=%s&/%s\">%s</a
<p>",path_script,attach_name,uucount,towww(group),item,got,utage,attach_name,attach_name);
                            }
*****

***** a.a
                            else {
                                if (ini_true(I_NON_ASCII)) printf("<a%s href=\"%s/%s?uucount=%d&cmd=article&group=%s&item=%d&pa
t=100&utag=%s&/%s\">%s</a><p>",custom_href,path_script,attach_name,uucount,towww(group),item,utage,attach_name,rfc1522s(attach_
ame));
                                else printf("<a%s href=\"%s/%s?uucount=%d&cmd=article&group=%s&item=%d&part=100&utag=%s&/%s\">%
</a><p>",custom_href,path_script,attach_name,uucount,towww(group),item,utage,attach_name,attach_name);
                            }
***** DNEWSWEB.C
                            else {
                                if (ini_true(I_NON_ASCII))
                                    printf("<a href=\"%s/%s?uucount=%d&cmd=article&group=%s&item=%d&part=100&utag=%s&/%s\">%s</
><p>",path_script,attach_name,uucount,towww(group),item,utage,attach_name,rfc1522s(attach_name));
                                else
                                    printf("<a href=\"%s/%s?uucount=%d&cmd=article&group=%s&item=%d&part=100&utag=%s&/%s\">%s</
><p>",path_script,attach_name,uucount,towww(group),item,utage,attach_name,attach_name);
                            }
*****

***** a.a
                if (!israw) {
                    if (!isimage) if (!isref)
                        if (*ini_get(I_KEEP_FORMATING) == 't') {
                            if (isquoted) JLLformat_wrap_output(JLLtext_encode, decode_quote(s), atoi(ini_get(I_WRAP_TEXT)));
                            else JLLformat_wrap_output(JLLtext_encode, s, atoi(ini_get(I_WRAP_TEXT)));
                        }
                        else {
                            if (isquoted) show_text(decode_quote(s));
                            else if (isbase64) {
                                        if (isbase64text)
                                            printf("%s",text_encode(decode_base64text(s)));
                                        else
                                            printf("%s",text_encode(decode_base64s(s)));
                                }
                                else show_text(s);
                        }
                } else {
***** DNEWSWEB.C
                if (!israw) {
                        if (!isimage) if (!isref) 
                                if (*ini_get(I_KEEP_FORMATING) == 't')
                                        JLLformat_wrap_output(JLLtext_encode, s, atoi(ini_get(I_WRAP_TEXT)));
                                else
                                        show_text(s);
                } else {
*****

