Subversion Repositories Kolibri OS

Rev

Rev 4534 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3368 leency 1
//Leency & SoUrcerer, LGPL
2
 
4139 hidnplayr 3
void ParseMail()
3368 leency 4
{
5
	dword line_off, new_buf;
6
	char tline[256];
7
 
4417 leency 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
3368 leency 9
	{
4417 leency 10
		aim = STOP;
4166 leency 11
		mailend -= 5;
4186 leency 12
		DSBYTE[mailend] = '\0';
4166 leency 13
		if (strstr(mailstart, "+OK")!=mailstart)
3368 leency 14
		{
15
			aim = GET_ANSWER_RETR;
4166 leency 16
			mailend = mailstart;
3368 leency 17
			debug("GET_ANSWER_RETR != +OK, retry GET_ANSWER_RETR");
18
			return;
19
		}
4166 leency 20
		mailsize = mailend - mailstart;
4186 leency 21
		debug("Getting QP");
4166 leency 22
		if (strstri(mailstart, "quoted-printable")!=0)
3368 leency 23
		{
4186 leency 24
			new_buf = malloc(mailsize);
25
			qp_decode stdcall (mailstart, new_buf, mailsize);
3368 leency 26
			if (EAX==-1) debug("Too small buffer to convert QUOTED-PRINTABLE");
27
			else
28
			{
4166 leency 29
				free(mailstart);
30
				mailstart = new_buf;
31
				mailsize = strlen(mailstart);
32
				mailend = mailsize + mailstart;
3368 leency 33
			}
3413 leency 34
		}
4417 leency 35
		debug("ProcessBase64");
36
		ProcessBase64();
4186 leency 37
		debug("GetHeaders: From, To, Date, Subject");
3368 leency 38
		GetHeader(#from, "\nFrom:");
39
		GetHeader(#to,   "\nTo:");
40
		GetHeader(#date, "\nDate:");
41
		GetHeader(#subj, "\nSubject:");
4186 leency 42
		debug("Get mdata");
4417 leency 43
		mdata = strstr(mailstart, "\x0a\x0d") + 3;
4186 leency 44
		debug("ConvertToDOS");
4166 leency 45
		ConvertToDOS(mdata, mailstart);
4186 leency 46
		debug("SetAtrFromCurr");
3413 leency 47
		atr.SetAtrFromCurr(mail_list.current+1);
3368 leency 48
		DrawMailBox();
49
	}
50
}
51
 
52
void ConvertToDOS(dword inbuf, searchin)
53
{
54
	dword dos_buf=0;
5690 leency 55
	cur_charset = CH_CP866;
56
	if (strstri(searchin, "windows-1251")!=0) || (strstri(searchin, "windows1251")!=0)
57
		{ dos_buf = ChangeCharset("CP1251", "CP866", inbuf);    cur_charset = CH_CP1251;}
58
	else if (strstri(searchin, "koi8-")!=0)
59
		{ dos_buf = ChangeCharset("KOI8-RU", "CP866", inbuf);   cur_charset = CH_KOI8;}
60
	else if (strstri(searchin, "utf-8")!=0) || (strstri(searchin, "utf8")!=0)
61
		{ dos_buf = ChangeCharset("UTF-8", "CP866", inbuf);     cur_charset = CH_UTF8;}
62
	else if (strstri(searchin, "iso8859-5")!=0) || (strstri(searchin, "iso-8859-5")!=0)
63
		{ dos_buf = ChangeCharset("ISO8859-5", "CP866", inbuf); cur_charset = CH_ISO8859_5;}
64
	else if (strstri(searchin, "windows-1252")!=0) || (strstri(searchin, "windows1252")!=0)
65
		{ dos_buf = ChangeCharset("CP1252", "CP866", inbuf);    cur_charset = CH_CP1252;}
3368 leency 66
}
67
 
68
 
69
dword CopyBetweenOffsets(dword start, end) //do not forget to free(line) after use
70
{
71
	dword line, new_line;
72
	if (end <= start) return 0;
73
	line = new_line = malloc(end - start + 3);
74
	while (end > start)
75
	{
76
		DSBYTE[new_line] = DSBYTE[start];
77
		start++;
78
		new_line++;
79
	}
80
	DSBYTE[new_line] = '\0';
81
	return line;
82
}
83
 
4186 leency 84
 
3368 leency 85
void GetHeader(dword workstr, searchstr)
86
{
87
	char tmpbuf[512];
88
	dword Qoff;
4186 leency 89
	int q_start, b_start;
3368 leency 90
 
4166 leency 91
	strcpyb(mailstart, workstr, searchstr, "\n");
4417 leency 92
	/*
4186 leency 93
	debug(searchstr);
94
	debug(workstr);
95
	if (strlen(workstr)<8) return;
96
	q_start = strstri(workstr, "?Q?");
97
	b_start = strstri(workstr, "?B?");
98
	if (q_start)
3368 leency 99
	{
100
		qp_decode stdcall (workstr, #tmpbuf, strlen(workstr));
101
		ConvertToDOS(#tmpbuf, workstr);
102
		strcpy(workstr, #tmpbuf);
103
		Qoff = strstri(workstr, "?Q?");
104
		strcpy(workstr, Qoff);
105
	}
4186 leency 106
 
107
	//any text that goes after "?=" deletes now
108
	if (b_start)
3368 leency 109
	{
4186 leency 110
		base64_decode stdcall (b_start, #tmpbuf, strlen(b_start)-5);
3368 leency 111
		ConvertToDOS(#tmpbuf, workstr);
112
		strcpy(workstr, #tmpbuf);
113
	}
114
	if (strlen(workstr)+10*6-Form.cwidth>0) { workstr=Form.cwidth/6+workstr-12; DSBYTE[workstr]='\0';}
4417 leency 115
	*/
116
}
117
 
118
 
119
 
120
void ProcessBase64()
121
{
122
	int b_start, b_end, b_size, b_buf;
123
	int clean_mailstart;
124
 
125
	b_start = strstr(mailstart, "?B?");
126
	debug("b_size");
127
	debugi(b_start);
128
	if (b_start)
129
	{
130
		b_end = strstr(b_start, "?=");
131
		debug("b_end");
132
		debugi(b_end);
133
		b_size = b_end - b_start;
134
		debug("b_size");
135
		debugi(b_size);
136
		b_buf = malloc(b_size);
137
		strcpyb(mailstart, b_buf, "?B?", "?=");
138
		debug("b_buf");
139
		debug(b_buf);
140
 
141
		base64_decode stdcall (b_buf, b_buf, b_size-3);
142
		ConvertToDOS(b_buf, mailstart);
143
		if (b_size
144
 
145
		clean_mailstart = malloc(strlen(mailstart));
146
		strlcpy(clean_mailstart, mailstart, b_start-mailstart);
147
		strcat(clean_mailstart, b_buf);
148
		strcat(clean_mailstart, b_end+2);
149
		free(b_buf);
150
		free(mailstart);
151
		mailsize = strlen(clean_mailstart);
152
		mailstart = clean_mailstart;
153
		mailend = mailstart + mailsize;
154
		ProcessBase64();
155
	}
156
}
157
 
158
 
159
//