liza 0.9c

git-svn-id: svn://kolibrios.org@4164 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2013-11-04 21:40:13 +00:00
parent 415044a6e8
commit dc003af096
5 changed files with 142 additions and 150 deletions

View File

@ -0,0 +1,61 @@
char from[256];
char to[256];
char date[256];
char subj[256];
dword mdata;
struct letter_attr
{
char adress[sizeof(to)];
char subject[sizeof(subj)];
byte direction;
int size;
void CreateArray();
void SetSizes();
void SetAtrFromCurr(int N);
int GetSize(int N);
char GetDirection(int N);
dword GetSubject(int N);
dword GetAdress(int N);
};
letter_attr atr;
dword mails_db;
void letter_attr::CreateArray()
{
free(mails_db);
mails_db = malloc( mail_list.count * sizeof(atr) );
}
void letter_attr::SetSizes()
{
int i;
for (i=1; i < mail_list.count; i++)
{
ESDWORD[sizeof(atr)*i+#mails_db+#atr.size-#atr] = GetLetterSize_(i);
ESDWORD[sizeof(atr)*i+#mails_db+#atr.subject-#atr] = ' ';
ESDWORD[sizeof(atr)*i+#mails_db+#atr.subject-#atr+1] = '\0';
}
}
void letter_attr::SetAtrFromCurr(int N)
{
byte mail_direction=0;
if (strstri(#to, #email_text))
{
mail_direction = 1;
strcpy(sizeof(atr)*N+#mails_db+#atr.adress-#atr, #from);
}
if (strstri(#from, #email_text))
{
mail_direction = 2;
strcpy(sizeof(atr)*N+#mails_db+#atr.adress-#atr, #to);
}
ESBYTE[sizeof(atr)*N+#mails_db+#atr.direction-#atr] = mail_direction;
strcpy(sizeof(atr)*N+#mails_db+#atr.subject-#atr, #subj);
}
int letter_attr::GetSize(int N) { return ESDWORD[sizeof(atr)*N+#mails_db+#atr.size-#atr]; }
char letter_attr::GetDirection(int N) { return ESBYTE[sizeof(atr)*N+#mails_db+#atr.direction-#atr]; }
dword letter_attr::GetSubject(int N) { return sizeof(atr)*N+#mails_db+#atr.subject-#atr; }
dword letter_attr::GetAdress(int N) { return sizeof(atr)*N+#mails_db+#atr.adress-#atr; }

View File

@ -37,8 +37,7 @@ enum {
SEND_NSTAT, SEND_NSTAT,
GET_ANSWER_NSTAT, GET_ANSWER_NSTAT,
SEND_RETR, SEND_RETR,
GET_ANSWER_RETR, GET_ANSWER_RETR
FAILED
}; };
//WindowDefinitions //WindowDefinitions
@ -75,8 +74,12 @@ int ticks;
char immbuffer[BUFFERSIZE]; char immbuffer[BUFFERSIZE];
llist mail_list;
llist letter_view;
#include "settings.c" #include "settings.c"
#include "login.c" #include "login.c"
#include "letter_attr.c"
#include "mail_box.c" #include "mail_box.c"
#include "parselist.c" #include "parselist.c"
@ -114,7 +117,8 @@ void OpenMailDat()
ReadFile(0, 512, #read_data, "/sys/network/mail.dat"); ReadFile(0, 512, #read_data, "/sys/network/mail.dat");
if (!read_data) if (!read_data)
{ {
strcpy(#email_text, "example@mail.com"); strcpy(#email_text, "testliza@ya.ru"); //temporarily, for testing
strcpy(#pass_text, "kolibri");
} }
else else
{ {

View File

@ -12,13 +12,19 @@ unsigned char pass_text[32];
edit_box login_box= {PANEL_W-6,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(email_text)+2,#email_text,#mouse_dd,0b10}; edit_box login_box= {PANEL_W-6,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(email_text)+2,#email_text,#mouse_dd,0b10};
edit_box pass_box= {PANEL_W-6,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(pass_text)+2,#pass_text,#mouse_dd,0b1}; edit_box pass_box= {PANEL_W-6,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(pass_text)+2,#pass_text,#mouse_dd,0b1};
void StopConnect(dword message)
{
if (message) notify(message);
aim = STOP;
}
void LoginBoxLoop() void LoginBoxLoop()
{ {
int key, id; int key, id;
char socket_char; char socket_char;
SetLoginStatus(NULL,NULL); SetLoginStatus(NULL);
goto _LB_DRAW; goto _LB_DRAW;
loop() loop()
@ -27,7 +33,7 @@ void LoginBoxLoop()
switch(EAX & 0xFF) switch(EAX & 0xFF)
{ {
case evMouse: case evMouse:
IF (GetProcessSlot(Form.ID)-GetActiveProcess()!=0) break; if (!CheckActiveProcess(Form.ID)) break;
edit_box_mouse stdcall (#login_box); edit_box_mouse stdcall (#login_box);
edit_box_mouse stdcall (#pass_box); edit_box_mouse stdcall (#pass_box);
break; break;
@ -35,12 +41,11 @@ void LoginBoxLoop()
case evButton: case evButton:
id = GetButtonID(); id = GetButtonID();
if (id==1) SaveAndExit(); if (id==1) SaveAndExit();
if (id==11) OptionsLoop(); if (id==11) SettingsDialog();
if (id==12) if (id==12)
{ {
if (!aim) aim=RESOLVE; else aim=NULL; if (!aim) aim=RESOLVE; else aim=NULL;
GetSettings(); GetSettings();
SetLoginStatus(NULL, NULL);
DrawLoginScreen(); DrawLoginScreen();
} }
break; break;
@ -57,12 +62,10 @@ void LoginBoxLoop()
edit_box_draw stdcall(#pass_box); edit_box_draw stdcall(#pass_box);
break; break;
} }
if (key==13) if (key==13) && (!aim)
{ {
if (aim) break;
aim=RESOLVE; aim=RESOLVE;
GetSettings(); GetSettings();
SetLoginStatus(NULL, NULL);
DrawLoginScreen(); DrawLoginScreen();
} }
EAX=key<<8; EAX=key<<8;
@ -76,128 +79,110 @@ void LoginBoxLoop()
break; break;
default: default:
if (!aim) { SetLoginStatus(NULL, NULL); break; } if (!aim) break;
if (!email_text) { notify("Enter email!"); aim=NULL; } if (!email_text) StopConnect("Enter email!");
if (!pass_text) { notify("Enter password!"); aim=NULL; } if (!pass_text) StopConnect("Enter password!");
if ((!login) || (!POP_server_path)) { notify("Email should be such as username@somesite.com"); aim=NULL; } if ((!login) || (!POP_server_path)) StopConnect("Email should be such as username@somesite.com");
if (aim == RESOLVE) if (aim == RESOLVE)
{ {
SetLoginStatus(1, "Resolving server address...");
sockaddr.sin_family = AF_INET4; sockaddr.sin_family = AF_INET4;
AX = POP_server_port; AX = POP_server_port;
$xchg al, ah $xchg al, ah
sockaddr.sin_port = AX; sockaddr.sin_port = AX;
sockaddr.sin_addr = GetIPfromAdress(#POP_server_path); sockaddr.sin_addr = GetIPfromAdress(#POP_server_path);
if (!sockaddr.sin_addr) { SetLoginStatus(12, "Can't obtain server IP."); aim = FAILED; break;} if (!sockaddr.sin_addr) { StopConnect("Can't obtain server IP."); break;}
aim = OPEN_CONNECTION; aim = OPEN_CONNECTION;
break;
} }
if (aim == OPEN_CONNECTION) if (aim == OPEN_CONNECTION)
{ {
SetLoginStatus(1, "Connecting to server...");
socketnum = Socket(AF_INET4, SOCK_STREAM, 0); socketnum = Socket(AF_INET4, SOCK_STREAM, 0);
if (socketnum == 0xffffffff) { SetLoginStatus(13, "Cannot open socket."); aim = FAILED; break;} if (socketnum == 0xffffffff) { StopConnect("Cannot open socket."); break;}
Connect(socketnum, #sockaddr, 16); Connect(socketnum, #sockaddr, 16);
SetLoginStatus(55, "Connection established. Waiting for answer...");
aim = GET_ANSWER_CONNECT; aim = GET_ANSWER_CONNECT;
break;
} }
if (aim == GET_ANSWER_CONNECT) if (aim == GET_ANSWER_CONNECT)
{ {
ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0); ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
if ((ticks == 0xffffff) || (ticks < 2)) { SetLoginStatus(61, "Connection failed"); aim = FAILED; break;} if ((ticks == 0xffffff) || (ticks < 2)) { StopConnect("Connection failed"); break;}
immbuffer[ticks]='\0'; immbuffer[ticks]='\0';
if (immbuffer[ticks-2]=='\n') if (immbuffer[ticks-2]=='\n')
{ {
debug(#immbuffer);
if (strstr(#immbuffer,"+OK")) if (strstr(#immbuffer,"+OK"))
{
SetLoginStatus(60, "Verifying username...");
aim = SEND_USER; aim = SEND_USER;
}
else else
{ StopConnect("Failed to connect to server. Retry...");
//aim=NULL; //may don't need retry?
SetLoginStatus(55, "Failed to connect to server. Retry...");
}
}
else
{
SetLoginStatus(103, "Connection failed");
} }
} }
if (aim == SEND_USER) if (aim == SEND_USER)
{ {
request_len = GetRequest("USER", #login); request_len = GetRequest("USER", #login);
Send(socketnum, #request, request_len, 0); if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
if (EAX == 0xffffffff) { SetLoginStatus(60, "Failed to send USER. Retry..."); break;} {
SetLoginStatus(70, "Login verifying..."); SetLoginStatus("Failed to send USER. Retry...");
debug("Send USER, awaiting answer..."); break;
}
aim = GET_ANSWER_USER; aim = GET_ANSWER_USER;
} }
if (aim == GET_ANSWER_USER) if (aim == GET_ANSWER_USER)
{ {
ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0); ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
if ((ticks == 0xffffffff) || (ticks < 2)) { SetLoginStatus(81, "Connection failed"); break;} if ((ticks == 0xffffffff) || (ticks < 2)) { SetLoginStatus("Connection failed"); break;}
immbuffer[ticks]='\0'; immbuffer[ticks]='\0';
if (immbuffer[ticks-2]=='\n') if (immbuffer[ticks-2]=='\n')
{ {
debug("GOT::");
debug(#immbuffer);
if (strstr(#immbuffer,"+OK")) if (strstr(#immbuffer,"+OK"))
{ aim = SEND_PASS; SetLoginStatus(80, "Verifying password...");} aim = SEND_PASS;
else else
{ notify("Wrong username"); aim=NULL;} {
debug(#immbuffer);
StopConnect("Wrong username");
}
} }
else else
{ {
SetLoginStatus(103, "Connection failed"); StopConnect("Connection failed");
} }
} }
if (aim == SEND_PASS) if (aim == SEND_PASS)
{ {
debug("\n Send PASS, awaiting answer...");
request_len = GetRequest("PASS", #pass_text); request_len = GetRequest("PASS", #pass_text);
Send(socketnum, #request, request_len, 0); if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
if (EAX == 0xffffffff) { SetLoginStatus(80, "Failed to send PASS. Retry..."); break;} {
SetLoginStatus("Failed to send PASS. Retry...");
break;
}
aim = GET_ANSWER_PASS; aim = GET_ANSWER_PASS;
} }
if (aim == GET_ANSWER_PASS) if (aim == GET_ANSWER_PASS)
{ {
ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0); ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
if ((ticks == 0xffffff) || (ticks < 2)) { SetLoginStatus(101, "Server disconnected"); break;} if ((ticks == 0xffffff) || (ticks < 2)) { SetLoginStatus("Server disconnected"); break;}
immbuffer[ticks]='\0'; immbuffer[ticks]='\0';
if (immbuffer[ticks-2]=='\n') if (immbuffer[ticks-2]=='\n')
{ {
debug("GOT::"); if (strstr(#immbuffer,"+OK")) MailBoxLoop();
else
{
StopConnect("Wrong password or POP3 disabled");
debug(#immbuffer); debug(#immbuffer);
if (strstr(#immbuffer,"+OK"))
{
SetLoginStatus(100, "Entering mailbox...");
aim=SEND_NSTAT;
MailBoxLoop();
}
else
{
notify("Wrong password");
aim=NULL;
} }
} }
else else
{ {
SetLoginStatus(103, "Connection failed"); StopConnect("Connection failed");
} }
} }
@ -207,6 +192,7 @@ void LoginBoxLoop()
} }
void DrawLoginScreen() void DrawLoginScreen()
{ {
panel_x = Form.cwidth - PANEL_W /2; panel_x = Form.cwidth - PANEL_W /2;
@ -237,7 +223,7 @@ void DrawLoginScreen()
} }
else DrawCaptButton(panel_x+120,panel_y+90,100,20,12,sc.work_button, sc.work_button_text,"Stop"); else DrawCaptButton(panel_x+120,panel_y+90,100,20,12,sc.work_button, sc.work_button_text,"Stop");
SetLoginStatus(cur_st_percent, cur_st_text); SetLoginStatus(cur_st_text);
} }
@ -271,24 +257,21 @@ void GetServerPathAndLogin()
void GetSettings() void GetSettings()
{ {
GetServerPathAndLogin(); //get GetServerPathAndLogin();
if (checked[CUSTOM]) if (checked[CUSTOM])
{ {
if (!strcmp(#POP_server_path, "pop.gmail.com")) POP_server_port = 995; POP_server_port = DEFAULT_POP_PORT;
else POP_server_port = DEFAULT_POP_PORT;
} }
if (checked[MANUAL]) if (checked[MANUAL])
{ {
strcpy(#POP_server_path, #POP_server1); strcpy(#POP_server_path, #POP_server1);
POP_server_port = atoi(#POP_server_port1); POP_server_port = atoi(#POP_server_port1);
} }
debug(#POP_server_path); if (!strcmp(#POP_server_path, "pop.gmail.com")) StopConnect("Can't connect GMAIL servers. Not support SSL/TLS encryption");
debug(itoa(POP_server_port));
} }
void SetLoginStatus(dword percent1, text1) void SetLoginStatus(dword text1)
{ {
DrawProgressBar(10, Form.cheight-22, PANEL_W, 12, sc.work, sc.work_graph, 0x54B1D6, sc.work_text, percent1, text1); if (text1) WriteText(10, Form.cheight-22, 0x80, sc.work_text, text1);
cur_st_percent = percent1;
cur_st_text = text1; cur_st_text = text1;
} }

View File

@ -3,33 +3,10 @@
#define LIST_INFO_H 59 #define LIST_INFO_H 59
int status_bar_h = 15; int status_bar_h = 15;
llist mail_list;
llist letter_view;
scroll_bar scroll1 = { 17,200,210, LIST_INFO_H-3,18,0,115,15,0,0xCCCccc,0xD2CED0,0x555555,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1}; scroll_bar scroll1 = { 17,200,210, LIST_INFO_H-3,18,0,115,15,0,0xCCCccc,0xD2CED0,0x555555,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
scroll_bar scroll2 = { 17,200,210, LIST_INFO_H,18,0,115,15,0,0xCCCccc,0xD2CED0,0x555555,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1}; scroll_bar scroll2 = { 17,200,210, LIST_INFO_H,18,0,115,15,0,0xCCCccc,0xD2CED0,0x555555,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
char from[256];
char to[256];
char date[256];
char subj[256];
dword mdata;
struct letter_attr
{
char adress[sizeof(to)];
char subject[sizeof(subj)];
byte direction;
int size;
void CreateArray();
void SetSizes();
void SetAtrFromCurr(int N);
int GetSize(int N);
char GetDirection(int N);
dword GetSubject(int N);
dword GetAdress(int N);
};
letter_attr atr;
dword mails_db;
char *listbuffer; char *listbuffer;
char *listpointer; char *listpointer;
@ -63,6 +40,7 @@ void MailBoxLoop()
mail_list.ClearList(); mail_list.ClearList();
SetMailBoxStatus( NULL , NULL); SetMailBoxStatus( NULL , NULL);
cur_charset = 0; cur_charset = 0;
aim=SEND_NSTAT;
goto _MB_DRAW; goto _MB_DRAW;
@ -72,7 +50,7 @@ void MailBoxLoop()
switch(EAX & 0xFF) switch(EAX & 0xFF)
{ {
case evMouse: case evMouse:
IF (GetProcessSlot(Form.ID)-GetActiveProcess()!=0) break; IF (!CheckActiveProcess(Form.ID)) break;
m.get(); m.get();
if (!m.lkm) panels_drag=0; if (!m.lkm) panels_drag=0;
@ -110,6 +88,8 @@ void MailBoxLoop()
{ {
if (letter_view.MouseScroll(m.vert)) DrawLetter(); if (letter_view.MouseScroll(m.vert)) DrawLetter();
} }
//if (!m.lkm) && (menu.ProcessMouse(mm.x, mm.y)) &&
//if (!m.lkm) && if (menu.ProcessMouse(mm.x, mm.y)) DrawMenuList();
break; break;
case evButton: case evButton:
@ -182,7 +162,7 @@ void MailBoxLoop()
default: default:
if (aim == SEND_NSTAT) if (aim == SEND_NSTAT)
{ {
debug("Counting mail, awaiting answer..."); SetLoginStatus("Counting mail, awaiting answer...");
request_len = GetRequest("STAT", NULL); request_len = GetRequest("STAT", NULL);
Send(socketnum, #request, request_len, 0); Send(socketnum, #request, request_len, 0);
if (EAX == 0xffffffff) { debug("Error sending STAT. Retry..."w); break;} if (EAX == 0xffffffff) { debug("Error sending STAT. Retry..."w); break;}
@ -196,7 +176,6 @@ void MailBoxLoop()
if (immbuffer[ticks-2]=='\n') if (immbuffer[ticks-2]=='\n')
{ {
debug("GOT::");
debug(#immbuffer); debug(#immbuffer);
if (strstr(#immbuffer,"+OK")) if (strstr(#immbuffer,"+OK"))
{ {
@ -211,8 +190,7 @@ void MailBoxLoop()
} }
else else
{ {
notify("Sorry, can't recieve your mail"); StopConnect("Sorry, can't recieve your mail");
aim=NULL; //aim = SEND_NLIST;
} }
} }
} }
@ -252,37 +230,40 @@ void MailBoxLoop()
DrawMailBox(); DrawMailBox();
debug("Send RETR, awaiting answer..."); debug("Send RETR, awaiting answer...");
request_len = GetRequest("RETR", itoa(mail_list.current+1)); request_len = GetRequest("RETR", itoa(mail_list.current+1));
Send(socketnum, #request, request_len, 0); if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
if (EAX == 0xffffffff) { notify("Error while trying to get letter from server"); aim=NULL; break;} {
StopConnect("Error while trying to get letter from server");
free(mailbuffer); break;
}
letter_size = atr.GetSize(mail_list.current+1) + 1024; letter_size = atr.GetSize(mail_list.current+1) + 1024;
mailbuffer = malloc(letter_size); free(mailbuffer);
if (!mailbuffer) {debug("alloc error!"); aim=NULL; break;} if (!mailbuffer = malloc(letter_size))
{
debug("alloc error!");
aim=NULL;
break;
}
mailpointer = mailbuffer; mailpointer = mailbuffer;
aim = GET_ANSWER_RETR; aim = GET_ANSWER_RETR;
debugi(letter_size);
} }
if (aim == GET_ANSWER_RETR) if (aim == GET_ANSWER_RETR)
{ {
aim=NULL;
break;
ticks = Receive(socketnum, mailpointer, letter_size + mailbuffer - mailpointer , MSG_DONTWAIT); ticks = Receive(socketnum, mailpointer, letter_size + mailbuffer - mailpointer , MSG_DONTWAIT);
debugi(ticks);
if (ticks == 0xffffffff) break; if (ticks == 0xffffffff) break;
//debugi(EAX);
mailpointer = mailpointer + ticks; mailpointer = mailpointer + ticks;
//*mailpointer='\0';
//debug(mailbuffer);
if (!aim) continue; if (!aim) break;
if (letter_size + mailbuffer - mailpointer - 2 < 0) if (letter_size + mailbuffer - mailpointer - 2 < 0)
{ {
debug("Resizing buffer"); debug("Resizing buffer");
letter_size += 4096; letter_size += 4096;
mailbuffer = realloc(mailbuffer, letter_size); mailbuffer = realloc(mailbuffer, letter_size);
if (!mailbuffer) {debug("Realloc error!"); aim=NULL; break;} if (!mailbuffer) { StopConnect("Realloc error!"); break;}
} }
if (letter_size>9000) if (letter_size>9000)
@ -481,42 +462,5 @@ int GetLetterSize_(int number){
} }
void letter_attr::CreateArray()
{
free(mails_db);
mails_db = malloc( mail_list.count * sizeof(atr) );
}
void letter_attr::SetSizes()
{
int i;
for (i=1; i < mail_list.count; i++)
{
ESDWORD[sizeof(atr)*i+#mails_db+#atr.size-#atr] = GetLetterSize_(i);
ESDWORD[sizeof(atr)*i+#mails_db+#atr.subject-#atr] = ' ';
ESDWORD[sizeof(atr)*i+#mails_db+#atr.subject-#atr+1] = '\0';
}
}
void letter_attr::SetAtrFromCurr(int N)
{
byte mail_direction=0;
if (strstri(#to, #email_text))
{
mail_direction = 1;
strcpy(sizeof(atr)*N+#mails_db+#atr.adress-#atr, #from);
}
if (strstri(#from, #email_text))
{
mail_direction = 2;
strcpy(sizeof(atr)*N+#mails_db+#atr.adress-#atr, #to);
}
ESBYTE[sizeof(atr)*N+#mails_db+#atr.direction-#atr] = mail_direction;
strcpy(sizeof(atr)*N+#mails_db+#atr.subject-#atr, #subj);
}
int letter_attr::GetSize(int N) { return ESDWORD[sizeof(atr)*N+#mails_db+#atr.size-#atr]; }
char letter_attr::GetDirection(int N) { return ESBYTE[sizeof(atr)*N+#mails_db+#atr.direction-#atr]; }
dword letter_attr::GetSubject(int N) { return sizeof(atr)*N+#mails_db+#atr.subject-#atr; }
dword letter_attr::GetAdress(int N) { return sizeof(atr)*N+#mails_db+#atr.adress-#atr; }

View File

@ -18,7 +18,7 @@ edit_box SMTP_server_box = {210,190,140,0xffffff,0x94AECE,0xffc90E,0xfffff
edit_box SMTP_server_port_box = {210,190,165,0xffffff,0x94AECE,0xffc90E,0xffffff,0,5,#SMTP_server_port1,#mouse_opt,0b1000000000000000}; edit_box SMTP_server_port_box = {210,190,165,0xffffff,0x94AECE,0xffc90E,0xffffff,0,5,#SMTP_server_port1,#mouse_opt,0b1000000000000000};
void OptionsLoop() void SettingsDialog()
{ {
int key, id; int key, id;