forked from KolibriOS/kolibrios
Liza 0.9, works on new network stack.
git-svn-id: svn://kolibrios.org@4139 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
a6ab7fa13e
commit
4fe0afac2f
96
programs/cmm/lib/socket_new.h
Normal file
96
programs/cmm/lib/socket_new.h
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
#define SOCK_STREAM 1
|
||||||
|
#define SOCK_DGRAM 2
|
||||||
|
|
||||||
|
#define AF_INET4 2
|
||||||
|
|
||||||
|
#define MSG_PEEK 0x02
|
||||||
|
#define MSG_DONTWAIT 0x40
|
||||||
|
|
||||||
|
dword errorcode;
|
||||||
|
|
||||||
|
struct sockaddr_in{
|
||||||
|
word sin_family;
|
||||||
|
word sin_port;
|
||||||
|
dword sin_addr;
|
||||||
|
char padding[8];
|
||||||
|
};
|
||||||
|
|
||||||
|
inline fastcall dword Socket(ECX, EDX, ESI)
|
||||||
|
{
|
||||||
|
$push ebx
|
||||||
|
$mov eax, 75
|
||||||
|
$mov ebx, 0
|
||||||
|
$int 0x40
|
||||||
|
errorcode = EBX;
|
||||||
|
$pop ebx
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fastcall dword Close(ECX)
|
||||||
|
{
|
||||||
|
$push ebx
|
||||||
|
$mov eax, 75
|
||||||
|
$mov ebx, 1
|
||||||
|
$int 0x40
|
||||||
|
errorcode = EBX;
|
||||||
|
$pop ebx
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fastcall dword Bind(ECX, EDX, ESI)
|
||||||
|
{
|
||||||
|
$push ebx
|
||||||
|
$mov eax, 75
|
||||||
|
$mov ebx, 2
|
||||||
|
$int 0x40
|
||||||
|
errorcode = EBX;
|
||||||
|
$pop ebx
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fastcall dword Listen(ECX, EDX)
|
||||||
|
{
|
||||||
|
$push ebx
|
||||||
|
$mov eax, 75
|
||||||
|
$mov ebx, 3
|
||||||
|
$int 0x40
|
||||||
|
errorcode = EBX;
|
||||||
|
$pop ebx
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fastcall dword Connect(ECX, EDX, ESI)
|
||||||
|
{
|
||||||
|
$push ebx
|
||||||
|
$mov eax, 75
|
||||||
|
$mov ebx, 4
|
||||||
|
$int 0x40
|
||||||
|
errorcode = EBX;
|
||||||
|
$pop ebx
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fastcall dword Accept(ECX, EDX, ESI)
|
||||||
|
{
|
||||||
|
$push ebx
|
||||||
|
$mov eax, 75
|
||||||
|
$mov ebx, 5
|
||||||
|
$int 0x40
|
||||||
|
errorcode = EBX;
|
||||||
|
$pop ebx
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fastcall dword Send(ECX, EDX, ESI, EDI)
|
||||||
|
{
|
||||||
|
$push ebx
|
||||||
|
$mov eax, 75
|
||||||
|
$mov ebx, 6
|
||||||
|
$int 0x40
|
||||||
|
errorcode = EBX;
|
||||||
|
$pop ebx
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fastcall dword Receive(ECX, EDX, ESI, EDI)
|
||||||
|
{
|
||||||
|
$push ebx
|
||||||
|
$mov eax, 75
|
||||||
|
$mov ebx, 7
|
||||||
|
$int 0x40
|
||||||
|
errorcode = EBX;
|
||||||
|
$pop ebx
|
||||||
|
}
|
@ -10,7 +10,7 @@
|
|||||||
#include "..\lib\figures.h"
|
#include "..\lib\figures.h"
|
||||||
#include "..\lib\file_system.h"
|
#include "..\lib\file_system.h"
|
||||||
#include "..\lib\list_box.h"
|
#include "..\lib\list_box.h"
|
||||||
#include "..\lib\socket.h"
|
#include "..\lib\socket_new.h"
|
||||||
//*.obj libraries
|
//*.obj libraries
|
||||||
#include "..\lib\lib.obj\box_lib.h"
|
#include "..\lib\lib.obj\box_lib.h"
|
||||||
#include "..\lib\lib.obj\network.h"
|
#include "..\lib\lib.obj\network.h"
|
||||||
@ -24,10 +24,8 @@ byte in_out_mail[18*36] = FROM "in_out_mail.raw";
|
|||||||
//connection algorithm
|
//connection algorithm
|
||||||
enum {
|
enum {
|
||||||
STOP,
|
STOP,
|
||||||
GET_PORT,
|
RESOLVE,
|
||||||
GET_SERVER_IP,
|
OPEN_CONNECTION,
|
||||||
GET_SOCKET,
|
|
||||||
CONNECT,
|
|
||||||
GET_ANSWER_CONNECT,
|
GET_ANSWER_CONNECT,
|
||||||
SEND_USER,
|
SEND_USER,
|
||||||
GET_ANSWER_USER,
|
GET_ANSWER_USER,
|
||||||
@ -38,7 +36,8 @@ enum {
|
|||||||
SEND_NSTAT,
|
SEND_NSTAT,
|
||||||
GET_ANSWER_NSTAT,
|
GET_ANSWER_NSTAT,
|
||||||
SEND_RETR,
|
SEND_RETR,
|
||||||
GET_ANSWER_RETR
|
GET_ANSWER_RETR,
|
||||||
|
FAILED
|
||||||
};
|
};
|
||||||
|
|
||||||
//WindowDefinitions
|
//WindowDefinitions
|
||||||
@ -46,9 +45,10 @@ enum {
|
|||||||
#define WIN_H 440
|
#define WIN_H 440
|
||||||
#define WIN_MIN_W 500
|
#define WIN_MIN_W 500
|
||||||
#define WIN_MIN_H 380
|
#define WIN_MIN_H 380
|
||||||
#define LOGIN_HEADER "Login - Email client Liza 0.8a"
|
#define LOGIN_HEADER "Login - Email client Liza 0.9"
|
||||||
#define OPTIONS_HEADER "Options - Email client Liza 0.8a"
|
#define OPTIONS_HEADER "Options - Email client Liza 0.9"
|
||||||
#define MAILBOX_HEADER "Mail Box - Email client Liza 0.8a"
|
#define MAILBOX_HEADER "Mail Box - Email client Liza 0.9"
|
||||||
|
#define BUFFERSIZE 512
|
||||||
proc_info Form;
|
proc_info Form;
|
||||||
system_colors sc;
|
system_colors sc;
|
||||||
#define LBUMP 0xFFFfff
|
#define LBUMP 0xFFFfff
|
||||||
@ -59,34 +59,20 @@ dword cur_st_text;
|
|||||||
|
|
||||||
//connection data
|
//connection data
|
||||||
#define DEFAULT_POP_PORT 110;
|
#define DEFAULT_POP_PORT 110;
|
||||||
dword local_port=1000;
|
|
||||||
char POP_server_path[128];
|
char POP_server_path[128];
|
||||||
dword POP_server_IP;
|
|
||||||
dword POP_server_port;
|
dword POP_server_port;
|
||||||
char login[128];
|
char login[128];
|
||||||
char request[256+22];
|
char request[256+22];
|
||||||
int request_len;
|
int request_len;
|
||||||
char connection_status;
|
char connection_status;
|
||||||
dword socket;
|
dword socketnum;
|
||||||
|
|
||||||
|
sockaddr_in sockaddr;
|
||||||
|
|
||||||
int aim;
|
int aim;
|
||||||
int ticks;
|
int ticks;
|
||||||
|
|
||||||
//global data for server response
|
char immbuffer[BUFFERSIZE];
|
||||||
char immbuffer[512];
|
|
||||||
int immpointer;
|
|
||||||
|
|
||||||
void immfree(){
|
|
||||||
immpointer=0;
|
|
||||||
immbuffer[immpointer]='\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
void immputc(char agot_char){
|
|
||||||
immbuffer[immpointer]=agot_char;
|
|
||||||
immpointer++;
|
|
||||||
immbuffer[immpointer]='\0';
|
|
||||||
if (immpointer>511) {immpointer=0; debug ("IMM BUFFER OVERFLOW ERROR"); aim=NULL;}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "settings.c"
|
#include "settings.c"
|
||||||
#include "login.c"
|
#include "login.c"
|
||||||
@ -127,9 +113,7 @@ 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, "eiroglif@yandex.ru"); //temporarily, for testing
|
|
||||||
strcpy(#email_text, "example@mail.com");
|
strcpy(#email_text, "example@mail.com");
|
||||||
//strcpy(#pass_text, "rostov");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -147,7 +131,7 @@ void OpenMailDat()
|
|||||||
void SaveAndExit()
|
void SaveAndExit()
|
||||||
{
|
{
|
||||||
char write_data[512], pass_b64[256];
|
char write_data[512], pass_b64[256];
|
||||||
CloseSocket(socket);
|
Close(socketnum);
|
||||||
strcpy(#write_data, #email_text);
|
strcpy(#write_data, #email_text);
|
||||||
strcat(#write_data, "\n");
|
strcat(#write_data, "\n");
|
||||||
base64_encode stdcall (#pass_text, #pass_b64, strlen(#pass_text));
|
base64_encode stdcall (#pass_text, #pass_b64, strlen(#pass_text));
|
||||||
|
@ -38,7 +38,7 @@ void LoginBoxLoop()
|
|||||||
if (id==11) OptionsLoop();
|
if (id==11) OptionsLoop();
|
||||||
if (id==12)
|
if (id==12)
|
||||||
{
|
{
|
||||||
if (!aim) aim=GET_PORT; else aim=NULL;
|
if (!aim) aim=RESOLVE; else aim=NULL;
|
||||||
GetSettings();
|
GetSettings();
|
||||||
SetLoginStatus(NULL, NULL);
|
SetLoginStatus(NULL, NULL);
|
||||||
DrawLoginScreen();
|
DrawLoginScreen();
|
||||||
@ -60,7 +60,7 @@ void LoginBoxLoop()
|
|||||||
if (key==13)
|
if (key==13)
|
||||||
{
|
{
|
||||||
if (aim) break;
|
if (aim) break;
|
||||||
aim=GET_PORT;
|
aim=RESOLVE;
|
||||||
GetSettings();
|
GetSettings();
|
||||||
SetLoginStatus(NULL, NULL);
|
SetLoginStatus(NULL, NULL);
|
||||||
DrawLoginScreen();
|
DrawLoginScreen();
|
||||||
@ -81,70 +81,62 @@ void LoginBoxLoop()
|
|||||||
if (!pass_text) { notify("Enter password!"); aim=NULL; }
|
if (!pass_text) { notify("Enter password!"); aim=NULL; }
|
||||||
if ((!login) || (!POP_server_path)) { notify("Email should be such as username@somesite.com"); aim=NULL; }
|
if ((!login) || (!POP_server_path)) { notify("Email should be such as username@somesite.com"); aim=NULL; }
|
||||||
|
|
||||||
if (aim == GET_PORT)
|
if (aim == RESOLVE)
|
||||||
{
|
{
|
||||||
SetLoginStatus(5, "Search for free local port...");
|
SetLoginStatus(1, "Resolving server address...");
|
||||||
local_port = GetFreePort(1000);
|
|
||||||
if (!local_port) { notify("Error: There is no free local ports"); aim=NULL; break;}
|
sockaddr.sin_family = AF_INET4;
|
||||||
SetLoginStatus(12, "Obtain server IP...");
|
AX = POP_server_port;
|
||||||
aim = GET_SERVER_IP;
|
$xchg al, ah
|
||||||
|
sockaddr.sin_port = AX;
|
||||||
|
sockaddr.sin_addr = GetIPfromAdress(#POP_server_path);
|
||||||
|
if (!sockaddr.sin_addr) { SetLoginStatus(12, "Can't obtain server IP."); aim = FAILED; break;}
|
||||||
|
|
||||||
|
aim = OPEN_CONNECTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aim == GET_SERVER_IP)
|
if (aim == OPEN_CONNECTION)
|
||||||
{
|
{
|
||||||
POP_server_IP = GetIPfromAdress(#POP_server_path);
|
SetLoginStatus(1, "Connecting to server...");
|
||||||
if (!POP_server_IP) { SetLoginStatus(12, "Can't obtain server IP. Retry..."); break; }
|
|
||||||
SetLoginStatus(25, "Obtain to open socket..."w);
|
|
||||||
aim = GET_SOCKET;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (aim == GET_SOCKET)
|
socketnum = Socket(AF_INET4, SOCK_STREAM, 0);
|
||||||
{
|
if (socketnum == 0xffffffff) { SetLoginStatus(13, "Cannot open socket."); aim = FAILED; break;}
|
||||||
socket = OpenSocket(local_port, POP_server_port, POP_server_IP, SOCKET_ACTIVE);
|
Connect(socketnum, #sockaddr, 16);
|
||||||
if (socket == 0xffffffff) { SetLoginStatus(25, "Error obtaining socket. Retry..."); break;}
|
SetLoginStatus(55, "Connection established. Waiting for answer...");
|
||||||
SetLoginStatus(40, "Establish a connection...");
|
|
||||||
aim = CONNECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (aim == CONNECT)
|
|
||||||
{
|
|
||||||
connection_status=StatusSocket(socket);
|
|
||||||
if (connection_status==0) {notify("Connection to server isn't possible"); aim=NULL; break; };
|
|
||||||
if (connection_status==7) {SetLoginStatus(40, "Server disconnected. Retry..."); break; };
|
|
||||||
if (connection_status!=4) break; //0-connection isn't possible, 2-connecting, 4-connected, 7-server disconnected
|
|
||||||
SetLoginStatus(55, "Connection established. Reading answer...");
|
|
||||||
immfree();
|
|
||||||
aim = GET_ANSWER_CONNECT;
|
aim = GET_ANSWER_CONNECT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (aim == GET_ANSWER_CONNECT)
|
if (aim == GET_ANSWER_CONNECT)
|
||||||
{
|
{
|
||||||
if (!PollSocket(socket)) break;
|
ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
|
||||||
socket_char=ReadSocket(socket);
|
if ((ticks == 0xffffff) || (ticks < 2)) { SetLoginStatus(61, "Connection failed"); aim = FAILED; break;}
|
||||||
immputc(socket_char);
|
immbuffer[ticks]='\0';
|
||||||
|
|
||||||
if (socket_char=='\n')
|
if (immbuffer[ticks-2]=='\n')
|
||||||
{
|
{
|
||||||
debug(#immbuffer);
|
debug(#immbuffer);
|
||||||
if (strstr(#immbuffer,"+OK"))
|
if (strstr(#immbuffer,"+OK"))
|
||||||
{
|
{
|
||||||
SetLoginStatus(60, "Verifying username...");
|
SetLoginStatus(60, "Verifying username...");
|
||||||
aim = SEND_USER;
|
aim = SEND_USER;
|
||||||
immfree();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
immfree();
|
|
||||||
//aim=NULL; //may don't need retry?
|
//aim=NULL; //may don't need retry?
|
||||||
SetLoginStatus(55, "Failed to connect to server. 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);
|
||||||
WriteSocket(socket,request_len,#request);
|
Send(socketnum, #request, request_len, 0);
|
||||||
if (EAX == 0xffffffff) { SetLoginStatus(60, "Failed to send USER. Retry..."); break;}
|
if (EAX == 0xffffffff) { SetLoginStatus(60, "Failed to send USER. Retry..."); break;}
|
||||||
SetLoginStatus(70, "Login verifying...");
|
SetLoginStatus(70, "Login verifying...");
|
||||||
debug("Send USER, awaiting answer...");
|
debug("Send USER, awaiting answer...");
|
||||||
@ -153,18 +145,22 @@ void LoginBoxLoop()
|
|||||||
|
|
||||||
if (aim == GET_ANSWER_USER)
|
if (aim == GET_ANSWER_USER)
|
||||||
{
|
{
|
||||||
if (!PollSocket(socket)) break;
|
ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
|
||||||
socket_char=ReadSocket(socket);
|
if ((ticks == 0xffffffff) || (ticks < 2)) { SetLoginStatus(81, "Connection failed"); break;}
|
||||||
immputc(socket_char);
|
immbuffer[ticks]='\0';
|
||||||
|
|
||||||
if (socket_char=='\n')
|
if (immbuffer[ticks-2]=='\n')
|
||||||
{
|
{
|
||||||
debug("GOT::");
|
debug("GOT::");
|
||||||
debug(#immbuffer);
|
debug(#immbuffer);
|
||||||
if (strstr(#immbuffer,"+OK"))
|
if (strstr(#immbuffer,"+OK"))
|
||||||
{ aim = SEND_PASS; SetLoginStatus(80, "Verifying password..."); immfree(); }
|
{ aim = SEND_PASS; SetLoginStatus(80, "Verifying password...");}
|
||||||
else
|
else
|
||||||
{ notify("Wrong username"); immfree(); aim=NULL;}
|
{ notify("Wrong username"); aim=NULL;}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetLoginStatus(103, "Connection failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,18 +168,18 @@ void LoginBoxLoop()
|
|||||||
{
|
{
|
||||||
debug("\n Send PASS, awaiting answer...");
|
debug("\n Send PASS, awaiting answer...");
|
||||||
request_len = GetRequest("PASS", #pass_text);
|
request_len = GetRequest("PASS", #pass_text);
|
||||||
WriteSocket(socket,request_len,#request);
|
Send(socketnum, #request, request_len, 0);
|
||||||
if (EAX == 0xffffffff) { SetLoginStatus(80, "Failed to send PASS. Retry..."); break;}
|
if (EAX == 0xffffffff) { SetLoginStatus(80, "Failed to send PASS. Retry..."); break;}
|
||||||
aim = GET_ANSWER_PASS;
|
aim = GET_ANSWER_PASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aim == GET_ANSWER_PASS)
|
if (aim == GET_ANSWER_PASS)
|
||||||
{
|
{
|
||||||
if (!PollSocket(socket)) break;
|
ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
|
||||||
socket_char=ReadSocket(socket);
|
if ((ticks == 0xffffff) || (ticks < 2)) { SetLoginStatus(101, "Server disconnected"); break;}
|
||||||
immputc(socket_char);
|
immbuffer[ticks]='\0';
|
||||||
|
|
||||||
if (socket_char=='\n')
|
if (immbuffer[ticks-2]=='\n')
|
||||||
{
|
{
|
||||||
debug("GOT::");
|
debug("GOT::");
|
||||||
debug(#immbuffer);
|
debug(#immbuffer);
|
||||||
@ -191,16 +187,18 @@ void LoginBoxLoop()
|
|||||||
{
|
{
|
||||||
SetLoginStatus(100, "Entering mailbox...");
|
SetLoginStatus(100, "Entering mailbox...");
|
||||||
aim=SEND_NSTAT;
|
aim=SEND_NSTAT;
|
||||||
immfree();
|
|
||||||
MailBoxLoop();
|
MailBoxLoop();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
notify("Wrong password");
|
notify("Wrong password");
|
||||||
aim=NULL;
|
aim=NULL;
|
||||||
immfree();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetLoginStatus(103, "Connection failed");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ void MailBoxLoop()
|
|||||||
if (id==EXIT_MAIL)
|
if (id==EXIT_MAIL)
|
||||||
{
|
{
|
||||||
StopLoading();
|
StopLoading();
|
||||||
CloseSocket(socket);
|
Close(socketnum);
|
||||||
LoginBoxLoop();
|
LoginBoxLoop();
|
||||||
}
|
}
|
||||||
if (id==CHANGE_CHARSET)
|
if (id==CHANGE_CHARSET)
|
||||||
@ -208,18 +208,17 @@ void MailBoxLoop()
|
|||||||
{
|
{
|
||||||
debug("Counting mail, awaiting answer...");
|
debug("Counting mail, awaiting answer...");
|
||||||
request_len = GetRequest("STAT", NULL);
|
request_len = GetRequest("STAT", NULL);
|
||||||
WriteSocket(socket,request_len,#request);
|
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;}
|
||||||
aim = GET_ANSWER_NSTAT;
|
aim = GET_ANSWER_NSTAT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aim == GET_ANSWER_NSTAT)
|
if (aim == GET_ANSWER_NSTAT)
|
||||||
{
|
{
|
||||||
if (!PollSocket(socket)) break;
|
ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
|
||||||
socket_char=ReadSocket(socket);
|
if ((ticks == 0xffffff) || (ticks < 2)) break;
|
||||||
immputc(socket_char);
|
|
||||||
|
|
||||||
if (socket_char=='\n')
|
if (immbuffer[ticks-2]=='\n')
|
||||||
{
|
{
|
||||||
debug("GOT::");
|
debug("GOT::");
|
||||||
debug(#immbuffer);
|
debug(#immbuffer);
|
||||||
@ -232,13 +231,11 @@ void MailBoxLoop()
|
|||||||
listbuffer = mem_Alloc(30*mail_list.count); //24* original
|
listbuffer = mem_Alloc(30*mail_list.count); //24* original
|
||||||
listpointer = listbuffer;
|
listpointer = listbuffer;
|
||||||
aim = SEND_NLIST;
|
aim = SEND_NLIST;
|
||||||
debug("Recieving mail list...");
|
debug("Receiving mail list...");
|
||||||
immfree();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
notify("Sorry, can't recieve your mail");
|
notify("Sorry, can't recieve your mail");
|
||||||
immfree();
|
|
||||||
aim=NULL; //aim = SEND_NLIST;
|
aim=NULL; //aim = SEND_NLIST;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -248,21 +245,19 @@ void MailBoxLoop()
|
|||||||
{
|
{
|
||||||
WriteText(5, Form.cheight-11, 0x80, sc.work_text, "Send LIST, awaiting answer...");
|
WriteText(5, Form.cheight-11, 0x80, sc.work_text, "Send LIST, awaiting answer...");
|
||||||
request_len = GetRequest("LIST", NULL);
|
request_len = GetRequest("LIST", NULL);
|
||||||
WriteSocket(socket,request_len,#request);
|
Send(socketnum, #request, request_len, 0);
|
||||||
if (EAX == 0xffffffff) {debug("Error while sending LIST. Retry..."); break;}
|
if (EAX == 0xffffffff) {debug("Error while sending LIST. Retry..."); break;}
|
||||||
aim = GET_ANSWER_NLIST;
|
aim = GET_ANSWER_NLIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aim == GET_ANSWER_NLIST)
|
if (aim == GET_ANSWER_NLIST)
|
||||||
{
|
{
|
||||||
ticks = PollSocket(socket);
|
ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
|
||||||
if (!ticks) break;
|
if ((ticks == 0xffffffff) || (ticks < 3)) break;
|
||||||
for (;ticks>0;ticks--)
|
|
||||||
{
|
|
||||||
socket_char=ReadSocket(socket);
|
|
||||||
listputc(socket_char);
|
|
||||||
|
|
||||||
if (socket_char=='.') //this way of checking end of message IS BAD
|
//for (;ticks>0;ticks--)
|
||||||
|
//{
|
||||||
|
if (immbuffer[ticks-3]=='.') //this way of checking end of message IS BAD
|
||||||
{
|
{
|
||||||
aim = SEND_RETR;
|
aim = SEND_RETR;
|
||||||
debug("Got mail list");
|
debug("Got mail list");
|
||||||
@ -271,8 +266,9 @@ void MailBoxLoop()
|
|||||||
atr.CreateArray();
|
atr.CreateArray();
|
||||||
atr.SetSizes();
|
atr.SetSizes();
|
||||||
}
|
}
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (aim == SEND_RETR)
|
if (aim == SEND_RETR)
|
||||||
{
|
{
|
||||||
from = to = date = subj = cur_charset = NULL;
|
from = to = date = subj = cur_charset = NULL;
|
||||||
@ -280,35 +276,36 @@ 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));
|
||||||
WriteSocket(socket,request_len,#request);
|
Send(socketnum, #request, request_len, 0);
|
||||||
if (EAX == 0xffffffff) { notify("Error while trying to get letter from server"); aim=NULL; break;}
|
if (EAX == 0xffffffff) { notify("Error while trying to get letter from server"); aim=NULL; break;}
|
||||||
|
|
||||||
mailbuffer = free(mailbuffer);
|
mailbuffer = free(mailbuffer);
|
||||||
letter_size = atr.GetSize(mail_list.current+1) + 1024;
|
letter_size = atr.GetSize(mail_list.current+1) + 1024;
|
||||||
mailbuffer = malloc(letter_size);
|
mailbuffer = malloc(letter_size);
|
||||||
|
if (!mailbuffer) {debug("alloc error!"); aim=NULL; break;}
|
||||||
mailpointer = mailbuffer;
|
mailpointer = mailbuffer;
|
||||||
aim = GET_ANSWER_RETR;
|
aim = GET_ANSWER_RETR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aim == GET_ANSWER_RETR)
|
if (aim == GET_ANSWER_RETR)
|
||||||
{
|
{
|
||||||
ticks=PollSocket(socket);
|
ticks = Receive(socketnum, mailpointer, letter_size + mailbuffer - mailpointer , MSG_DONTWAIT);
|
||||||
if (!ticks) break;
|
if (ticks == 0xffffffff) break;
|
||||||
|
if (ticks == 0) break;
|
||||||
|
//debugi(EAX);
|
||||||
|
|
||||||
|
mailpointer = mailpointer + ticks;
|
||||||
|
//*mailpointer='\0';
|
||||||
|
//debug(mailbuffer);
|
||||||
|
|
||||||
for (;ticks>0;ticks--)
|
|
||||||
{
|
|
||||||
socket_char=ReadSocket(socket);
|
|
||||||
//debugch(socket_char);
|
|
||||||
*mailpointer=socket_char;
|
|
||||||
mailpointer++;
|
|
||||||
*mailpointer='\0';
|
|
||||||
if (!aim) continue;
|
if (!aim) continue;
|
||||||
|
|
||||||
if (letter_size + mailbuffer - mailpointer - 2 < 0)
|
if (letter_size + mailbuffer - mailpointer - 2 < 0)
|
||||||
{
|
{
|
||||||
debug("Buffer overflow!!1 Realloc..."w);
|
debug("Resizing buffer");
|
||||||
letter_size += 4096;
|
letter_size += 4096;
|
||||||
mailbuffer = realloc(mailbuffer, letter_size);
|
mailbuffer = realloc(mailbuffer, letter_size);
|
||||||
if (!mailbuffer) {debug("Relloc error!"); aim=NULL; break;}
|
if (!mailbuffer) {debug("Realloc error!"); aim=NULL; break;}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (letter_size>9000)
|
if (letter_size>9000)
|
||||||
@ -318,8 +315,7 @@ void MailBoxLoop()
|
|||||||
if (id!=cur_st_percent) SetMailBoxStatus( id , NULL);
|
if (id!=cur_st_percent) SetMailBoxStatus( id , NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
ParceMail();
|
ParseMail();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -491,7 +487,6 @@ void StopLoading()
|
|||||||
aim = NULL;
|
aim = NULL;
|
||||||
mailbuffer = free(mailbuffer);
|
mailbuffer = free(mailbuffer);
|
||||||
to = from = date = subj = cur_charset = NULL;
|
to = from = date = subj = cur_charset = NULL;
|
||||||
while (PollSocket(socket)) ReadSocket(socket);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetMailCount(){
|
int GetMailCount(){
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
//Leency & SoUrcerer, LGPL
|
//Leency & SoUrcerer, LGPL
|
||||||
|
|
||||||
void ParceMail()
|
void ParseMail()
|
||||||
{
|
{
|
||||||
dword line_off, new_buf;
|
dword line_off, new_buf;
|
||||||
char tline[256];
|
char tline[256];
|
||||||
|
|
||||||
if ( mailpointer-mailbuffer>9 ) if ( (strncmp(mailpointer-5,"\r\n.\r\n",5)==0) || (strncmp(mailpointer-3,"\n.\n",3)==0) )
|
if ( mailpointer-mailbuffer>9 ) if (strncmp(mailpointer-5,"\n.\n",5)==0) // note that c-- assembles "\n.\n" to 0x0d, 0x0a, 0x2e, 0x0d, 0x0a
|
||||||
{
|
{
|
||||||
|
debug("End of mail detected");
|
||||||
|
mailpointer = mailpointer - 5;
|
||||||
|
*mailpointer='\0';
|
||||||
|
|
||||||
if (strstr(mailbuffer, "+OK")!=mailbuffer)
|
if (strstr(mailbuffer, "+OK")!=mailbuffer)
|
||||||
{
|
{
|
||||||
aim = GET_ANSWER_RETR;
|
aim = GET_ANSWER_RETR;
|
||||||
|
Loading…
Reference in New Issue
Block a user