Subversion Repositories Kolibri OS

Rev

Rev 4142 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4142 Rev 4166
Line 3... Line 3...
3
void ParseMail()
3
void ParseMail()
4
{
4
{
5
	dword line_off, new_buf;
5
	dword line_off, new_buf;
6
	char tline[256];
6
	char tline[256];
Line 7... Line 7...
7
 
7
 
8
	if ( mailpointer-mailbuffer>9 ) if (strncmp(mailpointer-5,"\n.\n",5)==0) // note that c-- assembles "\n.\n" to 0x0d, 0x0a, 0x2e, 0x0d, 0x0a
8
	if ( mailend-mailstart > 9) if (strncmp(mailend-5,"\n.\n",5)==0) // note that c-- assembles "\n.\n" to 0x0d, 0x0a, 0x2e, 0x0d, 0x0a
9
	{
-
 
10
		debug("End of mail detected");
9
	{
11
		mailpointer = mailpointer - 5;
-
 
12
		
10
		mailend -= 5;
13
		if (strstr(mailbuffer, "+OK")!=mailbuffer) 
11
		if (strstr(mailstart, "+OK")!=mailstart) 
14
		{
12
		{
15
			aim = GET_ANSWER_RETR;
13
			aim = GET_ANSWER_RETR;
16
			mailpointer = mailbuffer;
14
			mailend = mailstart;
17
			debug("GET_ANSWER_RETR != +OK, retry GET_ANSWER_RETR");
15
			debug("GET_ANSWER_RETR != +OK, retry GET_ANSWER_RETR");
18
			return;
16
			return;
19
		}
17
		}
20
		aim=NULL;
18
		aim=NULL;
21
		DSBYTE[mailpointer] = '\0';
-
 
22
		debug("Real letter size:");
19
		DSBYTE[mailend] = '\0';
23
		debugi(mailpointer - mailbuffer);
20
		mailsize = mailend - mailstart;
24
 
21
 
25
		if (strstri(mailbuffer, "quoted-printable")!=0)
22
		if (strstri(mailstart, "quoted-printable")!=0)
26
		{
-
 
27
			debug ("getting qp");
23
		{
28
			new_buf = malloc(mailpointer-mailbuffer);
24
			new_buf = malloc(mailend-mailstart);
29
			qp_decode stdcall (mailbuffer, new_buf, mailpointer-mailbuffer);
25
			qp_decode stdcall (mailstart, new_buf, mailend-mailstart);
30
			if (EAX==-1) debug("Too small buffer to convert QUOTED-PRINTABLE");
26
			if (EAX==-1) debug("Too small buffer to convert QUOTED-PRINTABLE");
31
			else
27
			else
32
			{
28
			{
33
				free(mailbuffer);
29
				free(mailstart);
34
				mailbuffer = new_buf;
30
				mailstart = new_buf;
-
 
31
				mailsize = strlen(mailstart);
35
				mailpointer = strlen(mailbuffer) + mailbuffer;
32
				mailend = mailsize + mailstart;
36
			}
33
			}
37
		}
-
 
38
		debug ("getting list info");
34
		}
39
		GetHeader(#from, "\nFrom:");
35
		GetHeader(#from, "\nFrom:");
40
		GetHeader(#to,   "\nTo:");
36
		GetHeader(#to,   "\nTo:");
41
		GetHeader(#date, "\nDate:");
37
		GetHeader(#date, "\nDate:");
42
		GetHeader(#subj, "\nSubject:");
38
		GetHeader(#subj, "\nSubject:");
43
		mdata = strstr(mailbuffer, "\n\r") + 3;		// 0x0d 0x0a, 0x0a
-
 
44
		debug ("converting to dos");
39
		mdata = strstr(mailstart, "\n\r") + 3;		// 0x0d 0x0a, 0x0a
45
		ConvertToDOS(mdata, mailbuffer);
40
		ConvertToDOS(mdata, mailstart);
46
		FromHTMLtoTXT();
41
		FromHTMLtoTXT();
Line 47... Line 42...
47
		letter_view.first = letter_view.count = 0;
42
		letter_view.first = letter_view.count = 0;
48
		
43
		
Line 85... Line 80...
85
 
80
 
86
void FromHTMLtoTXT()
81
void FromHTMLtoTXT()
87
{
82
{
88
	dword cur_chr, txt_buf_srt, txt_buf_end, is_tag=0;
83
	dword cur_chr, txt_buf_srt, txt_buf_end, is_tag=0;
89
	int i;
84
	int i;
90
	if (strstri(mdata, "")==0) && (strstri(mailbuffer, "text/html")==0) {debug("no html tags found"); return;}
85
	if (strstri(mdata, "")==0) && (strstri(mailstart, "text/html")==0) {debug("no html tags found"); return;}
91
	debug ("converting: html -> txt");
86
	debug ("converting: html -> txt");
92
	cur_chr = mdata;
87
	cur_chr = mdata;
93
	txt_buf_srt = malloc(mailpointer - mailbuffer);
88
	txt_buf_srt = malloc(mailend - mailstart);
Line 94... Line 89...
94
	txt_buf_end = txt_buf_srt;
89
	txt_buf_end = txt_buf_srt;
95
 
90
 
96
	while (cur_chr < mailpointer)
91
	while (cur_chr < mailend)
97
	{
92
	{
98
		if (DSBYTE[cur_chr]=='<') is_tag = 1;
93
		if (DSBYTE[cur_chr]=='<') is_tag = 1;
99
		if (!is_tag)
94
		if (!is_tag)
Line 105... Line 100...
105
		if (DSBYTE[cur_chr]=='>') is_tag = NULL;
100
		if (DSBYTE[cur_chr]=='>') is_tag = NULL;
106
		cur_chr++;
101
		cur_chr++;
107
	}
102
	}
108
	DSBYTE[txt_buf_end] = '\0';
103
	DSBYTE[txt_buf_end] = '\0';
109
	strcpy(mdata, txt_buf_srt);
104
	strcpy(mdata, txt_buf_srt);
110
	mailpointer = strlen(mailbuffer) + mailbuffer; //тупо везде это ставить
105
	mailend = strlen(mailstart) + mailstart;
111
	free(txt_buf_srt);
106
	free(txt_buf_srt);
112
}
107
}
Line 113... Line 108...
113
 
108
 
Line 145... Line 140...
145
void GetHeader(dword workstr, searchstr)
140
void GetHeader(dword workstr, searchstr)
146
{
141
{
147
	char tmpbuf[512];
142
	char tmpbuf[512];
148
	dword Qoff;
143
	dword Qoff;
Line 149... Line 144...
149
 
144
 
150
	strcpyb(mailbuffer, workstr, searchstr, "\n");
145
	strcpyb(mailstart, workstr, searchstr, "\n");
151
	if (strstri(workstr, "?Q?"))
146
	if (strstri(workstr, "?Q?"))
152
	{
147
	{
153
		qp_decode stdcall (workstr, #tmpbuf, strlen(workstr));
148
		qp_decode stdcall (workstr, #tmpbuf, strlen(workstr));
154
		ConvertToDOS(#tmpbuf, workstr);	
149
		ConvertToDOS(#tmpbuf, workstr);