Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 4168 → Rev 4169

/programs/cmm/liza/liza.c
45,9 → 45,9
#define WIN_H 440
#define WIN_MIN_W 500
#define WIN_MIN_H 380
#define LOGIN_HEADER "Login - Email client Liza 0.9e"
#define OPTIONS_HEADER "Options - Email client Liza 0.9e"
#define MAILBOX_HEADER "Mail Box - Email client Liza 0.9e"
#define LOGIN_HEADER "Login - Email client Liza 0.9.2"
#define OPTIONS_HEADER "Options - Email client Liza 0.9.2"
#define MAILBOX_HEADER "Mail Box - Email client Liza 0.9.2"
#define BUFFERSIZE 512
proc_info Form;
system_colors sc;
117,7 → 117,7
ReadFile(0, 512, #read_data, "/sys/network/mail.dat");
if (!read_data)
{
strcpy(#email_text, "testliza@ya.ru"); //temporarily, for testing
strcpy(#email_text, "testliza@ya.ru");
strcpy(#pass_text, "kolibri");
}
else
131,8 → 131,6
login_box.size = login_box.pos = strlen(#email_text);
}
 
 
 
void SaveAndExit()
{
char write_data[512], pass_b64[256];
145,6 → 143,7
ExitProcess();
}
 
 
int GetRequest(dword command, text)
{
strcpy(#request, command);
161,6 → 160,7
{
if (message) notify(message);
aim = STOP;
Close(socketnum);
}
 
stop:
/programs/cmm/liza/login.c
13,75 → 13,16
edit_box pass_box= {PANEL_W-6,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(pass_text)+2,#pass_text,#mouse_dd,0b1};
 
 
 
 
void LoginBoxLoop()
void LoginNetworkProcess()
{
int key, id;
char socket_char;
 
SetLoginStatus(NULL);
 
goto _LB_DRAW;
loop()
if (aim) switch(aim)
{
WaitEventTimeout(2);
switch(EAX & 0xFF)
{
case evMouse:
if (!CheckActiveProcess(Form.ID)) break;
edit_box_mouse stdcall (#login_box);
edit_box_mouse stdcall (#pass_box);
break;
case evButton:
id = GetButtonID();
if (id==1) SaveAndExit();
if (id==11) SettingsDialog();
if (id==12)
{
if (!aim) aim=RESOLVE; else aim=NULL;
GetSettings();
DrawLoginScreen();
}
break;
case evKey:
key = GetKey();
if (key==9)
{
if (login_box.flags & 0b10)
{ pass_box.flags = 0b11; login_box.flags = 0; }
else
{ pass_box.flags = 0b1; login_box.flags = 0b10; }
edit_box_draw stdcall(#login_box);
edit_box_draw stdcall(#pass_box);
break;
}
if (key==13) && (!aim)
{
aim=RESOLVE;
GetSettings();
DrawLoginScreen();
}
EAX=key<<8;
edit_box_key stdcall(#login_box);
edit_box_key stdcall(#pass_box);
break;
case evReDraw: _LB_DRAW:
if !(DefineWindow(LOGIN_HEADER)) break;
DrawLoginScreen();
break;
 
default:
if (!aim) break;
case RESOLVE:
if (!email_text) StopConnect("Enter email!");
if (!pass_text) StopConnect("Enter password!");
if ((!login) || (!POP_server_path)) StopConnect("Email should be such as username@somesite.com");
if (!aim) return;
if (aim == RESOLVE)
{
sockaddr.sin_family = AF_INET4;
AX = POP_server_port;
$xchg al, ah
88,26 → 29,18
sockaddr.sin_port = AX;
sockaddr.sin_addr = GetIPfromAdress(#POP_server_path);
if (!sockaddr.sin_addr) { StopConnect("Can't obtain server IP."); break;}
aim = OPEN_CONNECTION;
else aim = OPEN_CONNECTION;
break;
}
if (aim == OPEN_CONNECTION)
{
case OPEN_CONNECTION:
socketnum = Socket(AF_INET4, SOCK_STREAM, 0);
if (socketnum == 0xffffffff) { StopConnect("Cannot open socket."); break;}
Connect(socketnum, #sockaddr, 16);
aim = GET_ANSWER_CONNECT;
break;
}
 
if (aim == GET_ANSWER_CONNECT)
{
case GET_ANSWER_CONNECT:
ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
if ((ticks == 0xffffff) || (ticks < 2)) { StopConnect("Connection failed"); break;}
immbuffer[ticks]='\0';
if (immbuffer[ticks-2]=='\n')
{
if (strstr(#immbuffer,"+OK"))
115,10 → 48,8
else
StopConnect("Failed to connect to server. Retry...");
}
}
 
if (aim == SEND_USER)
{
break;
case SEND_USER:
request_len = GetRequest("USER", #login);
if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
{
125,15 → 56,12
SetLoginStatus("Failed to send USER. Retry...");
break;
}
aim = GET_ANSWER_USER;
}
 
if (aim == GET_ANSWER_USER)
{
else aim = GET_ANSWER_USER;
break;
case GET_ANSWER_USER:
ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
if ((ticks == 0xffffffff) || (ticks < 2)) { SetLoginStatus("Connection failed"); break;}
immbuffer[ticks]='\0';
if (immbuffer[ticks-2]=='\n')
{
if (strstr(#immbuffer,"+OK"))
148,10 → 76,8
{
StopConnect("Connection failed");
}
}
 
if (aim == SEND_PASS)
{
break;
case SEND_PASS:
request_len = GetRequest("PASS", #pass_text);
if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
{
158,11 → 84,9
SetLoginStatus("Failed to send PASS. Retry...");
break;
}
aim = GET_ANSWER_PASS;
}
 
if (aim == GET_ANSWER_PASS)
{
else aim = GET_ANSWER_PASS;
break;
case GET_ANSWER_PASS:
ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
if ((ticks == 0xffffff) || (ticks < 2)) { SetLoginStatus("Server disconnected"); break;}
immbuffer[ticks]='\0';
180,12 → 104,72
{
StopConnect("Connection failed");
}
}
}
 
void LoginBoxLoop()
{
int key, id;
 
SetLoginStatus(NULL);
goto _LB_DRAW;
loop()
{
WaitEventTimeout(2);
switch(EAX & 0xFF)
{
case evMouse:
if (!CheckActiveProcess(Form.ID)) break;
edit_box_mouse stdcall (#login_box);
edit_box_mouse stdcall (#pass_box);
break;
case evButton:
id = GetButtonID();
if (id==1) SaveAndExit();
if (id==11) SettingsDialog();
if (id==12)
{
if (!aim) aim=RESOLVE; else aim=NULL;
GetSettings();
DrawLoginScreen();
}
break;
case evKey:
key = GetKey();
if (key==9)
{
if (login_box.flags & 0b10)
{ pass_box.flags = 0b11; login_box.flags = 0; }
else
{ pass_box.flags = 0b1; login_box.flags = 0b10; }
edit_box_draw stdcall(#login_box);
edit_box_draw stdcall(#pass_box);
break;
}
if (key==13) && (!aim)
{
aim=RESOLVE;
GetSettings();
DrawLoginScreen();
}
EAX=key<<8;
edit_box_key stdcall(#login_box);
edit_box_key stdcall(#pass_box);
break;
case evReDraw: _LB_DRAW:
if !(DefineWindow(LOGIN_HEADER)) break;
DrawLoginScreen();
break;
 
default:
LoginNetworkProcess();
}
}
}
 
 
 
223,27 → 207,15
}
 
 
void GetServerPathAndLogin()
void GetSettings()
{
int i=strchr(#email_text,'@');
int at_pos = strchr(#email_text,'@');
strlcpy(#login, #email_text, at_pos-1);
POP_server_path=login=NULL;
 
if (i)
if (checked[CUSTOM])
{
strcpy(#POP_server_path, "pop.");
strcat(#POP_server_path, #email_text+i);
}
strcpy(#login, #email_text);
login[i-1]=NULL;
}
 
 
void GetSettings()
{
GetServerPathAndLogin();
if (checked[CUSTOM])
{
strcat(#POP_server_path, #email_text+at_pos);
POP_server_port = DEFAULT_POP_PORT;
}
if (checked[MANUAL])
/programs/cmm/liza/mail_box.c
27,7 → 27,118
CLOSE_CHANGE_CHARSET
};
 
void MailBoxNetworkProcess()
{
int load_persent;
if (aim) switch(aim)
{
case SEND_NSTAT:
SetLoginStatus("Counting mail, awaiting answer...");
request_len = GetRequest("STAT", NULL);
Send(socketnum, #request, request_len, 0);
if (EAX == 0xffffffff) { debug("Error sending STAT. Retry..."w); break;}
aim = GET_ANSWER_NSTAT;
break;
 
case GET_ANSWER_NSTAT:
ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
if ((ticks == 0xffffff) || (ticks < 2)) break;
if (immbuffer[ticks-2]=='\n')
{
debug(#immbuffer);
if (strstr(#immbuffer,"+OK"))
{
strcpyb(#immbuffer, #param, "+OK ", " ");
mail_list.count = atoi(#param);
free(listbuffer);
listbuffer = mem_Alloc(30*mail_list.count); //24* original
listpointer = listbuffer;
aim = SEND_NLIST;
debug("Receiving mail list...");
}
else
{
StopConnect("Sorry, can't recieve your mail");
}
}
break;
 
case SEND_NLIST:
WriteText(5, Form.cheight-11, 0x80, sc.work_text, "Send LIST, awaiting answer...");
request_len = GetRequest("LIST", NULL);
Send(socketnum, #request, request_len, 0);
if (EAX == 0xffffffff) {debug("Error while sending LIST. Retry..."); break;}
else aim = GET_ANSWER_NLIST;
break;
 
case GET_ANSWER_NLIST:
ticks = Receive(socketnum, listpointer, listbuffer + 30*mail_list.count - listpointer, MSG_DONTWAIT);
if (ticks == 0xffffffff) break;
listpointer = listpointer + ticks;
if (listpointer - listbuffer < 5) break;
if (strncmp(listpointer-5,"\n.\n",5)==0) // note that c-- assembles "\n.\n" to 0x0d, 0x0a, 0x2e, 0x0d, 0x0a
{
aim = SEND_RETR;
debug("Got mail list");
DrawMailBox();
*listpointer='\0';
atr.CreateArray();
atr.SetSizes();
}
break;
 
case SEND_RETR:
from = to = date = subj = cur_charset = NULL;
letter_view.ClearList();
DrawMailBox();
debug("Send RETR, awaiting answer...");
request_len = GetRequest("RETR", itoa(mail_list.current+1));
if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
{
StopConnect("Error while trying to get letter from server");
break;
}
mailsize = atr.GetSize(mail_list.current+1) + 1024;
free(mailstart);
if (!mailstart = malloc(mailsize))
{
debug("alloc error!");
aim=NULL;
break;
}
mailend = mailstart;
aim = GET_ANSWER_RETR;
case GET_ANSWER_RETR:
ticks = Receive(socketnum, mailend, mailsize + mailstart - mailend, MSG_DONTWAIT);
if (ticks == 0xffffffff) break;
mailend = mailend + ticks;
 
if (!aim) break;
 
if (mailsize + mailstart - mailend - 2 < 0)
{
debug("Resizing buffer");
mailsize += 4096;
mailstart = realloc(mailstart, mailsize);
if (!mailstart) { StopConnect("Realloc error!"); break;}
}
 
//if (mailsize>9000)
{
load_persent = mailend - mailstart * 100 ;
load_persent /= mailsize - 1024;
if (load_persent != cur_st_percent) SetMailBoxStatus( load_persent , NULL);
}
ParseMail();
}
}
 
 
void MailBoxLoop()
{
int key, id;
159,126 → 270,12
 
break;
default:
if (aim == SEND_NSTAT)
{
SetLoginStatus("Counting mail, awaiting answer...");
request_len = GetRequest("STAT", NULL);
Send(socketnum, #request, request_len, 0);
if (EAX == 0xffffffff) { debug("Error sending STAT. Retry..."w); break;}
aim = GET_ANSWER_NSTAT;
MailBoxNetworkProcess();
}
if (aim == GET_ANSWER_NSTAT)
{
ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
if ((ticks == 0xffffff) || (ticks < 2)) break;
if (immbuffer[ticks-2]=='\n')
{
debug(#immbuffer);
if (strstr(#immbuffer,"+OK"))
{
mail_list.count = GetMailCount();
free(listbuffer);
listbuffer = mem_Alloc(30*mail_list.count); //24* original
listpointer = listbuffer;
aim = SEND_NLIST;
debug("Receiving mail list...");
}
else
{
StopConnect("Sorry, can't recieve your mail");
}
}
}
 
if (aim == SEND_NLIST)
{
WriteText(5, Form.cheight-11, 0x80, sc.work_text, "Send LIST, awaiting answer...");
request_len = GetRequest("LIST", NULL);
Send(socketnum, #request, request_len, 0);
if (EAX == 0xffffffff) {debug("Error while sending LIST. Retry..."); break;}
aim = GET_ANSWER_NLIST;
}
 
if (aim == GET_ANSWER_NLIST)
{
ticks = Receive(socketnum, listpointer, listbuffer + 30*mail_list.count - listpointer, MSG_DONTWAIT);
if (ticks == 0xffffffff) break;
listpointer = listpointer + ticks;
if (listpointer - listbuffer < 5) break;
if (strncmp(listpointer-5,"\n.\n",5)==0) // note that c-- assembles "\n.\n" to 0x0d, 0x0a, 0x2e, 0x0d, 0x0a
{
aim = SEND_RETR;
debug("Got mail list");
DrawMailBox();
*listpointer='\0';
atr.CreateArray();
atr.SetSizes();
}
}
if (aim == SEND_RETR)
{
from = to = date = subj = cur_charset = NULL;
letter_view.ClearList();
DrawMailBox();
debug("Send RETR, awaiting answer...");
request_len = GetRequest("RETR", itoa(mail_list.current+1));
if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
{
StopConnect("Error while trying to get letter from server");
break;
}
mailsize = atr.GetSize(mail_list.current+1) + 1024;
free(mailstart);
if (!mailstart = malloc(mailsize))
{
debug("alloc error!");
aim=NULL;
break;
}
mailend = mailstart;
aim = GET_ANSWER_RETR;
}
if (aim == GET_ANSWER_RETR)
{
ticks = Receive(socketnum, mailend, mailsize + mailstart - mailend, MSG_DONTWAIT);
if (ticks == 0xffffffff) break;
mailend = mailend + ticks;
 
if (!aim) break;
 
if (mailsize + mailstart - mailend - 2 < 0)
{
debug("Resizing buffer");
mailsize += 4096;
mailstart = realloc(mailstart, mailsize);
if (!mailstart) { StopConnect("Realloc error!"); break;}
}
 
if (mailsize>9000)
{
id = mailend - mailstart * 100 ;
id /= mailsize - 1024;
if (id!=cur_st_percent) SetMailBoxStatus( id , NULL);
}
 
//debug(mailstart);
//pause(10);
//debug("======================");
ParseMail();
}
 
}
}
}
 
 
void DrawMailBox()
{
DrawMailList();
293,15 → 290,12
#define BUT_Y 7
#define BUT_H 22
#define BUT_W 74
#define BUT_SPACE 11
int toolbar_w = BUT_Y + BUT_H + BUT_Y + 3;
mail_list.SetSizes(0, toolbar_w, Form.cwidth - scroll1.size_x - 1, mail_list.h, 60,18);
 
DrawBar(0,0, Form.cwidth,toolbar_w-3, sc.work);
DrawCaptButton(10 , BUT_Y, BUT_W, BUT_H, GET_MAIL, sc.work_button, sc.work_button_text,"Get mail");
DrawCaptButton(BUT_W+BUT_SPACE + 10, BUT_Y, BUT_W, BUT_H, SEND_MAIL, sc.work_button, sc.work_button_text,"Send Email");
DrawCaptButton(BUT_W+BUT_SPACE*2 + 10, BUT_Y, BUT_W, BUT_H, DELETE_LETTER, sc.work_button, sc.work_button_text,"Delete");
DrawCaptButton(BUT_W+BUT_SPACE*3 + 10, BUT_Y, BUT_W, BUT_H, SAVE_LETTER, sc.work_button, sc.work_button_text,"Save");
DrawCaptButton(BUT_W+ 20, BUT_Y, BUT_W+10, BUT_H, SAVE_LETTER, sc.work_button, sc.work_button_text,"Save letter");
DrawCaptButton(Form.cwidth-BUT_W - 10, BUT_Y, BUT_W, BUT_H, EXIT_MAIL, sc.work_button, sc.work_button_text,"< Exit");
 
DrawBar(0, mail_list.y-3, mail_list.w,1, sc.work_graph);
428,7 → 422,8
 
void SetMailBoxStatus(dword percent1, text1)
{
if (text1) WriteText(3, Form.cheight -status_bar_h + 3, 0x80, sc.work_text, text1);
DrawProgressBar(3, Form.cheight -status_bar_h + 1, 220, 12, sc.work, 0xC3C3C3, 0x54B1D6, sc.work_text, percent1, text1);
cur_st_percent = percent1;
cur_st_text = text1;
}
 
440,12 → 435,6
to = from = date = subj = cur_charset = NULL;
}
 
int GetMailCount(){
char tmpbuf4[512];
strcpyb(#immbuffer, #tmpbuf4, "+OK ", " ");
return atoi(#tmpbuf4);
}
 
int GetLetterSize_(int number)
{
char search_num[24];