P°φklad p°φjmu zßsilky

P°φklad v jazyku klienta :

var cnt1, cnt2  : trecnum;
    j,i,err     : integer;
    id_zas,lsize: integer;
    curs1,curs2 : cursor;
    box         : integer;
    query1,query2  : string[120];
    fname       : string[255];

begin
err := InitWBMail("winbase", nil); // inicializace
   if err = 0 then begin
     err := MailOpenInBox(box);     // otev°enφ schrßnky
     if err = 0 then begin
       MailBoxLoad(box,0);     // naΦtenφ informacφ (pouze seznam)
       query1 := "SELECT * FROM _Sysext._Inboxmsgs WHERE subject=""Data""";
// vybrßnφ t∞ch zßsilek, kterΘ majφ dan² subject
       if not Open_SQL_Cursor(curs1, query1) then begin  
         Rec_cnt(curs1, cnt1);
         for j := 0 to cnt1 - 1 do begin
            id_zas := curs1[j].id;   // identifikßtor j-tΘ zßsilky
            MailBoxGetMsg(box,id_zas); //zφskßnφ textu j-tΘho dopisu
            lsize := curs1[j].size;
            if lsize > 0 then begin
// ... prßce s textem dopis∙
            end;
// zφskßnφ informacφ o p°ipojen²ch souborech j-tΘ zßsilky
            MailBoxGetFilInfo(box,id_zas); 
            query2 := "SELECT * FROM _Sysext._Inboxfiles WHERE id="+Int2str(id_zas);
            if not Open_SQL_cursor(curs2, query2) then begin
               Rec_cnt(curs2,cnt2);
               for i := 0 to cnt2 - 1 do begin
// zφskßnφ informacφ o p°ipojen²ch souborech j-tΘ zßsilky
                 fname := curs2[i].name;    
// o°φznutφ cesty (platφ pouze pro Windows)
                 while SubStr("\",fname) do 
                   StrDelete(fname,1,StrPos("\",fname));  
// vytvo°enφ jmΘna souboru pro ulo₧enφ
                 fname := "D:\tempdir\wbdata\"+fname;
// ulo₧enφ souboru
                 err := MailBoxSaveFileAs(box,id_zas,i,nil,fname); 
                 if err > 0 then Signalize;
               end;
               Close_cursor(curs2);
            end;
// vymazßnφ zßsilky ze schrßnky i z databßze
            MailBoxDeleteMsg(box,id_zas,TRUE); 
         end;
         Close_cursor(curs1);
       end;
       MailCloseInBox(box); // zav°φt schrßnku
     end else Signalize;    // chyba p°i otev°enφ schrßnky
     CloseWBMail;       // ukonΦit komunikaci
  end else Signalize;   // chyba p°i inicializaci
end.

Tent²₧ p°φklad v SQL na serveru:

(funkce pro spoluprßci s poÜtou nevyvolajφ v²jimku - nelze zachytit handlerem)

PROCEDURE `PrijmiMail`();
BEGIN
   DECLARE err,i  INT;
   DECLARE box    INT;
   DECLARE id_zas,lsize INT;
   DECLARE fname  CHAR(255);
   SET err = InitWBMail("winbase","");
   IF err = 0 THEN BEGIN
     SET err = MailOpenInBox(box);
     IF err = 0 THEN BEGIN
       CALL MailBoxLoad(box,0);
       FOR Zas AS INSENSITIVE CURSOR FOR
         SELECT * FROM _Sysext._Inboxmsgs WHERE Subject="Data"
       DO 
       BEGIN
          SET id_zas = Zas.id;
          CALL MailBoxGetMsg(box,id_zas);
          SET lsize = Zas.size;
          IF lsize > 0 THEN
          BEGIN
  // ... prßce s textem dopis∙
          END; END IF;
          CALL MailBoxGetFilInfo(box,id_zas);            
          SET i = 0;
          FOR ZasFil AS INSENSITIVE CURSOR FOR
            SELECT * FROM _Sysext._Inboxfiles WHERE id=id_zas
          DO 
          BEGIN
            SET fname = ZasFil.name;
            WHILE POSITION("\" IN fname)>0 DO 
               CALL StrDelete(fname,1,POSITION("\" IN fname));  
            END WHILE;
            SET fname = "D:\tempdir\wbdata\"||fname;
            SET Err = MailBoxSaveFileAs(box,id_zas,i,"",fname);
            IF Err > 0 THEN
              CALL Log_write("Chyba p°i uklßdßnφ souboru "+int2str(Err));
            END IF;
            SET i = i+1;
          END;
          END FOR;
          CALL MailBoxDeleteMsg(box,Zas.id,FALSE);
       END;
       END FOR;
       CALL MailCloseInBox(box);
     END; ELSE 
       CALL Log_write("Chyba p°i otevφrßnφ schrßnky "+int2str(Err)); 
     END IF;
     CALL CloseWBMail();
   END; ELSE 
     CALL Log_write("Chyba p°i inicializaci "+int2str(Err)); 
   END IF;
END
Viz takΘ: Spoluprßce s elektronickou poÜtou - ·vod
  P°φjem poÜty