Subversion Repositories Kolibri OS

Rev

Rev 4166 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4166 Rev 4186
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 ( mailend-mailstart > 9) if (strncmp(mailend-5,"\n.\n",5)==0) // note that c-- assembles "\n.\n" to 0x0d, 0x0a, 0x2e, 0x0d, 0x0a
8
	if ( mailend-mailstart > 9) && (strncmp(mailend-5,"\n.\n",5)==0) // note that c-- assembles "\n.\n" to 0x0d, 0x0a, 0x2e, 0x0d, 0x0a
9
	{
9
	{
-
 
10
		mailend -= 5;
10
		mailend -= 5;
11
		DSBYTE[mailend] = '\0';
11
		if (strstr(mailstart, "+OK")!=mailstart) 
12
		if (strstr(mailstart, "+OK")!=mailstart) 
12
		{
13
		{
13
			aim = GET_ANSWER_RETR;
14
			aim = GET_ANSWER_RETR;
14
			mailend = mailstart;
15
			mailend = mailstart;
15
			debug("GET_ANSWER_RETR != +OK, retry GET_ANSWER_RETR");
16
			debug("GET_ANSWER_RETR != +OK, retry GET_ANSWER_RETR");
16
			return;
17
			return;
17
		}
18
		}
18
		aim=NULL;
-
 
19
		DSBYTE[mailend] = '\0';
19
		aim=NULL;
Line -... Line 20...
-
 
20
		mailsize = mailend - mailstart;
20
		mailsize = mailend - mailstart;
21
 
21
 
22
		debug("Getting QP");
22
		if (strstri(mailstart, "quoted-printable")!=0)
23
		if (strstri(mailstart, "quoted-printable")!=0)
23
		{
24
		{
24
			new_buf = malloc(mailend-mailstart);
25
			new_buf = malloc(mailsize);
25
			qp_decode stdcall (mailstart, new_buf, mailend-mailstart);
26
			qp_decode stdcall (mailstart, new_buf, mailsize);
26
			if (EAX==-1) debug("Too small buffer to convert QUOTED-PRINTABLE");
27
			if (EAX==-1) debug("Too small buffer to convert QUOTED-PRINTABLE");
27
			else
28
			else
28
			{
29
			{
29
				free(mailstart);
30
				free(mailstart);
30
				mailstart = new_buf;
31
				mailstart = new_buf;
31
				mailsize = strlen(mailstart);
32
				mailsize = strlen(mailstart);
32
				mailend = mailsize + mailstart;
33
				mailend = mailsize + mailstart;
-
 
34
			}
33
			}
35
		}
34
		}
36
		debug("GetHeaders: From, To, Date, Subject");
35
		GetHeader(#from, "\nFrom:");
37
		GetHeader(#from, "\nFrom:");
36
		GetHeader(#to,   "\nTo:");
38
		GetHeader(#to,   "\nTo:");
-
 
39
		GetHeader(#date, "\nDate:");
37
		GetHeader(#date, "\nDate:");
40
		GetHeader(#subj, "\nSubject:");
-
 
41
		debug("Get mdata");
38
		GetHeader(#subj, "\nSubject:");
42
		mdata = strstr(mailstart, "\x0a\x0d") + 3;		// 0x0d 0x0a, 0x0a
-
 
43
		debug("ConvertToDOS");
39
		mdata = strstr(mailstart, "\n\r") + 3;		// 0x0d 0x0a, 0x0a
44
		ConvertToDOS(mdata, mailstart);
40
		ConvertToDOS(mdata, mailstart);
45
		debug("FromHTMLtoTXT");
Line 41... Line 46...
41
		FromHTMLtoTXT();
46
		FromHTMLtoTXT();
42
		letter_view.first = letter_view.count = 0;
47
		letter_view.first = letter_view.count = 0;
43
		
48
		
44
		line_off = mdata;
49
		line_off = mdata;
45
		while (line_off>1)
50
		while (line_off>1)
46
		{
51
		{
-
 
52
			line_off = GetNextLine(line_off);
47
			line_off = GetNextLine(line_off);
53
			letter_view.count++;	
48
			letter_view.count++;	
54
		}
49
		}
55
		debug("SetAtrFromCurr");
50
		atr.SetAtrFromCurr(mail_list.current+1);
56
		atr.SetAtrFromCurr(mail_list.current+1);
Line 81... Line 87...
81
void FromHTMLtoTXT()
87
void FromHTMLtoTXT()
82
{
88
{
83
	dword cur_chr, txt_buf_srt, txt_buf_end, is_tag=0;
89
	dword cur_chr, txt_buf_srt, txt_buf_end, is_tag=0;
84
	int i;
90
	int i;
85
	if (strstri(mdata, "")==0) && (strstri(mailstart, "text/html")==0) {debug("no html tags found"); return;}
91
	if (strstri(mdata, "")==0) && (strstri(mailstart, "text/html")==0) {debug("no html tags found"); return;}
86
	debug ("converting: html -> txt");
92
	debug ("Mail got  code");
87
	cur_chr = mdata;
93
	cur_chr = mdata;
88
	txt_buf_srt = malloc(mailend - mailstart);
94
	txt_buf_srt = malloc(mailend - mailstart);
89
	txt_buf_end = txt_buf_srt;
95
	txt_buf_end = txt_buf_srt;
Line 90... Line 96...
90
 
96
 
Line 135... Line 141...
135
	}
141
	}
136
	DSBYTE[new_line] = '\0';
142
	DSBYTE[new_line] = '\0';
137
	return line;
143
	return line;
138
}
144
}
Line -... Line 145...
-
 
145
 
139
 
146
 
140
void GetHeader(dword workstr, searchstr)
147
void GetHeader(dword workstr, searchstr)
141
{
148
{
142
	char tmpbuf[512];
149
	char tmpbuf[512];
-
 
150
	dword Qoff;
Line 143... Line 151...
143
	dword Qoff;
151
	int q_start, b_start;
-
 
152
 
-
 
153
	strcpyb(mailstart, workstr, searchstr, "\n");
-
 
154
	debug(searchstr);
144
 
155
	debug(workstr);
-
 
156
	if (strlen(workstr)<8) return;
-
 
157
	q_start = strstri(workstr, "?Q?");
145
	strcpyb(mailstart, workstr, searchstr, "\n");
158
	b_start = strstri(workstr, "?B?");
146
	if (strstri(workstr, "?Q?"))
159
	if (q_start)
147
	{
160
	{
148
		qp_decode stdcall (workstr, #tmpbuf, strlen(workstr));
161
		qp_decode stdcall (workstr, #tmpbuf, strlen(workstr));
149
		ConvertToDOS(#tmpbuf, workstr);	
162
		ConvertToDOS(#tmpbuf, workstr);	
150
		strcpy(workstr, #tmpbuf);
163
		strcpy(workstr, #tmpbuf);
151
		Qoff = strstri(workstr, "?Q?");
164
		Qoff = strstri(workstr, "?Q?");
-
 
165
		strcpy(workstr, Qoff);
-
 
166
	}
152
		strcpy(workstr, Qoff);
167
 
153
	}
168
	//any text that goes after "?=" deletes now
154
	if (strstr(workstr, "?B?"))
169
	if (b_start)
155
	{
170
	{
156
		base64_decode stdcall (strstri(workstr, "?B?"), #tmpbuf, strlen(workstr));
171
		base64_decode stdcall (b_start, #tmpbuf, strlen(b_start)-5);
157
		ConvertToDOS(#tmpbuf, workstr);	
172
		ConvertToDOS(#tmpbuf, workstr);	
158
		strcpy(workstr, #tmpbuf);
173
		strcpy(workstr, #tmpbuf);
159
	}
174
	}
160
	if (strlen(workstr)+10*6-Form.cwidth>0) { workstr=Form.cwidth/6+workstr-12; DSBYTE[workstr]='\0';}
175
	if (strlen(workstr)+10*6-Form.cwidth>0) { workstr=Form.cwidth/6+workstr-12; DSBYTE[workstr]='\0';}