Subversion Repositories Kolibri OS

Rev

Rev 4152 | Go to most recent revision | 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 *mailbuffer;
  15. char *mailpointer;
  16.  
  17.  
  18. enum {
  19.         GET_MAIL = 20,
  20.         SEND_MAIL,
  21.         DELETE_LETTER,
  22.         SAVE_LETTER,
  23.         STOP_LOADING,
  24.         EXIT_MAIL,
  25.         CHANGE_CHARSET,
  26.         CLOSE_CHANGE_CHARSET
  27. };
  28.  
  29.  
  30. void MailBoxLoop()
  31. {
  32.         int key, id;
  33.         mouse m;
  34.         int panels_drag = 0;
  35.         char socket_char;
  36.         int letter_size;
  37.         dword line_col, text_col;
  38.  
  39.         mail_list.h = Form.cheight/4;
  40.         mail_list.ClearList();
  41.         SetMailBoxStatus( NULL , NULL);
  42.         cur_charset = 0;
  43.         aim=SEND_NSTAT;
  44.        
  45.         goto _MB_DRAW;
  46.  
  47.         loop() 
  48.         {
  49.                 WaitEventTimeout(2);
  50.                 switch(EAX & 0xFF)
  51.                 {
  52.                         case evMouse:
  53.                                 IF (!CheckActiveProcess(Form.ID)) break;
  54.                                 m.get();
  55.                                
  56.                                 if (!m.lkm) panels_drag=0;
  57.                                 if (m.lkm) && (m.y>mail_list.y+mail_list.h-1) && (m.y<mail_list.y+mail_list.h+6)
  58.                                 && (!scroll1.delta2) && (!scroll2.delta2) panels_drag = 1;
  59.                                 if (panels_drag)
  60.                                 {
  61.                                         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;
  62.                                         mail_list.h = m.y - mail_list.y-2;
  63.                                         DrawMailBox();
  64.                                         break;
  65.                                 }
  66.  
  67.                                 if (!mail_list.count) break;
  68.                                 if (!panels_drag) { scrollbar_v_mouse (#scroll1); scrollbar_v_mouse (#scroll2); }
  69.                                
  70.                                 if (mail_list.first <> scroll1.position)
  71.                                 {
  72.                                         mail_list.first = scroll1.position;
  73.                                         DrawMailList();
  74.                                         break;
  75.                                 };
  76.                                 if (letter_view.first <> scroll2.position)
  77.                                 {
  78.                                         letter_view.first = scroll2.position;
  79.                                         DrawLetter();
  80.                                         break;
  81.                                 };
  82.                                
  83.                                 if (mail_list.y+mail_list.h + 10 > m.y)
  84.                                 {
  85.                                         if (mail_list.MouseScroll(m.vert)) DrawMailList();
  86.                                 }
  87.                                 else
  88.                                 {
  89.                                         if (letter_view.MouseScroll(m.vert)) DrawLetter();
  90.                                 }
  91.                                 //if (!m.lkm) && (menu.ProcessMouse(mm.x, mm.y)) &&
  92.                                 //if (!m.lkm) && if (menu.ProcessMouse(mm.x, mm.y)) DrawMenuList();
  93.  
  94.                                 break;                         
  95.                         case evButton:
  96.                                 id = GetButtonID();
  97.                                 if (id==1) SaveAndExit();
  98.                                 if (id==GET_MAIL) aim = SEND_NSTAT;
  99.                                 if (id==SAVE_LETTER)
  100.                                 {
  101.                                         if (!mailbuffer) break;
  102.                                         WriteFile(strlen(mailbuffer), mailbuffer, "mail.txt");
  103.                                         pause(10);
  104.                                         RunProgram("tinypad", "mail.txt");
  105.                                 }
  106.                                 if (id==STOP_LOADING)
  107.                                 {
  108.                                         StopLoading();
  109.                                         DrawStatusBar();
  110.                                         DrawMailList();
  111.                                 }
  112.                                 if (id==EXIT_MAIL)
  113.                                 {
  114.                                         StopLoading();
  115.                                         Close(socketnum);
  116.                                         LoginBoxLoop();
  117.                                 }
  118.                                 if (id==CHANGE_CHARSET)
  119.                                 {
  120.                                         DefineButton(0,0,Form.cwidth,Form.cheight, CLOSE_CHANGE_CHARSET+BT_HIDE+BT_NOFRAME);
  121.                                         DrawRectangle(Form.cwidth-100, Form.cheight-status_bar_h- 70, 70, 82, sc.work_graph);
  122.                                         DrawRectangle3D(Form.cwidth-99, Form.cheight-status_bar_h- 69, 68, 80, 0xFFFfff, sc.work);
  123.                                         for (id=0; id<5; id++)
  124.                                         {
  125.                                                 if (cur_charset==id+1) { line_col=sc.work_button; text_col=sc.work_button_text; }
  126.                                                 else { line_col=sc.work; text_col=sc.work_text; }
  127.                                                 DrawBar(Form.cwidth-98, id*16+Form.cheight-status_bar_h- 68, 67, 16, line_col);
  128.                                                 DrawCaptButton(Form.cwidth-100, id*16+Form.cheight-status_bar_h- 68, 70,16, 10+id+BT_HIDE,
  129.                                                 0, text_col, charsets[id+1]);
  130.                                         }
  131.                                 }
  132.                                 if (id==CLOSE_CHANGE_CHARSET) goto _MB_DRAW;
  133.  
  134.                                 if (id>=30)
  135.                                 {
  136.                                         if (aim) break;
  137.                                         mail_list.current = mail_list.first + id - 30;
  138.                                         DrawMailList();
  139.                                         aim = SEND_RETR;
  140.                                 }
  141.  
  142.                                 break;                         
  143.                         case evKey:
  144.                                 key = GetKey();
  145.  
  146.                                 if (!aim) && (mail_list.ProcessKey(key))
  147.                                 {
  148.                                         DrawMailList();
  149.                                         aim = SEND_RETR;
  150.                                 }
  151.  
  152.                                 break;
  153.                         case evReDraw: _MB_DRAW:
  154.                                 if !(DefineWindow(MAILBOX_HEADER)) break;
  155.                                 scroll1.bckg_col = scroll2.bckg_col = 0xBBBbbb;
  156.                                 scroll1.frnt_col = scroll2.frnt_col = sc.work;
  157.                                 scroll1.line_col = scroll2.line_col = sc.work_graph;
  158.                                 DrawToolbar();
  159.                                 DrawMailBox();
  160.  
  161.                                 break;
  162.                         default:
  163.                                 if (aim == SEND_NSTAT)
  164.                                 {
  165.                                         SetLoginStatus("Counting mail, awaiting answer...");                   
  166.                                         request_len = GetRequest("STAT", NULL);
  167.                                         Send(socketnum, #request, request_len, 0);
  168.                                         if (EAX == 0xffffffff) { debug("Error sending STAT. Retry..."w); break;}
  169.                                         aim = GET_ANSWER_NSTAT;
  170.                                 }
  171.                                
  172.                                 if (aim == GET_ANSWER_NSTAT)
  173.                                 {
  174.                                         ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0);
  175.                                         if ((ticks == 0xffffff) || (ticks < 2)) break;
  176.                                                                                
  177.                                         if (immbuffer[ticks-2]=='\n')
  178.                                         {
  179.                                                 debug(#immbuffer);
  180.                                                 if (strstr(#immbuffer,"+OK"))
  181.                                                 {
  182.                                                         mail_list.count = GetMailCount();
  183.                                                         debug("Letters:");
  184.                                                         debug(itoa(mail_list.count));
  185.                                                         free(listbuffer);
  186.                                                         listbuffer = mem_Alloc(30*mail_list.count); //24* original
  187.                                                         listpointer = listbuffer;      
  188.                                                         aim = SEND_NLIST;
  189.                                                         debug("Receiving mail list...");
  190.                                                 }
  191.                                                 else
  192.                                                 {
  193.                                                         StopConnect("Sorry, can't recieve your mail");
  194.                                                 }
  195.                                         }
  196.                                 }
  197.  
  198.                                 if (aim == SEND_NLIST)
  199.                                 {              
  200.                                         WriteText(5, Form.cheight-11, 0x80, sc.work_text, "Send LIST, awaiting answer...");
  201.                                         request_len = GetRequest("LIST", NULL);
  202.                                         Send(socketnum, #request, request_len, 0);
  203.                                         if (EAX == 0xffffffff) {debug("Error while sending LIST. Retry..."); break;}
  204.                                         aim = GET_ANSWER_NLIST;
  205.                                 }
  206.  
  207.                                 if (aim == GET_ANSWER_NLIST)
  208.                                 {              
  209.                                         ticks = Receive(socketnum, listpointer, listbuffer + 30*mail_list.count - listpointer, MSG_DONTWAIT);
  210.                                         if (ticks == 0xffffffff) break;
  211.                                         listpointer = listpointer + ticks;     
  212.                                        
  213.                                         if (listpointer - listbuffer < 5) break;
  214.                                         if (strncmp(listpointer-5,"\n.\n",5)==0)  // note that c-- assembles "\n.\n" to 0x0d, 0x0a, 0x2e, 0x0d, 0x0a   
  215.                                         {
  216.                                                 aim = SEND_RETR;
  217.                                                 debug("Got mail list");
  218.                                                 DrawMailBox();
  219.                                                
  220.                                                 *listpointer='\0';
  221.                                                 atr.CreateArray();
  222.                                                 atr.SetSizes();
  223.                                         }
  224.                                 }
  225.                                
  226.                                 if (aim == SEND_RETR)
  227.                                 {
  228.                                         from = to = date = subj = cur_charset = NULL;
  229.                                         letter_view.ClearList();
  230.                                         DrawMailBox();
  231.                                         debug("Send RETR, awaiting answer...");
  232.                                         request_len = GetRequest("RETR", itoa(mail_list.current+1));
  233.                                         if (Send(socketnum, #request, request_len, 0) == 0xffffffff)
  234.                                         {
  235.                                                 StopConnect("Error while trying to get letter from server");
  236.                                                 break;
  237.                                         }
  238.                                         letter_size = atr.GetSize(mail_list.current+1) + 1024;
  239.                                         free(mailbuffer);
  240.                                         if (!mailbuffer = malloc(letter_size))
  241.                                         {
  242.                                                 debug("alloc error!");
  243.                                                 aim=NULL;
  244.                                                 break;
  245.                                         }
  246.                                         mailpointer = mailbuffer;
  247.                                         aim = GET_ANSWER_RETR;
  248.                                 }
  249.                                
  250.                                 if (aim == GET_ANSWER_RETR)
  251.                                 {
  252.                                         aim=NULL;
  253.                                         break;
  254.                                         ticks = Receive(socketnum, mailpointer, letter_size + mailbuffer - mailpointer , MSG_DONTWAIT);
  255.                                         if (ticks == 0xffffffff) break;        
  256.                                        
  257.                                         mailpointer = mailpointer + ticks;
  258.  
  259.                                         if (!aim) break;
  260.  
  261.                                         if (letter_size + mailbuffer - mailpointer - 2 < 0)
  262.                                         {
  263.                                                 debug("Resizing buffer");
  264.                                                 letter_size += 4096;
  265.                                                 mailbuffer = realloc(mailbuffer, letter_size);
  266.                                                 if (!mailbuffer) { StopConnect("Realloc error!"); break;}
  267.                                         }
  268.  
  269.                                         if (letter_size>9000)
  270.                                         {
  271.                                                 id = mailpointer - mailbuffer * 100 ;
  272.                                                 id /= letter_size - 1024;
  273.                                                 if (id!=cur_st_percent) SetMailBoxStatus( id , NULL);
  274.                                         }
  275.  
  276.                                         ParseMail();
  277.                                 }
  278.  
  279.                 }
  280.         }
  281. }
  282.  
  283.  
  284. void DrawMailBox()
  285. {
  286.         DrawMailList();
  287.         DrawLetterInfo();
  288.         DrawLetter();
  289.         DrawStatusBar();
  290. }
  291.  
  292.  
  293. void DrawToolbar()
  294. {
  295.         #define BUT_Y 7
  296.         #define BUT_H 22
  297.         #define BUT_W 74
  298.         #define BUT_SPACE 11
  299.         int toolbar_w = BUT_Y + BUT_H + BUT_Y + 3;
  300.         mail_list.SetSizes(0, toolbar_w, Form.cwidth - scroll1.size_x - 1, mail_list.h, 60,18);
  301.  
  302.         DrawBar(0,0, Form.cwidth,toolbar_w-3, sc.work);
  303.         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   + 10, BUT_Y, BUT_W, BUT_H, SEND_MAIL,     sc.work_button, sc.work_button_text,"Send Email");
  305.         DrawCaptButton(BUT_W+BUT_SPACE*2 + 10, BUT_Y, BUT_W, BUT_H, DELETE_LETTER, sc.work_button, sc.work_button_text,"Delete");
  306.         DrawCaptButton(BUT_W+BUT_SPACE*3 + 10, BUT_Y, BUT_W, BUT_H, SAVE_LETTER,   sc.work_button, sc.work_button_text,"Save");
  307.         DrawCaptButton(Form.cwidth-BUT_W - 10, BUT_Y, BUT_W, BUT_H, EXIT_MAIL,     sc.work_button, sc.work_button_text,"< Exit");
  308.  
  309.         DrawBar(0, mail_list.y-3, mail_list.w,1, sc.work_graph);
  310.         DrawBar(0, mail_list.y-2, mail_list.w,1, 0xdfdfdf);
  311.         DrawBar(0, mail_list.y-1, mail_list.w,1, 0xf0f0f0);
  312. }
  313.  
  314. void DrawMailList()
  315. {
  316.         int i, on_y, on_x, direction;
  317.         dword sel_col;
  318.         mail_list.visible = mail_list.h / mail_list.line_h;
  319.  
  320.         for (i=30; i<150; i++) DeleteButton(i);
  321.         for (i=0; (i<mail_list.visible) && (i+mail_list.first<mail_list.count); i++)
  322.         {
  323.                 on_y = i*mail_list.line_h + mail_list.y;
  324.                 if (mail_list.current==mail_list.first+i) sel_col=0xEEEeee; else sel_col=0xFFFfff;
  325.                 DrawBar(0, on_y, mail_list.w, mail_list.line_h-1, sel_col);
  326.                 direction = atr.GetDirection(i+mail_list.first+1);
  327.                 on_x = strlen(itoa(i+mail_list.first+1))*6;
  328.                 letter_icons_pal[0]=sel_col;
  329.                 PutPaletteImage(sizeof(letter_icons)/3*direction + #letter_icons, 18,12, on_x+18,
  330.                         mail_list.line_h-12/2+ on_y, 8, #letter_icons_pal);
  331.                 WriteText(on_x + 42, on_y+5, 0x80, 0, atr.GetSubject(i+mail_list.first+1));
  332.                 DefineButton(0, on_y, mail_list.w-1, mail_list.line_h, 30+i+BT_HIDE+BT_NOFRAME);
  333.                 DrawBar(0, on_y + mail_list.line_h-1, mail_list.w, 1, 0xCCCccc);
  334.                 WriteText(10, on_y+5, 0x80, 0, itoa(i+mail_list.first+1));
  335.                 WriteText(mail_list.w - 40, on_y+5, 0x80, 0, ConvertMemSize(atr.GetSize(i+mail_list.first+1)));
  336.         }
  337.         DrawBar(0, i*mail_list.line_h + mail_list.y, mail_list.w, -i*mail_list.line_h+mail_list.h, 0xFFFfff);
  338.         DrawScroller1();
  339. }
  340.  
  341. void DrawLetterInfo()
  342. {
  343.         int lt_y = mail_list.y+mail_list.h;
  344.         DrawBar(0, lt_y, mail_list.w, 1, sc.work_graph);
  345.         DrawBar(0, lt_y+1, Form.cwidth, 1, LBUMP);
  346.         DrawBar(0, lt_y+2, Form.cwidth, LIST_INFO_H-4, sc.work);
  347.         WriteText(mail_list.w-30/2, lt_y, 0x80, 0x888888, "= = =");
  348.         WriteText(mail_list.w-30/2, lt_y+1, 0x80, 0xEeeeee, "= = =");
  349.         DrawBar(0, lt_y+LIST_INFO_H-2, mail_list.w, 1, sc.work_graph); //bottom
  350.         DrawBar(0, lt_y+LIST_INFO_H-1, mail_list.w, 1, 0xdfdfdf);
  351.         DrawBar(0, lt_y+LIST_INFO_H  , mail_list.w, 1, 0xf0f0f0);
  352.         WriteTextB(10, lt_y+8 , 0x80, sc.work_text, "From:");
  353.         WriteText (45, lt_y+8 , 0x80, sc.work_text, #from);
  354.         WriteTextB(10, lt_y+20, 0x80, sc.work_text, "To:");
  355.         WriteText (45, lt_y+20, 0x80, sc.work_text, #to);
  356.         WriteTextB(10, lt_y+32, 0x80, sc.work_text, "Date:");
  357.         WriteText (45, lt_y+32, 0x80, sc.work_text, #date);
  358.         WriteTextB(10, lt_y+44, 0x80, sc.work_text, "Subject:");
  359.         WriteText (66, lt_y+44, 0x80, sc.work_text, #subj);
  360. }
  361.  
  362. void DrawLetter()
  363. {
  364.         int i=0;
  365.         dword cur_line, next_line, line_text;
  366.         cur_line = mdata;
  367.  
  368.         letter_view.SetSizes(0, mail_list.y+mail_list.h+LIST_INFO_H+1, Form.cwidth - scroll2.size_x - 1,
  369.                 Form.cheight - mail_list.y - mail_list.h - LIST_INFO_H - 1 - status_bar_h, 60, 12);
  370.  
  371.         if (mailbuffer) && (!aim)
  372.         {
  373.                 for ( ; i < letter_view.first; i++) cur_line = GetNextLine(cur_line);
  374.  
  375.                 for (i=0; i < letter_view.h / letter_view.line_h; i++)
  376.                 {
  377.                         next_line = GetNextLine(cur_line);
  378.                         line_text = CopyBetweenOffsets(cur_line, next_line);
  379.                         cur_line = next_line;
  380.                         if (cur_line >= mailpointer) || (cur_line==1) break;
  381.                         DrawBar(letter_view.x, i*letter_view.line_h + letter_view.y, letter_view.w, letter_view.line_h, 0xFFFfff);
  382.                         if (line_text) { WriteText(letter_view.x+5, i*letter_view.line_h+letter_view.y+3, 0x80, 0, line_text); free(line_text);}
  383.                 }
  384.         }
  385.         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);
  386.         DrawBar(letter_view.x, letter_view.y + letter_view.h-1, letter_view.w, 1, sc.work_graph);
  387.         DrawScroller2();
  388. }
  389.  
  390. void DrawScroller1()
  391. {
  392.         scroll1.max_area = mail_list.count;
  393.         scroll1.cur_area = mail_list.visible;
  394.         scroll1.position = mail_list.first;
  395.  
  396.         scroll1.all_redraw=1;
  397.         scroll1.start_x = mail_list.x + mail_list.w;
  398.         scroll1.start_y = mail_list.y - 3;
  399.         scroll1.size_y = mail_list.h + 4;
  400.         scrollbar_v_draw(#scroll1);
  401. }
  402.  
  403. void DrawScroller2()
  404. {
  405.         scroll2.max_area = letter_view.count;
  406.         scroll2.cur_area = letter_view.visible;
  407.         scroll2.position = letter_view.first;
  408.  
  409.         scroll2.all_redraw=1;
  410.         scroll2.start_x = letter_view.x + letter_view.w;
  411.         scroll2.start_y = letter_view.y - 3;
  412.         scroll2.size_y = letter_view.h + 3;
  413.         scrollbar_v_draw(#scroll2);
  414. }
  415.  
  416.  
  417.  
  418. void DrawStatusBar()
  419. {
  420.         int st_y = Form.cheight -status_bar_h;
  421.         DrawBar(0, st_y, Form.cwidth, status_bar_h, sc.work);
  422.         if (aim) {
  423.                 SetMailBoxStatus(cur_st_percent, cur_st_text);
  424.                 DrawCaptButton(240, st_y+1, 36, status_bar_h-3, STOP_LOADING, sc.work_button, sc.work_button_text,"Stop");
  425.         }
  426.         DrawCaptButton(Form.cwidth - 100, st_y+1, 70, status_bar_h-2, CHANGE_CHARSET+BT_HIDE, sc.work, sc.work_text,charsets[cur_charset]);
  427. }
  428.  
  429.  
  430.  
  431. void SetMailBoxStatus(dword percent1, text1)
  432. {
  433.         DrawProgressBar(3, Form.cheight -status_bar_h + 1, 220, 12, sc.work, 0xC3C3C3, 0x54B1D6, sc.work_text, percent1, text1);
  434.         cur_st_percent = percent1;
  435.         cur_st_text = text1;
  436. }
  437.  
  438.  
  439. void StopLoading()
  440. {
  441.         aim = NULL;
  442.         mailbuffer = free(mailbuffer);
  443.         to = from = date = subj = cur_charset = NULL;
  444. }
  445.  
  446. int GetMailCount(){
  447.         char tmpbuf4[512];
  448.         strcpyb(#immbuffer, #tmpbuf4, "+OK ", " ");
  449.         return atoi(#tmpbuf4);
  450. }
  451.  
  452.  
  453.  
  454. int GetLetterSize_(int number){
  455.         char search_num[24];
  456.         char letter_size1[24];
  457.         strcpy(#search_num, "\n");                      // 0x0d, 0x0a
  458.         strcat(#search_num, itoa(number));
  459.         strcat(#search_num, " ");
  460.         strcpyb(listbuffer, #letter_size1, #search_num, "\x0d");
  461.         return atoi(#letter_size1);
  462. }
  463.  
  464.  
  465.  
  466.  
  467.