-- Prova del motore di GrumpyDove per aarch64: scansiona le cartelle, -- estrae gli header di un messaggio, cerca un testo. Nessun Qt, nessuna -- libreria esterna: solo Ada e il runtime GNAT. with Ada.Text_IO; use Ada.Text_IO; with Ada.Exceptions; with Interfaces.C; use type Interfaces.C.int; with Mail_Folders; with Mail_Header; with Mail_Search; procedure Prova is Buf : String (1 .. 512); Len : Interfaces.C.int; Depth : Interfaces.C.int; Tot : Natural := 0; -- Legge un messaggio abbastanza corto in una stringa fissa. function Read_Message (Path : String) return String is F : File_Type; Line : String (1 .. 1024); Last : Natural; Whole : String (1 .. 16384); Pos : Natural := 0; begin Open (F, In_File, Path); while not End_Of_File (F) loop Get_Line (F, Line, Last); for I in 1 .. Last loop if Pos < Whole'Last then Pos := Pos + 1; Whole (Pos) := Line (I); end if; end loop; if Pos < Whole'Last then Pos := Pos + 1; Whole (Pos) := ASCII.LF; end if; end loop; Close (F); return Whole (1 .. Pos); end Read_Message; begin Mail_Folders.Scan; Put_Line ("radice delle cartelle: " & Mail_Folders.Root); for I in 0 .. 40 loop Len := Mail_Folders.Folder_At (Interfaces.C.int (I), Depth, Buf'Address, Interfaces.C.int (Buf'Length)); exit when Len < 0; Tot := Tot + 1; Put_Line (" " & (1 .. Natural (Depth) => ' ') & Buf (1 .. Natural (Len))); end loop; Put_Line ("cartelle trovate:" & Natural'Image (Tot)); declare Raw : constant String := Read_Message (Mail_Folders.Root & "/Local/In/cur/msg1:2,S"); From : constant String := Mail_Header.Field (Raw, "from"); Subject : constant String := Mail_Header.Decode_Words (Mail_Header.Field (Raw, "subject")); begin Put_Line ("messaggio letto: " & Natural'Image (Raw'Length) & " byte"); Put_Line (" da: " & Mail_Header.Who (From)); Put_Line (" indirizzo:" & Mail_Header.Address (From)); Put_Line (" oggetto: " & Subject); end; Put_Line ("ricerca 'preventivo':" & Boolean'Image (Mail_Search.Holds ("Re: preventivo tettoia", "preventivo", Mail_Search.Contains))); Put_Line ("ricerca 'assente':" & Boolean'Image (Mail_Search.Holds ("Re: preventivo tettoia", "assente", Mail_Search.Contains))); exception when E : others => Put_Line ("ECCEZIONE: " & Ada.Exceptions.Exception_Information (E)); end Prova;