Skip to content
Snippets Groups Projects
Commit d40fa37f authored by rswindell's avatar rswindell
Browse files

Support QWKE "To:" and "Subject:" kludge lines in QWK/REP-imported

email/netmail messages. Does *not* support the "From:" kludge.
I know this function needs need to be completely replaced and it's silly to
have QWK kludge parsing logic in multiple places, but ugh, I didn't want to
rewrite this just yet.
parent 26f76fe7
No related branches found
No related tags found
No related merge requests found
......@@ -372,6 +372,7 @@ void sbbs_t::qwktonetmail(FILE *rep, char *block, char *into, uchar fromhub)
char *qwkbuf,to[129],name[129],sender[129],senderaddr[129]
,str[256],*p,*cp,*addr,fulladdr[129],ch;
char* sender_id = fromhub ? cfg.qhub[fromhub-1]->id : useron.alias;
char* subject = NULL;
char tmp[512];
int i,fido,inet=0,qnet=0;
uint16_t net;
......@@ -394,26 +395,59 @@ void sbbs_t::qwktonetmail(FILE *rep, char *block, char *into, uchar fromhub)
fulladdr[0]=0;
sprintf(str,"%.6s",block+116);
n=atol(str); /* i = number of 128 byte records */
n=atol(str); /* number of 128 byte records */
if(n<2L || n>999999L) {
errormsg(WHERE,ERR_CHK,"QWK blocks",n);
return;
}
if((qwkbuf=(char *)malloc(n*QWK_BLOCK_LEN))==NULL) {
// Allocate/zero an extra block of NULs for strchr() usage and other ASCIIZ goodness
if((qwkbuf=(char *)calloc(n + 1, QWK_BLOCK_LEN))==NULL) {
errormsg(WHERE,ERR_ALLOC,nulstr,n*QWK_BLOCK_LEN);
return;
}
memcpy((char *)qwkbuf,block,QWK_BLOCK_LEN);
fread(qwkbuf+QWK_BLOCK_LEN,n-1,QWK_BLOCK_LEN,rep);
if(into==NULL)
sprintf(to,"%-128.128s",(char *)qwkbuf+QWK_BLOCK_LEN); /* To user on first line */
size_t kludge_hdrlen = 0;
char* beg = qwkbuf + QWK_BLOCK_LEN;
char* end = qwkbuf + (n * QWK_BLOCK_LEN);
p = beg;
if(into==NULL) {
SAFECOPY(to, p); /* To user on first line */
char* tp = strchr(to, QWK_NEWLINE); /* chop off at first CR */
if(tp != NULL)
*tp = 0;
p += strlen(to) + 1;
}
else
SAFECOPY(to,into);
p=strchr(to,QWK_NEWLINE); /* chop off at first CR */
if(p) *p=0;
SAFECOPY(to, into);
// Parse QWKE Kludge Lines here:
while(p < end && *p != QWK_NEWLINE) {
if(strncmp(p, "To:", 3) == 0) {
p += 3;
SKIP_WHITESPACE(p);
char* tp = strchr(p, QWK_NEWLINE); /* chop off at first CR */
if(tp != NULL)
*tp = 0;
SAFECOPY(to, p);
p += strlen(p) + 1;
continue;
}
if(strncmp(p, "Subject:", 8) == 0) {
p += 8;
SKIP_WHITESPACE(p);
char* tp = strchr(p, QWK_NEWLINE); /* chop off at first CR */
if(tp != NULL)
*tp = 0;
subject = p;
p += strlen(p) + 1;
continue;
}
break;
}
kludge_hdrlen += (p - beg) + 1;
SAFECOPY(name,to);
p=strchr(name,'@');
......@@ -455,15 +489,10 @@ void sbbs_t::qwktonetmail(FILE *rep, char *block, char *into, uchar fromhub)
return;
}
l=QWK_BLOCK_LEN; /* Start of message text */
l = QWK_BLOCK_LEN + kludge_hdrlen; /* Start of message text */
if(qnet || inet) {
if(into==NULL) { /* If name@addr on first line, skip first line */
while(l<(n*QWK_BLOCK_LEN) && qwkbuf[l]!=QWK_NEWLINE) l++;
l++;
}
memset(&msg,0,sizeof(smbmsg_t));
msg.hdr.version=smb_ver();
msg.hdr.when_imported.time=time32(NULL);
......@@ -528,8 +557,11 @@ void sbbs_t::qwktonetmail(FILE *rep, char *block, char *into, uchar fromhub)
tm.tm_isdst=-1; /* Do not adjust for DST */
msg.hdr.when_written.time=mktime32(&tm);
sprintf(str,"%.25s",block+71); /* Title */
smb_hfield(&msg,SUBJECT,strlen(str),str);
if(subject == NULL) {
sprintf(str, "%.25s", block+71);
subject = str;
}
smb_hfield_str(&msg, SUBJECT, subject);
}
if(qnet) {
......@@ -668,6 +700,8 @@ void sbbs_t::qwktonetmail(FILE *rep, char *block, char *into, uchar fromhub)
if(qwkbuf[l]==0 || qwkbuf[l]==LF)
continue;
if(qwkbuf[l]==QWK_NEWLINE) {
if(m <= 2) /* Ignore blank lines at top of message */
continue;
smb_fwrite(&smb,crlf,2,smb.sdt_fp);
m+=2;
continue;
......@@ -825,7 +859,10 @@ void sbbs_t::qwktonetmail(FILE *rep, char *block, char *into, uchar fromhub)
hdr.attr|=FIDO_FILE;
}
SAFECOPY(hdr.subj,p);
if(subject != NULL)
SAFECOPY(hdr.subj, subject);
else
SAFECOPY(hdr.subj, p);
md(cfg.netmail_dir);
for(i=1;i;i++) {
......@@ -851,12 +888,7 @@ void sbbs_t::qwktonetmail(FILE *rep, char *block, char *into, uchar fromhub)
write(fido,str,strlen(str));
}
l=QWK_BLOCK_LEN;
if(into==NULL) { /* If name@addr on first line, skip first line */
while(l<n*QWK_BLOCK_LEN && qwkbuf[l]!=QWK_NEWLINE) l++;
l++;
}
l = QWK_BLOCK_LEN + kludge_hdrlen;
length=n*QWK_BLOCK_LEN;
while(l<length) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment