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 4169
Line 25... Line 25...
25
	EXIT_MAIL,
25
	EXIT_MAIL,
26
	CHANGE_CHARSET,
26
	CHANGE_CHARSET,
27
	CLOSE_CHANGE_CHARSET
27
	CLOSE_CHANGE_CHARSET
28
};
28
};
Line -... Line 29...
-
 
29
 
-
 
30
void MailBoxNetworkProcess()
-
 
31
{
-
 
32
	int load_persent;
-
 
33
	if (aim) switch(aim)
-
 
34
	{
-
 
35
		case SEND_NSTAT:
-
 
36
				SetLoginStatus("Counting mail, awaiting answer...");			
-
 
37
				request_len = GetRequest("STAT", NULL);
-
 
38
				Send(socketnum, #request, request_len, 0);
-
 
39
				if (EAX == 0xffffffff) { debug("Error sending STAT. Retry..."w); break;}
-
 
40
				aim = GET_ANSWER_NSTAT;
-
 
41
				break;
-
 
42
 
-
 
43
		case GET_ANSWER_NSTAT:
-
 
44
				ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
-
 
45
				if ((ticks == 0xffffff) || (ticks < 2)) break;
-
 
46
									
-
 
47
				if (immbuffer[ticks-2]=='\n')
-
 
48
				{
-
 
49
					debug(#immbuffer);
-
 
50
					if (strstr(#immbuffer,"+OK"))
-
 
51
					{
-
 
52
						strcpyb(#immbuffer, #param, "+OK ", " ");
-
 
53
						mail_list.count = atoi(#param);
-
 
54
						free(listbuffer);
-
 
55
						listbuffer = mem_Alloc(30*mail_list.count); //24* original
-
 
56
						listpointer = listbuffer;	
-
 
57
						aim = SEND_NLIST;
-
 
58
						debug("Receiving mail list...");
-
 
59
					}
-
 
60
					else
-
 
61
					{
-
 
62
						StopConnect("Sorry, can't recieve your mail");
-
 
63
					}
-
 
64
				}
-
 
65
				break;
-
 
66
 
-
 
67
		case SEND_NLIST:
-
 
68
				WriteText(5, Form.cheight-11, 0x80, sc.work_text, "Send LIST, awaiting answer...");
-
 
69
				request_len = GetRequest("LIST", NULL);
-
 
70
				Send(socketnum, #request, request_len, 0);
-
 
71
				if (EAX == 0xffffffff) {debug("Error while sending LIST. Retry..."); break;}
-
 
72
				else aim = GET_ANSWER_NLIST;
-
 
73
				break;
-
 
74
 
-
 
75
		case GET_ANSWER_NLIST:
-
 
76
				ticks = Receive(socketnum, listpointer, listbuffer + 30*mail_list.count - listpointer, MSG_DONTWAIT);
-
 
77
				if (ticks == 0xffffffff) break;	
-
 
78
				listpointer = listpointer + ticks;	
-
 
79
				
-
 
80
				if (listpointer - listbuffer < 5) break;
-
 
81
				if (strncmp(listpointer-5,"\n.\n",5)==0)  // note that c-- assembles "\n.\n" to 0x0d, 0x0a, 0x2e, 0x0d, 0x0a	
-
 
82
				{
-
 
83
					aim = SEND_RETR;
-
 
84
					debug("Got mail list");
-
 
85
					DrawMailBox();
-
 
86
					
-
 
87
					*listpointer='\0';
-
 
88
					atr.CreateArray();
-
 
89
					atr.SetSizes();
-
 
90
				}
-
 
91
				break;
-
 
92
 
-
 
93
		case SEND_RETR:
-
 
94
				from = to = date = subj = cur_charset = NULL;
-
 
95
				letter_view.ClearList();
-
 
96
				DrawMailBox();
-
 
97
				debug("Send RETR, awaiting answer...");
-
 
98
				request_len = GetRequest("RETR", itoa(mail_list.current+1));
-
 
99
				if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
-
 
100
				{
-
 
101
					StopConnect("Error while trying to get letter from server");
-
 
102
					break;
-
 
103
				}
-
 
104
				mailsize = atr.GetSize(mail_list.current+1) + 1024;
-
 
105
				free(mailstart);
-
 
106
				if (!mailstart = malloc(mailsize))
-
 
107
				{
-
 
108
					debug("alloc error!");
-
 
109
					aim=NULL;
-
 
110
					break;
-
 
111
				}
-
 
112
				mailend = mailstart;
-
 
113
				aim = GET_ANSWER_RETR;
-
 
114
			
-
 
115
		case GET_ANSWER_RETR:
-
 
116
				ticks = Receive(socketnum, mailend, mailsize + mailstart - mailend, MSG_DONTWAIT);
-
 
117
				if (ticks == 0xffffffff) break;
-
 
118
				
-
 
119
				mailend = mailend + ticks;
-
 
120
 
-
 
121
				if (!aim) break;
-
 
122
 
-
 
123
				if (mailsize + mailstart - mailend - 2 < 0)
-
 
124
				{
-
 
125
					debug("Resizing buffer");
-
 
126
					mailsize += 4096;
-
 
127
					mailstart = realloc(mailstart, mailsize);
-
 
128
					if (!mailstart) { StopConnect("Realloc error!"); break;}
-
 
129
				}
-
 
130
 
-
 
131
				//if (mailsize>9000)
-
 
132
				{
-
 
133
					load_persent = mailend - mailstart * 100 ;
-
 
134
					load_persent /= mailsize - 1024;
-
 
135
					if (load_persent != cur_st_percent) SetMailBoxStatus( load_persent , NULL);
-
 
136
				}
-
 
137
				ParseMail();
-
 
138
	}
-
 
139
}
Line 29... Line 140...
29
 
140
 
30
 
141
 
31
void MailBoxLoop()
142
void MailBoxLoop()
32
{
143
{
Line 157... Line 268...
157
				DrawToolbar();
268
				DrawToolbar();
158
				DrawMailBox();
269
				DrawMailBox();
Line 159... Line 270...
159
 
270
 
160
				break;
271
				break;
161
			default:
-
 
162
				if (aim == SEND_NSTAT)
-
 
163
				{
-
 
164
					SetLoginStatus("Counting mail, awaiting answer...");			
-
 
165
					request_len = GetRequest("STAT", NULL);
-
 
166
					Send(socketnum, #request, request_len, 0);
-
 
167
					if (EAX == 0xffffffff) { debug("Error sending STAT. Retry..."w); break;}
-
 
168
					aim = GET_ANSWER_NSTAT;
-
 
169
				}
-
 
170
				
-
 
171
				if (aim == GET_ANSWER_NSTAT)
-
 
172
				{
-
 
173
					ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
-
 
174
					if ((ticks == 0xffffff) || (ticks < 2)) break;
-
 
175
										
-
 
176
					if (immbuffer[ticks-2]=='\n')
-
 
177
					{
-
 
178
						debug(#immbuffer);
-
 
179
						if (strstr(#immbuffer,"+OK"))
-
 
180
						{
-
 
181
							mail_list.count = GetMailCount();
-
 
182
							free(listbuffer);
-
 
183
							listbuffer = mem_Alloc(30*mail_list.count); //24* original
-
 
184
							listpointer = listbuffer;	
-
 
185
							aim = SEND_NLIST;
-
 
186
							debug("Receiving mail list...");
-
 
187
						}
-
 
188
						else
-
 
189
						{
-
 
190
							StopConnect("Sorry, can't recieve your mail");
-
 
191
						}
-
 
192
					}
-
 
193
				}
-
 
194
 
-
 
195
				if (aim == SEND_NLIST)
-
 
196
				{		
-
 
197
					WriteText(5, Form.cheight-11, 0x80, sc.work_text, "Send LIST, awaiting answer...");
-
 
198
					request_len = GetRequest("LIST", NULL);
-
 
199
					Send(socketnum, #request, request_len, 0);
-
 
200
					if (EAX == 0xffffffff) {debug("Error while sending LIST. Retry..."); break;}
-
 
201
					aim = GET_ANSWER_NLIST;
-
 
202
				}
-
 
203
 
-
 
204
				if (aim == GET_ANSWER_NLIST)
-
 
205
				{		
-
 
206
					ticks = Receive(socketnum, listpointer, listbuffer + 30*mail_list.count - listpointer, MSG_DONTWAIT);
-
 
207
					if (ticks == 0xffffffff) break;	
-
 
208
					listpointer = listpointer + ticks;	
-
 
209
					
-
 
210
					if (listpointer - listbuffer < 5) break;
-
 
211
					if (strncmp(listpointer-5,"\n.\n",5)==0)  // note that c-- assembles "\n.\n" to 0x0d, 0x0a, 0x2e, 0x0d, 0x0a	
-
 
212
					{
-
 
213
						aim = SEND_RETR;
-
 
214
						debug("Got mail list");
-
 
215
						DrawMailBox();
-
 
216
						
-
 
217
						*listpointer='\0';
-
 
218
						atr.CreateArray();
272
			default:
219
						atr.SetSizes();
-
 
220
					}
-
 
221
				}
-
 
222
				
-
 
223
				if (aim == SEND_RETR)
-
 
224
				{
-
 
225
					from = to = date = subj = cur_charset = NULL;
-
 
226
					letter_view.ClearList();
-
 
227
					DrawMailBox();
-
 
228
					debug("Send RETR, awaiting answer...");
-
 
229
					request_len = GetRequest("RETR", itoa(mail_list.current+1));
-
 
230
					if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
-
 
231
					{
-
 
232
						StopConnect("Error while trying to get letter from server");
-
 
233
						break;
-
 
234
					}
-
 
235
					mailsize = atr.GetSize(mail_list.current+1) + 1024;
-
 
236
					free(mailstart);
-
 
237
					if (!mailstart = malloc(mailsize))
-
 
238
					{
-
 
239
						debug("alloc error!");
-
 
240
						aim=NULL;
-
 
241
						break;
-
 
242
					}
-
 
243
					mailend = mailstart;
-
 
244
					aim = GET_ANSWER_RETR;
-
 
245
				}
-
 
246
				
-
 
247
				if (aim == GET_ANSWER_RETR)
-
 
248
				{
-
 
249
					ticks = Receive(socketnum, mailend, mailsize + mailstart - mailend, MSG_DONTWAIT);
-
 
250
					if (ticks == 0xffffffff) break;
-
 
251
					
-
 
252
					mailend = mailend + ticks;
-
 
253
 
-
 
254
					if (!aim) break;
-
 
255
 
-
 
256
					if (mailsize + mailstart - mailend - 2 < 0)
-
 
257
					{
-
 
258
						debug("Resizing buffer");
-
 
259
						mailsize += 4096;
-
 
260
						mailstart = realloc(mailstart, mailsize);
-
 
261
						if (!mailstart) { StopConnect("Realloc error!"); break;}
-
 
262
					}
-
 
263
 
-
 
264
					if (mailsize>9000)
-
 
265
					{
-
 
266
						id = mailend - mailstart * 100 ;
-
 
267
						id /= mailsize - 1024;
-
 
268
						if (id!=cur_st_percent) SetMailBoxStatus( id , NULL);
-
 
269
					}
-
 
270
 
-
 
271
					//debug(mailstart);
-
 
272
					//pause(10);
-
 
273
					//debug("======================");
-
 
274
					ParseMail();
-
 
275
				}
-
 
276
 
273
				MailBoxNetworkProcess();
277
		}
274
		}
278
	}
275
	}
Line 291... Line 288...
291
void DrawToolbar()
288
void DrawToolbar()
292
{
289
{
293
	#define BUT_Y 7
290
	#define BUT_Y 7
294
	#define BUT_H 22
291
	#define BUT_H 22
295
	#define BUT_W 74
292
	#define BUT_W 74
296
	#define BUT_SPACE 11
-
 
297
	int toolbar_w = BUT_Y + BUT_H + BUT_Y + 3;
293
	int toolbar_w = BUT_Y + BUT_H + BUT_Y + 3;
298
	mail_list.SetSizes(0, toolbar_w, Form.cwidth - scroll1.size_x - 1, mail_list.h, 60,18);
294
	mail_list.SetSizes(0, toolbar_w, Form.cwidth - scroll1.size_x - 1, mail_list.h, 60,18);
Line 299... Line 295...
299
 
295
 
300
	DrawBar(0,0, Form.cwidth,toolbar_w-3, sc.work);
296
	DrawBar(0,0, Form.cwidth,toolbar_w-3, sc.work);
301
	DrawCaptButton(10                    , BUT_Y, BUT_W, BUT_H, GET_MAIL,      sc.work_button, sc.work_button_text,"Get mail");
-
 
302
	DrawCaptButton(BUT_W+BUT_SPACE   + 10, BUT_Y, BUT_W, BUT_H, SEND_MAIL,     sc.work_button, sc.work_button_text,"Send Email");
-
 
303
	DrawCaptButton(BUT_W+BUT_SPACE*2 + 10, BUT_Y, BUT_W, BUT_H, DELETE_LETTER, sc.work_button, sc.work_button_text,"Delete");
297
	DrawCaptButton(10                    , BUT_Y, BUT_W, BUT_H, GET_MAIL,    sc.work_button, sc.work_button_text,"Get mail");
304
	DrawCaptButton(BUT_W+BUT_SPACE*3 + 10, BUT_Y, BUT_W, BUT_H, SAVE_LETTER,   sc.work_button, sc.work_button_text,"Save");
298
	DrawCaptButton(BUT_W+ 20, BUT_Y, BUT_W+10, BUT_H, SAVE_LETTER, sc.work_button, sc.work_button_text,"Save letter");
Line 305... Line 299...
305
	DrawCaptButton(Form.cwidth-BUT_W - 10, BUT_Y, BUT_W, BUT_H, EXIT_MAIL,     sc.work_button, sc.work_button_text,"< Exit");
299
	DrawCaptButton(Form.cwidth-BUT_W - 10, BUT_Y, BUT_W, BUT_H, EXIT_MAIL,   sc.work_button, sc.work_button_text,"< Exit");
306
 
300
 
307
	DrawBar(0, mail_list.y-3, mail_list.w,1, sc.work_graph);
301
	DrawBar(0, mail_list.y-3, mail_list.w,1, sc.work_graph);
Line 426... Line 420...
426
 
420
 
427
 
421
 
428
 
422
 
-
 
423
void SetMailBoxStatus(dword percent1, text1)
429
void SetMailBoxStatus(dword percent1, text1)
424
{
430
{
425
	DrawProgressBar(3, Form.cheight -status_bar_h + 1, 220, 12, sc.work, 0xC3C3C3, 0x54B1D6, sc.work_text, percent1, text1);
Line 431... Line 426...
431
	if (text1) WriteText(3, Form.cheight -status_bar_h + 3, 0x80, sc.work_text, text1);
426
	cur_st_percent = percent1;
Line 438... Line 433...
438
	aim = NULL;
433
	aim = NULL;
439
	mailstart = free(mailstart);
434
	mailstart = free(mailstart);
440
	to = from = date = subj = cur_charset = NULL;
435
	to = from = date = subj = cur_charset = NULL;
441
}
436
}
Line 442... Line -...
442
 
-
 
443
int GetMailCount(){
-
 
444
	char tmpbuf4[512];
-
 
445
	strcpyb(#immbuffer, #tmpbuf4, "+OK ", " ");
-
 
446
	return atoi(#tmpbuf4);
-
 
447
}
-
 
448
 
437
 
449
int GetLetterSize_(int number)
438
int GetLetterSize_(int number)
450
{
439
{
451
   char search_num[24];
440
   char search_num[24];
452
   char mailsize1[24];
441
   char mailsize1[24];