Subversion Repositories Kolibri OS

Rev

Rev 4166 | Blame | Last modification | View Log | Download | RSS feed

  1. //Leency & SoUrcerer, LGPL
  2.  
  3. #define LIST_INFO_H 59
  4. int status_bar_h = 15;
  5.  
  6. 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};
  7. 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};
  8.  
  9.  
  10.  
  11. char *listbuffer;
  12. char *listpointer;
  13.  
  14. char *mailstart;
  15. char *mailend;
  16. int mailsize;
  17.  
  18.  
  19. enum {
  20.         GET_MAIL = 20,
  21.         SEND_MAIL,
  22.         DELETE_LETTER,
  23.         SAVE_LETTER,
  24.         STOP_LOADING,
  25.         EXIT_MAIL,
  26.         CHANGE_CHARSET,
  27.         CLOSE_CHANGE_CHARSET
  28. };
  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. }
  140.  
  141.  
  142. void MailBoxLoop()
  143. {
  144.         int key, id;
  145.         mouse m;
  146.         int panels_drag = 0;
  147.         dword line_col, text_col;
  148.  
  149.         mail_list.h = Form.cheight/4;
  150.         mail_list.ClearList();
  151.         SetMailBoxStatus( NULL , NULL);
  152.         cur_charset = 0;
  153.         aim = SEND_NSTAT;
  154.        
  155.         goto _MB_DRAW;
  156.  
  157.         loop() 
  158.         {
  159.                 WaitEventTimeout(2);
  160.                 switch(EAX & 0xFF)
  161.                 {
  162.                         case evMouse:
  163.                                 IF (!CheckActiveProcess(Form.ID)) break;
  164.                                 m.get();
  165.                                
  166.                                 if (!m.lkm) panels_drag=0;
  167.                                 if (m.lkm) && (m.y>mail_list.y+mail_list.h-1) && (m.y<mail_list.y+mail_list.h+6)
  168.                                 && (!scroll1.delta2) && (!scroll2.delta2) panels_drag = 1;
  169.                                 if (panels_drag)
  170.                                 {
  171.                                         if (m.y<mail_list.y+mail_list.min_h) || (m.y>Form.cheight-letter_view.min_h-status_bar_h-LIST_INFO_H) break;
  172.                                         mail_list.h = m.y - mail_list.y-2;
  173.                                         DrawMailBox();
  174.                                         break;
  175.                                 }
  176.  
  177.                                 if (!mail_list.count) break;
  178.                                 if (!panels_drag) { scrollbar_v_mouse (#scroll1); scrollbar_v_mouse (#scroll2); }
  179.                                
  180.                                 if (mail_list.first <> scroll1.position)
  181.                                 {
  182.                                         mail_list.first = scroll1.position;
  183.                                         DrawMailList();
  184.                                         break;
  185.                                 };
  186.                                 if (letter_view.first <> scroll2.position)
  187.                                 {
  188.                                         letter_view.first = scroll2.position;
  189.                                         DrawLetter();
  190.                                         break;
  191.                                 };
  192.                                
  193.                                 if (mail_list.y+mail_list.h + 10 > m.y)
  194.                                 {
  195.                                         if (mail_list.MouseScroll(m.vert)) DrawMailList();
  196.                                 }
  197.                                 else
  198.                                 {
  199.                                         if (letter_view.MouseScroll(m.vert)) DrawLetter();
  200.                                 }
  201.                                 //if (!m.lkm) && (menu.ProcessMouse(mm.x, mm.y)) &&
  202.                                 //if (!m.lkm) && if (menu.ProcessMouse(mm.x, mm.y)) DrawMenuList();
  203.  
  204.                                 break;                         
  205.                         case evButton:
  206.                                 id = GetButtonID();
  207.                                 if (id==1) SaveAndExit();
  208.                                 if (id==GET_MAIL) aim = SEND_NSTAT;
  209.                                 if (id==SAVE_LETTER)
  210.                                 {
  211.                                         if (!mailstart) break;
  212.                                         WriteFile(strlen(mailstart), mailstart, "mail.txt");
  213.                                         pause(10);
  214.                                         RunProgram("tinypad", "mail.txt");
  215.                                 }
  216.                                 if (id==STOP_LOADING)
  217.                                 {
  218.                                         StopLoading();
  219.                                         DrawStatusBar();
  220.                                         DrawMailList();
  221.                                 }
  222.                                 if (id==EXIT_MAIL)
  223.                                 {
  224.                                         StopLoading();
  225.                                         Close(socketnum);
  226.                                         LoginBoxLoop();
  227.                                 }
  228.                                 if (id==CHANGE_CHARSET)
  229.                                 {
  230.                                         DefineButton(0,0,Form.cwidth,Form.cheight, CLOSE_CHANGE_CHARSET+BT_HIDE+BT_NOFRAME);
  231.                                         DrawRectangle(Form.cwidth-100, Form.cheight-status_bar_h- 70, 70, 82, sc.work_graph);
  232.                                         DrawRectangle3D(Form.cwidth-99, Form.cheight-status_bar_h- 69, 68, 80, 0xFFFfff, sc.work);
  233.                                         for (id=0; id<5; id++)
  234.                                         {
  235.                                                 if (cur_charset==id+1) { line_col=sc.work_button; text_col=sc.work_button_text; }
  236.                                                 else { line_col=sc.work; text_col=sc.work_text; }
  237.                                                 DrawBar(Form.cwidth-98, id*16+Form.cheight-status_bar_h- 68, 67, 16, line_col);
  238.                                                 DrawCaptButton(Form.cwidth-100, id*16+Form.cheight-status_bar_h- 68, 70,16, 10+id+BT_HIDE,
  239.                                                 0, text_col, charsets[id+1]);
  240.                                         }
  241.                                 }
  242.                                 if (id==CLOSE_CHANGE_CHARSET) goto _MB_DRAW;
  243.  
  244.                                 if (id>=30)
  245.                                 {
  246.                                         if (aim) break;
  247.                                         mail_list.current = mail_list.first + id - 30;
  248.                                         DrawMailList();
  249.                                         aim = SEND_RETR;
  250.                                 }
  251.  
  252.                                 break;                         
  253.                         case evKey:
  254.                                 key = GetKey();
  255.  
  256.                                 if (!aim) && (mail_list.ProcessKey(key))
  257.                                 {
  258.                                         DrawMailList();
  259.                                         aim = SEND_RETR;
  260.                                 }
  261.  
  262.                                 break;
  263.                         case evReDraw: _MB_DRAW:
  264.                                 if !(DefineWindow(MAILBOX_HEADER)) break;
  265.                                 scroll1.bckg_col = scroll2.bckg_col = 0xBBBbbb;
  266.                                 scroll1.frnt_col = scroll2.frnt_col = sc.work;
  267.                                 scroll1.line_col = scroll2.line_col = sc.work_graph;
  268.                                 DrawToolbar();
  269.                                 DrawMailBox();
  270.  
  271.                                 break;
  272.                         default:
  273.                                 MailBoxNetworkProcess();
  274.                 }
  275.         }
  276. }
  277.  
  278.  
  279. void DrawMailBox()
  280. {
  281.         DrawMailList();
  282.         DrawLetterInfo();
  283.         DrawLetter();
  284.         DrawStatusBar();
  285. }
  286.  
  287.  
  288. void DrawToolbar()
  289. {
  290.         #define BUT_Y 7
  291.         #define BUT_H 22
  292.         #define BUT_W 74
  293.         int toolbar_w = BUT_Y + BUT_H + BUT_Y + 3;
  294.         mail_list.SetSizes(0, toolbar_w, Form.cwidth - scroll1.size_x - 1, mail_list.h, 60,18);
  295.  
  296.         DrawBar(0,0, Form.cwidth,toolbar_w-3, sc.work);
  297.         DrawCaptButton(10                    , BUT_Y, BUT_W, BUT_H, GET_MAIL,    sc.work_button, sc.work_button_text,"Get mail");
  298.         DrawCaptButton(BUT_W+ 20, BUT_Y, BUT_W+10, BUT_H, SAVE_LETTER, sc.work_button, sc.work_button_text,"Save letter");
  299.         DrawCaptButton(Form.cwidth-BUT_W - 10, BUT_Y, BUT_W, BUT_H, EXIT_MAIL,   sc.work_button, sc.work_button_text,"< Exit");
  300.  
  301.         DrawBar(0, mail_list.y-3, mail_list.w,1, sc.work_graph);
  302.         DrawBar(0, mail_list.y-2, mail_list.w,1, 0xdfdfdf);
  303.         DrawBar(0, mail_list.y-1, mail_list.w,1, 0xf0f0f0);
  304. }
  305.  
  306. void DrawMailList()
  307. {
  308.         int i, on_y, on_x, direction;
  309.         dword sel_col;
  310.         mail_list.visible = mail_list.h / mail_list.line_h;
  311.  
  312.         for (i=30; i<150; i++) DeleteButton(i);
  313.         for (i=0; (i<mail_list.visible) && (i+mail_list.first<mail_list.count); i++)
  314.         {
  315.                 on_y = i*mail_list.line_h + mail_list.y;
  316.                 if (mail_list.current==mail_list.first+i) sel_col=0xEEEeee; else sel_col=0xFFFfff;
  317.                 DrawBar(0, on_y, mail_list.w, mail_list.line_h-1, sel_col);
  318.                 direction = atr.GetDirection(i+mail_list.first+1);
  319.                 on_x = strlen(itoa(i+mail_list.first+1))*6;
  320.                 letter_icons_pal[0]=sel_col;
  321.                 PutPaletteImage(sizeof(letter_icons)/3*direction + #letter_icons, 18,12, on_x+18,
  322.                         mail_list.line_h-12/2+ on_y, 8, #letter_icons_pal);
  323.                 WriteText(on_x + 42, on_y+5, 0x80, 0, atr.GetSubject(i+mail_list.first+1));
  324.                 DefineButton(0, on_y, mail_list.w-1, mail_list.line_h, 30+i+BT_HIDE+BT_NOFRAME);
  325.                 DrawBar(0, on_y + mail_list.line_h-1, mail_list.w, 1, 0xCCCccc);
  326.                 WriteText(10, on_y+5, 0x80, 0, itoa(i+mail_list.first+1));
  327.                 WriteText(mail_list.w - 40, on_y+5, 0x80, 0, ConvertMemSize(atr.GetSize(i+mail_list.first+1)));
  328.         }
  329.         DrawBar(0, i*mail_list.line_h + mail_list.y, mail_list.w, -i*mail_list.line_h+mail_list.h, 0xFFFfff);
  330.         DrawScroller1();
  331. }
  332.  
  333. void DrawLetterInfo()
  334. {
  335.         int lt_y = mail_list.y+mail_list.h;
  336.         DrawBar(0, lt_y, mail_list.w, 1, sc.work_graph);
  337.         DrawBar(0, lt_y+1, Form.cwidth, 1, LBUMP);
  338.         DrawBar(0, lt_y+2, Form.cwidth, LIST_INFO_H-4, sc.work);
  339.         WriteText(mail_list.w-30/2, lt_y, 0x80, 0x888888, "= = =");
  340.         WriteText(mail_list.w-30/2, lt_y+1, 0x80, 0xEeeeee, "= = =");
  341.         DrawBar(0, lt_y+LIST_INFO_H-2, mail_list.w, 1, sc.work_graph); //bottom
  342.         DrawBar(0, lt_y+LIST_INFO_H-1, mail_list.w, 1, 0xdfdfdf);
  343.         DrawBar(0, lt_y+LIST_INFO_H  , mail_list.w, 1, 0xf0f0f0);
  344.         WriteTextB(10, lt_y+8 , 0x80, sc.work_text, "From:");
  345.         WriteText (45, lt_y+8 , 0x80, sc.work_text, #from);
  346.         WriteTextB(10, lt_y+20, 0x80, sc.work_text, "To:");
  347.         WriteText (45, lt_y+20, 0x80, sc.work_text, #to);
  348.         WriteTextB(10, lt_y+32, 0x80, sc.work_text, "Date:");
  349.         WriteText (45, lt_y+32, 0x80, sc.work_text, #date);
  350.         WriteTextB(10, lt_y+44, 0x80, sc.work_text, "Subject:");
  351.         WriteText (66, lt_y+44, 0x80, sc.work_text, #subj);
  352. }
  353.  
  354. void DrawLetter()
  355. {
  356.         int i=0;
  357.         dword cur_line, next_line, line_text;
  358.         cur_line = mdata;
  359.  
  360.         letter_view.SetSizes(0, mail_list.y+mail_list.h+LIST_INFO_H+1, Form.cwidth - scroll2.size_x - 1,
  361.                 Form.cheight - mail_list.y - mail_list.h - LIST_INFO_H - 1 - status_bar_h, 60, 12);
  362.  
  363.         if (mailstart) && (!aim)
  364.         {
  365.                 for ( ; i < letter_view.first; i++) cur_line = GetNextLine(cur_line);
  366.  
  367.                 for (i=0; i < letter_view.h / letter_view.line_h; i++)
  368.                 {
  369.                         next_line = GetNextLine(cur_line);
  370.                         line_text = CopyBetweenOffsets(cur_line, next_line);
  371.                         cur_line = next_line;
  372.                         if (cur_line >= mailend) || (cur_line==1) break;
  373.                         DrawBar(letter_view.x, i*letter_view.line_h + letter_view.y, letter_view.w, letter_view.line_h, 0xFFFfff);
  374.                         if (line_text) { WriteText(letter_view.x+5, i*letter_view.line_h+letter_view.y+3, 0x80, 0, line_text); free(line_text);}
  375.                 }
  376.         }
  377.         DrawBar(letter_view.x, i*letter_view.line_h + letter_view.y, letter_view.w, -i*letter_view.line_h + letter_view.h-1, 0xFFFfff);
  378.         DrawBar(letter_view.x, letter_view.y + letter_view.h-1, letter_view.w, 1, sc.work_graph);
  379.         DrawScroller2();
  380. }
  381.  
  382. void DrawScroller1()
  383. {
  384.         scroll1.max_area = mail_list.count;
  385.         scroll1.cur_area = mail_list.visible;
  386.         scroll1.position = mail_list.first;
  387.  
  388.         scroll1.all_redraw=1;
  389.         scroll1.start_x = mail_list.x + mail_list.w;
  390.         scroll1.start_y = mail_list.y - 3;
  391.         scroll1.size_y = mail_list.h + 4;
  392.         scrollbar_v_draw(#scroll1);
  393. }
  394.  
  395. void DrawScroller2()
  396. {
  397.         scroll2.max_area = letter_view.count;
  398.         scroll2.cur_area = letter_view.visible;
  399.         scroll2.position = letter_view.first;
  400.  
  401.         scroll2.all_redraw=1;
  402.         scroll2.start_x = letter_view.x + letter_view.w;
  403.         scroll2.start_y = letter_view.y - 3;
  404.         scroll2.size_y = letter_view.h + 3;
  405.         scrollbar_v_draw(#scroll2);
  406. }
  407.  
  408.  
  409.  
  410. void DrawStatusBar()
  411. {
  412.         int st_y = Form.cheight -status_bar_h;
  413.         DrawBar(0, st_y, Form.cwidth, status_bar_h, sc.work);
  414.         if (aim) {
  415.                 SetMailBoxStatus(cur_st_percent, cur_st_text);
  416.                 DrawCaptButton(240, st_y+1, 36, status_bar_h-3, STOP_LOADING, sc.work_button, sc.work_button_text,"Stop");
  417.         }
  418.         DrawCaptButton(Form.cwidth - 100, st_y+1, 70, status_bar_h-2, CHANGE_CHARSET+BT_HIDE, sc.work, sc.work_text,charsets[cur_charset]);
  419. }
  420.  
  421.  
  422.  
  423. void SetMailBoxStatus(dword percent1, text1)
  424. {
  425.         DrawProgressBar(3, Form.cheight -status_bar_h + 1, 220, 12, sc.work, 0xC3C3C3, 0x54B1D6, sc.work_text, percent1, text1);
  426.         cur_st_percent = percent1;
  427.         cur_st_text = text1;
  428. }
  429.  
  430.  
  431. void StopLoading()
  432. {
  433.         aim = NULL;
  434.         mailstart = free(mailstart);
  435.         to = from = date = subj = cur_charset = NULL;
  436. }
  437.  
  438. int GetLetterSize_(int number)
  439. {
  440.    char search_num[24];
  441.    char mailsize1[24];
  442.    strcpy(#search_num, "\n");       // 0x0d, 0x0a
  443.    itoa_(#search_num+1, number);
  444.    chrcat(#search_num, ' ');
  445.    strcpyb(listbuffer, #mailsize1, #search_num, "\x0d");
  446.    return atoi(#mailsize1);
  447. }
  448.  
  449.  
  450.  
  451.  
  452.