1
-- Topal: GPG/GnuPG and Alpine/Pine integration
2
-- Copyright (C) 2001--2008 Phillip J. Brooke
4
-- This program is free software: you can redistribute it and/or modify
5
-- it under the terms of the GNU General Public License version 3 as
6
-- published by the Free Software Foundation.
8
-- This program is distributed in the hope that it will be useful,
9
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
10
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
-- GNU General Public License for more details.
13
-- You should have received a copy of the GNU General Public License
14
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
6
with Ada.IO_Exceptions;
7
with Ada.Strings.Fixed;
8
with Ada.Strings.Unbounded;
12
17
with Externals; use Externals;
13
18
with Externals.Mail;
14
19
with Externals.Simple;
110
102
A_Menu := new Attachlist_Menus.MNA(1..List.Count);
111
103
for I in 1..List.Count loop
113
S : String := ToStr(UAP.Value(List.AA, I));
105
S : constant String := ToStr(UAP.Value(List.AA, I));
115
107
if S'Length < A_Head_Length then
116
108
A_Menu(I) := ToUBS(S);
155
151
Enable_Tab_Completion => True));
156
152
-- Deal with the last space that we'll often get.
158
NFN : String := ToStr(New_Filename);
154
NFN : constant String := ToStr(New_Filename);
160
156
if NFN(NFN'Last) = ' ' then
161
157
Alt_Filename := ToUBS(NFN(NFN'First..NFN'Last-1));
194
procedure Empty_Attachmentlist (List : in out Attachment_List) is
190
procedure Empty_Attachment_List (List : in out Attachment_List) is
196
192
UAP.Create(List.AA, Attachment_List_Initial_Size);
200
196
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
201
"Exception raised in Attachments.Empty_Attachmentlist");
197
"Exception raised in Attachments.Empty_Attachment_List");
199
end Empty_Attachment_List;
205
201
function Count (List : in Attachment_List) return Natural is
215
211
procedure Replace_Tmpfile (Tmpfile : in String;
216
List : in out Attachment_List;
217
Internal_Mimetype : out UBS) is
212
List : in Attachment_List) is
218
213
AL : UBS_Array(1..Count(List)+1);
219
TF : String := Temp_File_Name("attrtf");
214
BF : constant String := Temp_File_Name("att64-");
215
TF : constant String := Temp_File_Name("attrtf");
221
218
-- Do nothing if the attachment list is empty.
222
219
if List.Count /= 0 then
223
220
-- Now, construct a list of items.
224
221
AL(1) := ToUBS(Tmpfile);
225
222
for I in 1..List.Count loop
226
AL(I+1) := UAP.Value(List.AA, I);
223
-- Guess the content type.
224
CT := ToUBS(Externals.Simple.Guess_Content_Type(ToStr(UAP.Value(List.AA, I))) & "; name="""&Basename(ToStr(UAP.Value(List.AA, I)))&"""");
225
-- Create a base64 subpart.
226
Externals.Mail.Mimeconstruct_Subpart(Infile => ToStr(UAP.Value(List.AA, I)),
227
Outfile => BF & Trim_Leading_Spaces(Integer'Image(I)),
228
Content_Type => ToStr(CT),
231
Header => "Content-Type: " & ToStr(CT),
232
Use_Encoding => True,
233
Encoding => "base64");
234
-- Add the base64's file to the list.
235
AL(I+1) := ToUBS(BF & Trim_Leading_Spaces(Integer'Image(I)));
236
Ada.Text_IO.Put_Line("Added file `"&ToStr(UAP.Value(List.AA, I))&"' with content-type `"&ToStr(CT)&"'");
228
238
-- And call mimeconstruct.
229
239
Externals.Mail.Mimeconstruct_Mixed(AL, TF);
230
240
-- Then replace the original tmpfile.
231
Externals.Mail.Extract_Body(TF, Tmpfile);
232
-- We guess that the mimetype is in fact multipart/mixed.
234
Internal_Mimetype := ToUBS("");
241
Externals.Simple.Mv_F(TF, Tmpfile);
242
-- Convert to CR-LF line endings.
243
Externals.Simple.Dos2Unix_U(Tmpfile);