2013-03-12 17:19:10 +01:00
|
|
|
//Leency & SoUrcerer, LGPL
|
|
|
|
|
2013-10-31 19:40:41 +01:00
|
|
|
void ParseMail()
|
2013-03-12 17:19:10 +01:00
|
|
|
{
|
|
|
|
dword line_off, new_buf;
|
|
|
|
char tline[256];
|
|
|
|
|
2013-12-29 13:48:06 +01:00
|
|
|
if ( mailend-mailstart > 9) if (strncmp(mailend-5,"\n.\n",5)==0) // note that c-- assembles "\n.\n" to 0x0d, 0x0a, 0x2e, 0x0d, 0x0a
|
2013-03-12 17:19:10 +01:00
|
|
|
{
|
2013-12-29 13:48:06 +01:00
|
|
|
aim = STOP;
|
2013-11-05 00:27:39 +01:00
|
|
|
mailend -= 5;
|
2013-11-06 19:50:58 +01:00
|
|
|
DSBYTE[mailend] = '\0';
|
2013-11-05 00:27:39 +01:00
|
|
|
if (strstr(mailstart, "+OK")!=mailstart)
|
2013-03-12 17:19:10 +01:00
|
|
|
{
|
|
|
|
aim = GET_ANSWER_RETR;
|
2013-11-05 00:27:39 +01:00
|
|
|
mailend = mailstart;
|
2013-03-12 17:19:10 +01:00
|
|
|
debug("GET_ANSWER_RETR != +OK, retry GET_ANSWER_RETR");
|
|
|
|
return;
|
|
|
|
}
|
2013-11-05 00:27:39 +01:00
|
|
|
mailsize = mailend - mailstart;
|
2013-11-06 19:50:58 +01:00
|
|
|
debug("Getting QP");
|
2013-11-05 00:27:39 +01:00
|
|
|
if (strstri(mailstart, "quoted-printable")!=0)
|
2013-03-12 17:19:10 +01:00
|
|
|
{
|
2013-11-06 19:50:58 +01:00
|
|
|
new_buf = malloc(mailsize);
|
|
|
|
qp_decode stdcall (mailstart, new_buf, mailsize);
|
2013-03-12 17:19:10 +01:00
|
|
|
if (EAX==-1) debug("Too small buffer to convert QUOTED-PRINTABLE");
|
|
|
|
else
|
|
|
|
{
|
2013-11-05 00:27:39 +01:00
|
|
|
free(mailstart);
|
|
|
|
mailstart = new_buf;
|
|
|
|
mailsize = strlen(mailstart);
|
|
|
|
mailend = mailsize + mailstart;
|
2013-03-12 17:19:10 +01:00
|
|
|
}
|
2013-03-26 01:45:57 +01:00
|
|
|
}
|
2013-12-29 13:48:06 +01:00
|
|
|
debug("ProcessBase64");
|
|
|
|
ProcessBase64();
|
2013-11-06 19:50:58 +01:00
|
|
|
debug("GetHeaders: From, To, Date, Subject");
|
2013-03-12 17:19:10 +01:00
|
|
|
GetHeader(#from, "\nFrom:");
|
|
|
|
GetHeader(#to, "\nTo:");
|
|
|
|
GetHeader(#date, "\nDate:");
|
|
|
|
GetHeader(#subj, "\nSubject:");
|
2013-11-06 19:50:58 +01:00
|
|
|
debug("Get mdata");
|
2013-12-29 13:48:06 +01:00
|
|
|
mdata = strstr(mailstart, "\x0a\x0d") + 3;
|
2013-11-06 19:50:58 +01:00
|
|
|
debug("ConvertToDOS");
|
2013-11-05 00:27:39 +01:00
|
|
|
ConvertToDOS(mdata, mailstart);
|
2013-11-06 19:50:58 +01:00
|
|
|
debug("SetAtrFromCurr");
|
2013-03-26 01:45:57 +01:00
|
|
|
atr.SetAtrFromCurr(mail_list.current+1);
|
2013-03-12 17:19:10 +01:00
|
|
|
DrawMailBox();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConvertToDOS(dword inbuf, searchin)
|
|
|
|
{
|
|
|
|
dword dos_buf=0;
|
|
|
|
if (use_iconv==1)
|
|
|
|
{
|
|
|
|
cur_charset = CH_CP866;
|
|
|
|
if (strstri(searchin, "windows-1251")!=0) || (strstri(searchin, "windows1251")!=0)
|
|
|
|
{ dos_buf = ChangeCharset("CP1251", "CP866", inbuf); cur_charset = CH_CP1251;}
|
|
|
|
else if (strstri(searchin, "koi8-")!=0)
|
|
|
|
{ dos_buf = ChangeCharset("KOI8-RU", "CP866", inbuf); cur_charset = CH_KOI8;}
|
|
|
|
else if (strstri(searchin, "utf-8")!=0) || (strstri(searchin, "utf8")!=0)
|
|
|
|
{ dos_buf = ChangeCharset("UTF-8", "CP866", inbuf); cur_charset = CH_UTF8;}
|
|
|
|
else if (strstri(searchin, "iso8859-5")!=0) || (strstri(searchin, "iso-8859-5")!=0)
|
|
|
|
{ dos_buf = ChangeCharset("ISO8859-5", "CP866", inbuf); cur_charset = CH_ISO8859_5;}
|
|
|
|
else if (strstri(searchin, "windows-1252")!=0) || (strstri(searchin, "windows1252")!=0)
|
|
|
|
{ dos_buf = ChangeCharset("CP1252", "CP866", inbuf); cur_charset = CH_CP1252;}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (strstri(searchin, "windows-1251")!=0) wintodos( inbuf); else
|
|
|
|
if (strstri(searchin, "koi8-")!=0) koitodos( inbuf); else
|
|
|
|
if (strstri(searchin, "utf-8")!=0) utf8rutodos( inbuf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
dword CopyBetweenOffsets(dword start, end) //do not forget to free(line) after use
|
|
|
|
{
|
|
|
|
dword line, new_line;
|
|
|
|
if (end <= start) return 0;
|
|
|
|
line = new_line = malloc(end - start + 3);
|
|
|
|
while (end > start)
|
|
|
|
{
|
|
|
|
DSBYTE[new_line] = DSBYTE[start];
|
|
|
|
start++;
|
|
|
|
new_line++;
|
|
|
|
}
|
|
|
|
DSBYTE[new_line] = '\0';
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
2013-11-06 19:50:58 +01:00
|
|
|
|
2013-03-12 17:19:10 +01:00
|
|
|
void GetHeader(dword workstr, searchstr)
|
|
|
|
{
|
|
|
|
char tmpbuf[512];
|
|
|
|
dword Qoff;
|
2013-11-06 19:50:58 +01:00
|
|
|
int q_start, b_start;
|
2013-03-12 17:19:10 +01:00
|
|
|
|
2013-11-05 00:27:39 +01:00
|
|
|
strcpyb(mailstart, workstr, searchstr, "\n");
|
2013-12-29 13:48:06 +01:00
|
|
|
/*
|
2013-11-06 19:50:58 +01:00
|
|
|
debug(searchstr);
|
|
|
|
debug(workstr);
|
|
|
|
if (strlen(workstr)<8) return;
|
|
|
|
q_start = strstri(workstr, "?Q?");
|
|
|
|
b_start = strstri(workstr, "?B?");
|
|
|
|
if (q_start)
|
2013-03-12 17:19:10 +01:00
|
|
|
{
|
|
|
|
qp_decode stdcall (workstr, #tmpbuf, strlen(workstr));
|
|
|
|
ConvertToDOS(#tmpbuf, workstr);
|
|
|
|
strcpy(workstr, #tmpbuf);
|
|
|
|
Qoff = strstri(workstr, "?Q?");
|
|
|
|
strcpy(workstr, Qoff);
|
|
|
|
}
|
2013-11-06 19:50:58 +01:00
|
|
|
|
|
|
|
//any text that goes after "?=" deletes now
|
|
|
|
if (b_start)
|
2013-03-12 17:19:10 +01:00
|
|
|
{
|
2013-11-06 19:50:58 +01:00
|
|
|
base64_decode stdcall (b_start, #tmpbuf, strlen(b_start)-5);
|
2013-03-12 17:19:10 +01:00
|
|
|
ConvertToDOS(#tmpbuf, workstr);
|
|
|
|
strcpy(workstr, #tmpbuf);
|
|
|
|
}
|
|
|
|
if (strlen(workstr)+10*6-Form.cwidth>0) { workstr=Form.cwidth/6+workstr-12; DSBYTE[workstr]='\0';}
|
2013-12-29 13:48:06 +01:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ProcessBase64()
|
|
|
|
{
|
|
|
|
int b_start, b_end, b_size, b_buf;
|
|
|
|
int clean_mailstart;
|
|
|
|
|
|
|
|
b_start = strstr(mailstart, "?B?");
|
|
|
|
debug("b_size");
|
|
|
|
debugi(b_start);
|
|
|
|
if (b_start)
|
|
|
|
{
|
|
|
|
b_end = strstr(b_start, "?=");
|
|
|
|
debug("b_end");
|
|
|
|
debugi(b_end);
|
|
|
|
b_size = b_end - b_start;
|
|
|
|
debug("b_size");
|
|
|
|
debugi(b_size);
|
|
|
|
b_buf = malloc(b_size);
|
|
|
|
strcpyb(mailstart, b_buf, "?B?", "?=");
|
|
|
|
debug("b_buf");
|
|
|
|
debug(b_buf);
|
|
|
|
|
|
|
|
base64_decode stdcall (b_buf, b_buf, b_size-3);
|
|
|
|
ConvertToDOS(b_buf, mailstart);
|
|
|
|
if (b_size<strlen(b_buf)) notify("base64 overflow");
|
|
|
|
|
|
|
|
clean_mailstart = malloc(strlen(mailstart));
|
|
|
|
strlcpy(clean_mailstart, mailstart, b_start-mailstart);
|
|
|
|
strcat(clean_mailstart, b_buf);
|
|
|
|
strcat(clean_mailstart, b_end+2);
|
|
|
|
free(b_buf);
|
|
|
|
free(mailstart);
|
|
|
|
mailsize = strlen(clean_mailstart);
|
|
|
|
mailstart = clean_mailstart;
|
|
|
|
mailend = mailstart + mailsize;
|
|
|
|
ProcessBase64();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|