topal-75/ 0000755 0001750 0001750 00000000000 11722471751 010545 5 ustar pjb pjb topal-75/ada-readline-c.c 0000644 0001750 0001750 00000003007 11722471751 013437 0 ustar pjb pjb /*
Topal: GPG/GnuPG and Alpine/Pine integration
Copyright (C) 2001--2008 Phillip J. Brooke
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include
#include
#include
#include
/* A static variable for holding the line. */
static char *line_read = (char *)NULL;
/* Read a string, and return a pointer to it. Returns NULL on EOF. */
char * rl_gets (char * prompt)
{
/* If the buffer has already been allocated, return the memory
to the free pool. */
if (line_read)
{
free (line_read);
line_read = (char *)NULL;
}
/* Get a line from the user. */
line_read = readline (prompt);
/* If the line has any text in it, save it on the history. */
if (line_read && *line_read)
add_history (line_read);
/*
printf("Value in result is `%s'\n", line_read);
*/
return line_read;
}
void rl_disable_tab_completion ()
{
rl_bind_key ('\t', rl_insert);
}
void rl_enable_tab_completion ()
{
rl_bind_key ('\t', rl_complete);
}
topal-75/mkhelp 0000755 0001750 0001750 00000005666 11722471751 011770 0 ustar pjb pjb #!/bin/sh
# Topal: GPG/GnuPG and Alpine/Pine integration
# Copyright (C) 2001--2008 Phillip J. Brooke
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
cat > help.ads <.
-- Generated by a script.
package Help is
procedure Message;
procedure Disclaimer;
end Help;
EOF
cat > help.adb <.
-- Generated by a script.
with Ada.Text_IO;
package body Help is
procedure Message is
use Ada.Text_IO;
begin
EOF
expand help.txt | sed 's/"/""/g' | sed 's/^/ Put_Line("/' | sed 's/$/");/' >> help.adb
cat >> help.adb <
Put_Line(Standard_Error,
"Exception raised in Help.Message");
raise;
end Message;
procedure Disclaimer is
use Ada.Text_IO;
begin
EOF
sed '6,13 ! d; s/#//' < mkhelp | sed 's/^/ Put_Line("/' | sed 's/$/");/' >> help.adb
cat >> help.adb <
Put_Line(Standard_Error,
"Exception raised in Help.Disclaimer");
raise;
end Disclaimer;
end Help;
EOF
topal-75/cl_menus.ads 0000644 0001750 0001750 00000003575 11722471751 013055 0 ustar pjb pjb -- Topal: GPG/GnuPG and Alpine/Pine integration
-- Copyright (C) 2001--2008 Phillip J. Brooke
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License version 3 as
-- published by the Free Software Foundation.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see .
with Globals; use Globals;
generic
type Index is (<>);
package CL_Menus is
Arrays_Not_Matched : exception;
type MA is array (Index range <>) of UBS;
type MNA is array (Integer range <>) of UBS;
-- Give a Menu_Array for the valid characters (Accept_Chars), and a list
-- of items (Numbered_Menu) to be selected by number (the menu
-- subroutine will offer them up to 9 at a time). Char_Words
-- and Number_Word give the string to be displayed when that option is
-- selected. Number trailword is displayed after the numbered selection.
type CLM_Return is
record
Is_Num : Boolean;
I : Index;
N : Integer;
end record;
generic
Accept_Chars : MA;
Char_Words : MA;
Default_Prompt : String := "";
Default_Number_Word : String := "";
Default_Number_Trailword : String := "";
function Menu (Numbered_Menu : in MNA;
Number_Word : in String := Default_Number_Word;
Prompt : in String := Default_Prompt;
Number_Trailword : in String := Default_Number_Trailword)
return CLM_Return;
end CL_Menus;
topal-75/char_menus.adb 0000644 0001750 0001750 00000006350 11722471751 013345 0 ustar pjb pjb -- Topal: GPG/GnuPG and Alpine/Pine integration
-- Copyright (C) 2001--2010 Phillip J. Brooke
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License version 3 as
-- published by the Free Software Foundation.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see .
with Ada.Exceptions;
with Ada.Strings.Maps;
with Ada.Text_IO;
with Echo;
with Misc; use Misc;
package body Char_Menus is
function Menu (Prompt : in String := Default_Prompt) return Index is
use Ada.Strings.Maps;
use Ada.Text_IO;
C : Character;
begin
Debug("+Char_Menu.Menu");
if Accept_Chars'Length /= Char_Words'Length
or Accept_Chars'First /= Char_Words'First then
raise Arrays_Not_Matched;
end if;
if Config.Boolean_Opts(Debug) then
Debug("Char_Menu.Menu: Prompt is `" & Prompt & "'");
begin
for I in Accept_Chars'Range loop
Debug("Char_Menu.Menu: Group "
& Index'Image(I)
& " Accept_Chars=`" & ToStr(Accept_Chars(I)) & "'");
end loop;
exception
when The_Exception : others =>
Debug("Exception raised in Accept_Chars bit: "
& Ada.Exceptions.Exception_Name(The_Exception));
end;
begin
for I in Char_Words'Range loop
Debug("Char_Menu.Menu: Group "
& Index'Image(I)
& " Char_Words=`" & ToStr(Char_Words(I)) & "'");
end loop;
exception
when The_Exception : others =>
Debug("Exception raised in Char_Words bit: "
& Ada.Exceptions.Exception_Name(The_Exception));
end;
end if;
Put(Rewrite_Menu_Prompt(Prompt));
Entry_Loop:
loop
Echo.Clear_Echo;
Debug("Menu.Char_Menu: About to Get_Immediate");
Get_Immediate(C);
Debug("Menu.Char_Menu: Got: `" & C
& "' value " & Integer'Image(Character'Pos(C)));
Echo.Set_Echo;
-- Now, run through the menu.
for I in Accept_Chars'Range loop
if Is_In(C, To_Set(ToStr(Accept_Chars(I)))) then
Put(Do_SGR(Config.UBS_Opts(Colour_Menu_Choice))
& ToStr(Char_Words(I))
& Reset_SGR);
New_Line(2);
Debug("-Char_Menu.Menu with value "
& Index'Image(I)
& " for character `"
& C & "'");
return I;
end if;
end loop;
Debug("Menu.Char_Menu: No match for character `" & C & "'");
end loop Entry_Loop;
exception
when others =>
ErrorNE("Char_Menu.Menu: In exception handler. Re-raising.");
raise;
return Index'First; -- Never executed.
end Menu;
end Char_Menus;
topal-75/topal.tex 0000644 0001750 0001750 00000127442 11722471751 012420 0 ustar pjb pjb % Topal: GPG/GnuPG and Alpine/Pine integration
% Copyright (C) 2001--2012 Phillip J. Brooke
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License version 3 as
% published by the Free Software Foundation.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see .
\documentclass[a4paper,twoside,12pt,openright]{report}
\usepackage[utf8]{inputenc}
\usepackage{palatino,fancyhdr,amssymb,textcomp,txfonts,paralist}
\newcommand{\eg}{\textit{e.g.}}
\newcommand{\etc}{\textit{etc.}}
\newcommand{\ie}{\textit{i.e.}}
\newcommand{\vv}{\textit{vice versa}}
\usepackage[hyphens]{url}
\usepackage{hyphenat}
\usepackage{graphicx}
\renewcommand\familydefault{\sfdefault}
\usepackage{listings}
\lstset{language=,columns=fullflexible,escapechar=\%,keepspaces=true}
\lstset{basicstyle=\small\ttfamily}
\lstdefinestyle{type}{backgroundcolor=\color{green},showspaces=true}
\lstdefinestyle{response}{backgroundcolor=\color{yellow}}
\input{versionid.tex}
% Don't like Courier.
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{beramono}
\newcommand{\vefill}{\vspace*{\fill}}
\newcounter{saveenumi}
\newcommand{\saveenumi}{\setcounter{saveenumi}{\theenumi}}
\newcommand{\restoreenumi}{\setcounter{enumi}{\thesaveenumi}}
\newenvironment{enumerateleg}{\begin{enumerate}[(a)]}{\end{enumerate}}
\newlength{\Oldparindent}
\setlength{\Oldparindent}{\parindent}
% Maxwidth, from http://www.tex.ac.uk/cgi-bin/texfaq2html?label=grmaxwidth
\makeatletter
\def\maxwidth{%
\ifdim\Gin@nat@width>0.9\linewidth
0.9\linewidth
\else
\Gin@nat@width
\fi
}
\makeatother
% Screenshot figures. The filename and the caption.
\newcommand{\SSF}[2]{
\begin{figure}[htp!]
\centering
\fbox{\parbox{0.9\linewidth}{ \centering
\includegraphics[width=\maxwidth]{screens/#1}
\caption{#2}\label{fig:#1}}}
\end{figure}
(figure~\ref{fig:#1})}
\usepackage[bookmarksopen=true,bookmarksopenlevel=1,
bookmarksnumbered=true,
colorlinks=true, urlcolor=blue,
breaklinks=true,
pdftitle={Topal manual},
pdfauthor={Phil Brooke},
pdfsubject={Topal},
pdfkeywords={Topal, Pine, Alpine, OpenPGP, SMIME, GnuPG}
]{hyperref}
% Footing.
\fancyfoot{}
\fancyfoot[RO,LE]{\thepage}
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Title page/front cover
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pagestyle{empty}
\begin{titlepage}
\pdfbookmark[1]{Title page}{pdf:titlePage}
\setlength{\parindent}{0pt}
\raggedright
{\Huge\bf\scshape Topal\\\bigskip\large GPG/GnuPG and Alpine/Pine integration}\\[10ex]
{\Large Phil Brooke
}
\vfill
Release~\TopalRelease\\
\TopalBuildDate
\setlength{\parindent}{\Oldparindent}
\end{titlepage}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Inside front cover.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\vefill
\setlength{\parindent}{0pt}
{
Topal: GPG/GnuPG and Alpine/Pine integration
Copyright \copyright~ 2001--2012 Phillip J. Brooke
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see \url{http://www.gnu.org/licenses/}.
}
\setlength{\parindent}{\Oldparindent}
\cleardoublepage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Front matter, ToC, LoF, ...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\fancyhead{}
\pagenumbering{roman}
\setcounter{page}{1}
\pdfbookmark[1]{Table of contents}{pdf:TOC}
\tableofcontents
\cleardoublepage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Main matter.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pagenumbering{arabic}
\setcounter{page}{1}
\chapter{Introduction \& features}
Topal is a ‘glue’ program that links
\href{http://www.gnupg.org}{GnuPG}
and
\href{http://www.washington.edu/pine/}{Pine}/%
\href{http://www.washington.edu/alpine/}{Alpine}/%
\href{http://sourceforge.net/projects/re-alpine/}{``Re-Alpine'' (from
Sourceforge)}.
It offers
facilities to encrypt, decrypt, sign and verify emails, including
inline OpenPGP, MIME/OpenPGP and S/MIME. It
can also be used directly from the command-line.
\section{Features}
\begin{itemize}
\item Multiple inline PGP blocks can be processed in display filters.
\item Decryption and verification output can be cached to reduce the
number of times a passphrase is entered\footnote{Note that you should also
consider the use of \texttt{gpg-agent}.}. This also helps when
secret keys aren't always available, at the expense of storing
decrypted output.
\item MIME/OpenPGP (RFC2015/RFC3156) multipart messages can be sent
and received. Depending on configuration, this might involve
procmail or patching Alpine.
\item The deprecated application/pgp content-type can be sent and received.
\item S/MIME messages can be sent and received if \verb|gpgsm| is
available. (\verb|openssl| is also used in some circumstances, but
\verb|gpgsm| is still required.)
\item Topal can be used as Alpine's \verb|sendmail-path| command.
\item Topal has a remote sending mode (a server and a means of
accessing the server) for reading email on a distant computer via
SSH with secret keys on the local computer.
\item A range of mechanisms for selecting keys for both self and recipients.
\item There is a high level of configurability (although the
configuration interface does not expose all of it; you'll have to
edit \verb|.topal/config|).
\end{itemize}
\section{Terminology}
We use Pine and Alpine interchangably in this manual. The earliest
version of Pine that Topal supported was 4.44. When referring to
Thunderbird and Enigmail together, we sometimes just say Thunderbird.
Similarly, we often use GnuPG, GPG and sometimes OpenPGP and PGP interchangably.
\section{Version numbering}
Recent stable releases have been numbered 55, 56, \ldots. Prior to
release 55, the stable releases were 0.7.2, 0.7.8, 0.7.9 and
0.7.13.6.
\chapter{Important changes from previous stable versions}
\section{Important changes in release 70}
The \verb|use-agent| option sets GPG's \verb|--use-agent|
option as needed. Don't set it in any other way or it might be confusing\ldots.
\section{Important changes in release 68}
\begin{itemize}\item
The sending interface has changed. Selecting (for example) ‘e’ for
encrypt no longer immediately operates. Instead, the desired
operation is chosen, and then ‘g’ for ‘Go!’ is used. This allows
defaults to be associated with keys and email addresses in a
sensible way.
\item The MIME viewer setting \verb|mime-viewer|
has been replaced by two new settings, one for decrypting and one
for verifying. You should set these to suit your preferences. (The
redundant line will be dropped the next time you save your
configuration inside Topal.)
\end{itemize}
\section{Important changes in release 65}
An additional patch has been added. This should make the procmail
recipe redundant. More testing is required: it may have broken other
Alpine features.
\section{Important changes in release 60}
MIME sending now requires MIME-tool; mime-construct is no longer
used. See the compilation and installation instructions.
\section{Important changes in release 58}
The default configuration no longer uses absolute paths.
\section{Important changes in release 55}
\begin{itemize}\item
If you use a non-English locale, please check that Topal still works
as expected (I replaced code that fixed some locale problems).
\item The Alpine patch is based off my old Pine patches, but does a
little more. You will need to set the
\begin{quote}
\verb|Enable Topal hack for OpenPGP/MIME messages|
\end{quote}
option in the
hidden configuration list. Bug reports welcome.
\item The
\verb|--fix-email| wrapper no longer creates a
multipart/alternative: it creates a multipart/misc wrapper instead.
Please check that your procmail recipe includes a suitable backup in
case this doesn't work for you.
\end{itemize}
\section{Important changes in version 0.7.10}
The recommended procmail recipe has been changed.
\section{Important changes in version 0.7.8}
\verb|topal-fix-email| and \verb|topal-fix-folder| have been replaced by the
main topal binary. Change \verb|topal-fix-email| in your .procmailrc to be
\verb|topal --fix-email|. (Or add symlinks: the binary checks what it has been called as.)
You \emph{must} clear your cache otherwise the changes made for\linebreak
\verb|inline-separate-output| \marginpar{New in version~0.7.8.} will break (this occurs regardless of whether
the option is on or off). This new feature shows the GnuPG/Topal
output separately, then hands back the decrypted or verified output
without any wrappers. This makes it more suitable for dealing with
attachments (but you need to set it manually via
\verb|topal -config|).
Finally, the send menu has a new option: ‘Pass through unchanged’.
This does nothing to the message so, you can
always have Topal invoked as a filter for sending.
\chapter{Installation and configuration}
\section{Options}
Topal supports a range of modes; some have particular requirements:
the following table summarises them.
\newcommand{\colh}[1]{\rotatebox{89}{\parbox{5cm}{\raggedright #1}}}
\noindent\begin{tabular}{lccccccc}
\hline
&
\colh{Apply patch \texttt{-1} to Alpine}
&
\colh{Apply patch \texttt{-2} to Alpine}
&
\colh{Configure Alpine's \texttt{sending-filters}}
&
\colh{Configure Alpine's \texttt{display-filters}}
&
\colh{Configure Alpine's \texttt{sendmail-path}}
&
\colh{Configure \texttt{.mailcap}}
&
\colh{Configure \texttt{.procmail} or run \texttt{topal --fix-email}}
\\
\hline
Encrypt/sign inline OpenPGP &&&$\vee$&&$\vee$&&\\
Decrypt/verify inline OpenPGP &&&&\checkmark&&&\\
Encrypt/sign MIME/OpenPGP &$\vee$&&&&$\vee$&&\\
Decrypt/verify MIME/OpenPGP &&$\wedge$&&&&$\wedge$&\textopenbullet\\
Encrypt/sign S/MIME &\textopenbullet&&&&$\star$&&\\
Decrypt/verify S/MIME &&$\wedge$&&&&$\wedge$&\textopenbullet\\
\hline
\end{tabular}\bigskip
\noindent Key:
\begin{tabular}[t]{cl}
\hline
\checkmark&The only option.\\
$\wedge$&Use both of these together.\\
$\vee$&Use either of these.\\
$\star$&This is a preferred option, but you can use an alternative (\textopenbullet).\\
\textopenbullet&This is a possible option, but there is a better
option ($\star$ or $\wedge$).\\
\hline
\end{tabular}\bigskip
Inline OpenPGP is processed via Alpine's sending and display filters.
So you need to configure this within Alpine.
MIME messages are more complicated. MIME/OpenPGP messages can be sent
if patch 1 is applied to Alpine. However, although the corresponding
S/MIME messages appear to be correctly formed, use of patch 1 requires
that the message is embedded within a multipart/mixed message --- and
other mail clients (such as Mozilla Thunderbird and MS Outlook) will
not handle them properly. So for S/MIME sending, you are strongly
recommended to use Topal as a \verb|sendmail-path| for Alpine.
Receipt of MIME messages (both OpenPGP and S/MIME) is best handled via
Alpine with patch 2. This will cause Alpine to crash if your
\verb|.mailcap| is not properly configured to handled the cryptography
multipart/* types. An alternative is to invoke Topal's
\verb|--fix-email| mode via \verb|.procmail| which rewrites the
top-level cryptographic message into a multipart/mixed message
that can be more easily processed by Alpine.
\section{Compilation and installation}
To compile Topal, you need
\begin{compactitem}\item
a working C compiler,
\item
the GNU Ada Compiler (GNAT),
and
\item some common libraries, including \verb|readline| (e.g., the
package \linebreak\verb|libreadline6-dev| on Debian).
\end{compactitem}
There is a makefile: simply type \verb|make|.
Type \verb|make install| to actually install. The default location
is \verb|/usr|, so you'll need to be root to install. Alternatively, use
\linebreak\verb|make install INSTALLPATH=/usr/local| to install into
\verb|/usr/local|. (Or use the more specific variables \verb|INSTALLPATHBIN|,
\verb|INSTALLPATHMAN|, \verb|INSTALLPATHDOC| and \verb|INSTALLPATHPATCHES|.)
\subsection{Cygwin}
Before using the makefile, please apply the patch
\verb|cygwin.patch|. I haven't recently tested this\ldots.
\subsection{MIME-tool}
MIME sending requires the Topal version of Jeffrey S.~Dutky's
\verb|mime-tool|. This is included with the Topal sources, and is
compiled and installed at the same time using the Makefile.
\subsection{MIME viewing}
MIME viewing can be handled via
\begin{compactenum}\item
metamail, \item run-mailcap, or \item by saving to a file (mbox format) in the \verb|~/.topal|
directory and viewing with Alpine.
\end{compactenum}
If
you are using patch~2
(see ``Alpine patches'' below), then
depending on your Alpine configuration, Alpine might say something
like
\begin{quote}
\verb|Attachment SIGNED unrecognized. Try opening anyway?|
\end{quote}
--- you
should say \verb|yes| in that case.
\subsection{GNU sed}
GNU sed is required. I only discovered this when using Topal on Mac
OS X\ldots.
\section{Alpine patches}
There are two patches, for a range of versions of Pine and Alpine.
Patch 1 deals with sending MIME messages (\verb|-sendmime|); patch 2 with receiving them.
\begin{centering}
\begin{tabular}{lcc}
\hline
&Patch 1&Patch 2\\
\hline
Pine 4.44&\checkmark&\\
Pine 4.50&\checkmark&\\
Pine 4.53&\checkmark&\\
Pine 4.58&\checkmark&\\
Pine 4.60&\checkmark&\\
Pine 4.64&\checkmark&\\
Alpine 1.00&\checkmark&\\
Alpine 2.00&\checkmark&\checkmark\\
Alpine 2.02&\checkmark&\checkmark\\
\hline
\end{tabular}
\end{centering}
\bigskip
To apply these patches,
\verb|cd| into the Pine or Alpine source directory and use the
\verb|patch| command, \eg, \verb|patch -p1 < -2.02.patch-1|.
Please note that the Alpine patches also modify Alpine's
configuration. There is a hidden preference ‘enable Topal hack’
(\verb|enable-topal-hack|) that you need to enable.
% It doesn't seem to have broken anything else.... It seems to work for
% sending via an SMTP server - it might break for sending via
% /usr/lib/sendmail (if it does, please send me a debug trace by
% invoking pine with ‘\verb|-d 9|’).
\section{Alpine filter configuration}
Assuming that the topal binary is installed in \verb|/usr/bin|, set up
the Alpine sending and display filters as follows:
\begin{lstlisting}
display-filters=_BEGINNING("-----BEGIN PGP ")_ /usr/bin/topal
-display _TMPFILE_ _RESULTFILE_
sending-filters=/usr/bin/topal --read-from _INCLUDEALLHDRS_
-send _TMPFILE_ _RESULTFILE_ _RECIPIENTS_,
/usr/bin/topal --read-from _INCLUDEALLHDRS_
-sendmime _TMPFILE_ _RESULTFILE_ _MIMETYPE_
_RECIPIENTS_
\end{lstlisting}
You can choose either or both of the sending filters. The \verb|-sendmime|
option allows the user to choose the MIME type of the outbound
email. (Legacy fixes are in place that make \verb|-decrypt| and \verb|-verify|
behave the same as \verb|-display|.) Note that
\verb|_RECIPIENTS_| must be last.
The \verb|--read-from _INCLUDEALLHDRS_|\label{pg:readFrom} text makes Topal attempt to
guess a suitable key for signing and self-encryption. If multiple
possible keys match, then you'll be offered a menu of the keys. Use
of this option is strongly recommended (but can be omitted).
\section{Alpine sendmail-path configuration}
As an alternative (or addition!) to setting filters (above), you can set
\begin{lstlisting}
sendmail-path="/usr/bin/topal -asend"
\end{lstlisting}
Also see section~\ref{sec:smp-config} for more details on configuring
this mode.
This option allows Topal to handle attachments added within Alpine,
whereas sending using patch 1 requires that attachments are added via
Topal's interface (otherwise the attachments aren't covered by
encryption or signing).
\section{Mailcap configuration}
To decode MIME RFC2015/3156 multipart/signed and /encrypted messages
requires help via the ``mailcap'' system. Add in either the user mailcap
configuration (\verb|.mailcap|) or the system configuration
(\verb|/etc/mailcap|) the lines
\begin{lstlisting}
multipart/signed; /usr/bin/topal -mime '%\%%s' '%\%%t'; needsterminal
multipart/encrypted; /usr/bin/topal -mime '%\%%s' '%\%%t'; needsterminal
application/pgp; /usr/bin/topal -mimeapgp '%\%%s' '%\%%t'; needsterminal
\end{lstlisting}
Note that Alpine has been known to crash if you compile it with the
second patch, but do not set up your mailcap file to handle these
multipart types.
\section{Procmail configuration}\label{sec:procmail-configuration}
From Topal version 65, this recipe is no longer needed if you are
using patch~2.
If you prefer to modify inbound multipart messages rather than use
patch~2, you should add this recipe to your \verb|.procmailrc|:
\begin{lstlisting}
:0fw
| /usr/bin/topal --fix-email
\end{lstlisting}
This causes Topal to examine all inbound emails. Those with top-level
multipart/signed or multipart/encrypted MIME types are modified to add
a multipart/misc wrapper so that Alpine can hand it off to
Topal. All other emails are left unchanged.
I strongly advise that you also use one of the backup
recipes from the procmail manual.
\section{Topal configuration}
Create a directory called ‘\verb|${HOME}/.topal|’. This is
currently hard-coded into Topal. Create the basic configuration file
by running topal with the \verb|-dump| or \verb|-default| options.
This file should be named ‘\verb|config|’.
All \verb|.topal| files are silently ignored if they cannot be found.
Comments begin with a \verb|#| in the first column, and run to the end of a
line. They are totally ignored and are not currently preserved.
Parsing errors cause an exception.
If you want to include strings with spaces, you'll need to quote them
with double-quotes (\verb|"|). Double-quotes themselves can be
included by ‘stuffing’ (\verb|""|).
\chapter{Usage}
\section{Help!}
\verb|-help| as the first argument dumps a help message.
The help message is derived from the \verb|help.txt| file in the
source distribution.
See \verb|help.txt| for information on non-Pine use of Topal (section~\ref{sec:nonpine}).
Send \href{mailto:pjb@lothlann.freeserve.co.uk}{email to me} if you're really stuck.
\section{Configuration}
\verb|-config| as the first argument brings up the configuration menu.
This menu is also available when sending (so that the signing key can
be changed).
However, not all features can be configured via the menus. In some
cases, you'll need to edit \verb|.topal/config|. Later sections in
this manual give specific instructions for particular features.
If you want to change the comment mentioning Topal when sending
messages (\ie, the bit saying \verb|Topal (http://freshmeat.net/projects/topal)|) then modify
\verb|sending-options| (via the configuration menu or the \verb|config|
file).
Colours were introduced in release 71. If you want to turn them off,
set \verb|ansi-terminal=off| in the \verb|config| file. You can
change the colours by setting
\verb|colour-menu-title|,
\verb|colour-menu-key|,
\verb|colour-menu-choice|,
\verb|colour-important|,
\verb|colour-banner| and
\verb|colour-info|. The codes are the escape codes (see, for
example, colour table in the
\url{http://en.wikipedia.org/wiki/ANSI_escape_code} Wikipedia article on ANSI escape codes).
\section{Decryption/verification}
Depending on configuration, Topal will either ignore the file
altogether, ask you what you want to do with it, or proceed to
process the file automatically.
GPG will ask you for your passphrase when it needs it.
Caching is in place; the results of decryption and verification are
(subject to configuration) saved in \verb|~/.topal/cache|. The results of
caching mean that you won't be repeatedly asked for your passphrase,
at the expense of storing decrypts in the clear.
Be warned: Topal often invokes \verb|less| to view something. So you'll
need to use \verb|q| to get out of it. \verb|metamail|
or \verb|run-mailcap| may be called for anything
after MIME processing.
A new option \marginpar{New in version~0.7.8.} called \verb|inline-separate-output|
concerns inlined (\ie, not MIME) messages. If the option is on, then
the Topal/GnuPG output will be shown to you by \verb|less|. Then the
decrypted or verified output will be handed back to Pine/Alpine. This is the
way to approach attachments. However, you will normally want to keep
this option off, because if you're reading (for example) BugTraq
mailings, then it will want you to hit \verb|q| an awful lot\ldots.
\section{Sending}
\subsection{Main send menu}
Topal initially displays some chatter about selecting keys,
including (if possible) a key for the sending user. After that, you
will be presented with the sending main menu~\SSF{mainSendMenu.png}{Main
sending menu}. Some options (\eg, those
relating to MIME features) will not be offered unless you use
the \verb|-sendmime| option.
‘Abort’ tells Pine/Alpine you don't want Topal to process the email anymore.
‘Pass through unchanged’ does nothing to the message. This means that
you can always have Topal invoked for sending.
‘Add own key’ adds an ‘encrypt to self’ key. (It is added by default,
but if you remove it, this is a quick way to restore it.)
When you select ‘Go!’ you will be asked to confirm the command-line,
and after processing, \verb|less| is invoked to visually check that
the desired result has been achieved. Again, a confirmation is asked
for.
Topal can offer a choice of three MIME types. Don't use (2 --- app/pgp)
unless you really know what you're doing. (4 --- multipart encap) is
only relevant if you are signing and encrypting: this encapsulates a
MIME signed message inside an encrypted message (but Thunderbird
doesn't seem to process the signature on these). Otherwise, we do
both operations at once. (If you choose ‘clearsign’ and
‘multipart/*’, then all trailing blank lines will be deleted. Note
also that Pine/Alpine appears to delete trailing whitespace in
trailing blank lines.)
‘Configuration’ offers the same menu that is available from the
\verb|-config| option.
\subsection{List current recipient keys}
‘List current recipient keys’ offers a list of
recipients~\SSF{keyListMenu.png}{Key list menu}.
‘Quit and return to main send menu’ sends you back to the first menu.
‘Add key from main keyring’ prompts you for a search pattern. It will
do a general search on your GPG keyring \emph{and add} all matching keys. Beware of just pressing
enter --- it will select \emph{all} keys on your keyring.
A better alternative is to use the ‘select after search’ option. This
also does a search on your GPG keyring, but then you must select
one key to be added to your list of recipients.
\subsection{Examine key menu}
Selecting a key will offer a third menu (a similar menu is offered
when selecting a single key)~\SSF{examineKeyMenu.png}{Single key menu}.
‘Return to key list’ takes you back to the second menu.
‘Display details of key (less)’ simply uses GPG to list the
key details via \verb|less|. You'll need to use \verb|q| to get out of \verb|less|.
‘Verbose details of key (less)’ pipes verbose output from GPG for this
key into gpg. Again, you'll need to use \verb|q| to get out of \verb|less|.
‘Remove key from list’ removes the key from this recipient list.
\section{Command-line usage}\label{sec:nonpine}
\subsection{Sending (\texttt{-nps})}
If you invoke Topal on the command-line with a filename as an
argument, it will offer the sending functions on that
file~\SSF{npsSendMenu.png}{Non-pine sending menu}. It
doesn't actually send anything: instead it allows you to encrypt,
sign, \etc\ the message. {\em You have a choice of overwriting or
preserving the original file (this bit is case-sensitive).} So \verb|e|,
\verb|s| and \verb|c| are different from \verb|E|, \verb|S| and
\verb|C| respectively.
The main purpose of this mode is for encrypting or signing attachments
before they are attached to the message in Pine/Alpine. Beware that Pine/Alpine
does not feed the attachments to a sending filter. Or you could use
the attachments option when using Pine with MIME emails.
MIME functions are not available in this mode.
\subsection{Receiving (\texttt{-pd})}
\marginpar{New in release~71.}
Invoking Topal with only \verb|-pd| as an argument causes it to
read a message from standard input and attempt to decrypt/verify
it. This is useful for piping MIME messages from other
applications.
\section{Remote and server mode}
Suppose you are reading your email on a remote host via \verb|ssh| (as I
often do). You now want to compose an email and sign it, but your
secret key is only accessible on the local computer. Topal has
rudimentary support for this (primarily to support my style of
working). This comes in two parts: a ‘server’ mode to run on the local
computer (with access to the secret key) and a remote option in the
sending menu.
The server mode (on the local host) is started by running
\verb|topal -server|. This is where GPG requests for signing are made.
When sending, you can choose ‘remote’. This prompts for the host to
connect to using \verb|ssh|/\verb|scp|: this host should be running the ‘server’.
The files are sent to the local server, processed by the server, then
the results are copied back. \verb|ssh| and \verb|scp| are both used: because
they're used repeatedly, you might want to use key-based
authentication and have the key added to a current \verb|ssh-agent|.
There is also a remote mode for receiving, with a similar behaviour as
for sending. Alternatively could use something
like unison (or some other file synchroniser or a simple scp) to move
the email(s) concerned, then view them on the local computer.
A generally better alternative is to process your email locally by
using IMAPS and SMTPS to remotely access the mail server.
\section{Fixing multipart emails}
Two scripts used to be included with topal (long ago):
\verb|topal-fix-email| and \verb|topal-fix-folder|. They have
been replaced by the \verb|--fix-email| and \verb|--fix-folder|
command-line options to the main binary.
\verb|topal --fix-email| modifies any email that is (at the top
level) a multipart/signed or multipart/encrypted message. It creates
a multipart/misc message instead: this revised message is simply a
wrapped version of the original message so that Pine/Alpine can pass the
signed or encrypted part to Topal.
Usage:
\begin{itemize}\item
\verb|topal --fix-folder ...|
fixes the named email folders.
\item
\verb|topal --fix-email| takes no arguments; it accepts
a single email on stdin. Ideally, it should be invoked by procmail
(see section~\ref{sec:procmail-configuration}).
\end{itemize}
\verb|topal --fix-email| has a simpler mode (\verb|--simple|) where it
pretends that there are two MIME content types:
‘application/x-topal-encrypted’ and ‘application/x-topal-signed’. You
might prefer using this. These effectively rename the multipart email
instead of wrapping it.
Why do we need this? If we just set the \verb|.mailcap| file
for, say, multipart/signed, then Alpine (at least version 1.00) is
unable to handle a top-level multipart/signed email: an error message
starting
\begin{quote}
\verb|Can't find body for requested message|
\end{quote}
is seen. But
multipart/signed inside a multipart/mixed (or multipart/alternative,
\etc) can be successfully handed-off to Topal.
Replying to such messages is a pain: you'll have to save off the
actual message and read it in. Suggestions on fixing this are welcome\ldots.
See \verb|Workaround.Fix_Email| in the sources for more details.
\chapter{Notes}
This chapter includes a number of notes, explanations and further details.
\section{The Pine/Alpine patches, and sending other attachments}
What does the (first) patch to Alpine do? It removes some of the safety
checking when changing the content-type (\verb|_MIMETYPE_|) in a filter.
Normally, if the returned content-type is not text/*, then the entire
content-type is dropped by Alpine.
The patch instead adds a flag, ‘\verb|topal_hack|’, and sets this if the
returned content-type is not text. From time-to-time, we
pretend that the body is normal text. We take a little care to check
if this message is already a multipart message, so hopefully, the normal
sending of attachments still works. However, these attachments are
\emph{not} encrypted or signed by Topal. You will need to separately
process them before attaching them in Alpine (\eg, using the
command-line mode described in section~\ref{sec:nonpine}) or add them
using Topal's attachment menu (if you are using Topal's MIME sending features).
The second patch file \marginpar{New from Topal release~65 for Alpine~2.00.}
slightly modifies some of the mail reading code to allow .mailcap
settings to act directly on top-level multipart messages. But see
section~\ref{sec:crash-second-patch} if you find Alpine crashes when
this patch is used.
\section{Key IDs and keylists}
Topal internally lists keys by their fingerprint. It uses GPG to look
up key fingerprints by using whatever GPG can cope with.
Duplicate keys are silently suppressed. Removing a key only removes
one instance, so if somehow you've coerced Topal to list duplicates
(which is quite easy, since adding a key with its short key ID, and
the same key with its fingerprint will add two identical keys).
The way that Topal chooses the keys is as follows:
\begin{itemize}\item
For each recipient email address (supplied by Pine)
\begin{enumerate}\item
For each matching line in keylist, use the key ID to get a
fingerprint, and add the key to the list. \item If there are no
matching lines in keylist, try to get a fingerprint via just that
email address (but exclude \verb|xk| configuration entries).
\end{enumerate}
\end{itemize}
The keylist is a way to say, ‘for this particular email address, use
this particular key’. In your \verb|config| file, include lines
such as
\begin{lstlisting}
ake=50973B91,philb@soc.plym.ac.uk
ake=50973B91,pjb@lothlann.freeserve.co.uk
\end{lstlisting}
These mean ‘use key 50973B91 for the given email addresses’.
Similarly,
\begin{lstlisting}
xk=50973B91
\end{lstlisting}
means ‘don't use key 50973B91’. There are also similar
\verb|sake| and \verb|sxk| options for selection of secret keys
via the (recommended) \verb|--read-from| option (page~\pageref{pg:readFrom}).
For S/MIME, the same lists are used. If a key isn't relevant (an
S/MIME key when using OpenPGP or \vv) it is ignored.
Importantly, you need to use \verb|sake|/\verb|sxk| to give the
signing key for S/MIME, as \verb|my-key| only applies to OpenPGP
usage.
\section{Sending defaults}
\marginpar{New in release~68.}
verb|sd| lines in your \verb|config| file can assign a default to a key ID or email address.
The special string \verb|@ANY@| matches any email address (or
key).
The \emph{last matching} \verb|sd| expression applies, so use
\verb|@ANY@| first.
The individual letters mean\\
\begin{centering}
\begin{tabular}[t]{ll}
\verb|n|&no GPG\\
\verb|e|&encrypt\\
\verb|s|&sign and encrypt\\
\verb|c|&clearsign\\
\end{tabular}
\begin{tabular}[t]{ll}
\verb|I|&inline plain\\
\verb|A|&app pgp\\
\verb|M|&multipart\\
\verb|E|&multipart encapsulated\\
\verb|P|&S/MIME (not OpenPGP)\\
\end{tabular}
\end{centering}
\begin{samepage}
\noindent Example:
\begin{quote}
\verb|sd=pjb@lothlann.freeserve.co.uk,eI|
\end{quote}
means that the default settings for the given address are encryption
and inline plain.
\end{samepage}
Topal will warn you if you are sending to multiple recipients,
\verb|sd| has selected encryption, and not all of the recipients have
keys. However, it won't stop you continuing and sending an email that
some recipients can't read.
\section{Sendmail-path configuration}\label{sec:smp-config}
\marginpar{New in release~73.}
\verb|sc| lines in your \verb|config| file assign a \verb|sendmail-path|
command to the ‘from’ (sending)
email address.
Again, the special expression \verb|@ANY@| matches any email address
(but not key id's) and the last matching \verb|sd| expression applies.
Example:
\begin{quote}
\verb|sc=pjb@lothlann.freeserve.co.uk,mstmp -a default|
\end{quote}
means that emails sent using that address will actually be sent using
the (external) \verb|msmtp| program. If you are using Topal as a
\verb|sendmail-path|, you must ensure that there is a suitable
\verb|sc| line, as Topal does not actually know how to send email.
\subsection{Additional (bcc) recipients}
Note that \verb|msmtp| can add additional recipients, \eg,
\begin{quote}
\verb|mstmp -a default -- pjb@lothlann.freeserve.co.uk|
\end{quote}
\subsection{Message-ID munging}
The \verb|sendmail-path| mode can also modify Message-IDs and Content-IDs. The
configuration option \verb|replace-ids| controls this. If set to 0,
nothing is changed; 1 causes the Message-ID to be altered; and 2 (the
default) alters both Message-ID and Content-IDs (of attachments).
The Message-ID is altered from the standard Alpine form of
\begin{quote}
\verb||
\end{quote}
to
\begin{quote}
\verb|<1103063481092.1140.NCYBIHRU%user@somehost.org>|
\end{quote}
The email address used in the replacement is based on the From line.
\subsection{Send tokens}
The \verb|sendmail-path| mode also enables the \verb|st| (send token) lines in the
\verb|config| file. These lines have the form
\begin{quote}
\verb|st=user@example.org,somepasswordstring|
\end{quote}
If the Message-ID is altered and there is a matching send token, the
original Message-ID is encrypted and stored in the headers.
Additionally, a header is added based on this token, the Message-ID
and From line. This can be used to match inbound emails (self blind
copies) via procmail, \eg,
\begin{lstlisting}
:0fw
* ^From: .*\$
| /usr/local/bin/topal --check-send-token somepasswordstring
:0:
* ^X-Topal-Check-Send-Token: yes$
.topal-cc/
\end{lstlisting}
This causes emails apparently from \verb|user@example.org| to be
passed to Topal, which checks the headers. If the header token
matches for that password, a new header, \verb|Topal-Check-Send-Token: yes| is added.
Then procmail can filter on the basis of this header.
\subsection{Missing attachments trap}
\marginpar{New in Topal 73.} If set, the configuration line
\verb|attachment-trap=on| causes Topal to complain if the message contains
the string “attach” but it does not have any attachments.
This is only effective if Topal is running as a
\verb|sendmail-path|.
\section{Errors}
Bad things happening should result in Topal setting its exit status to
‘failed’, so Pine should detect this and not send your email.
Bug reports are welcome: send them by email to me (contact details in section~\ref{sec:author}).
\section{Saving encrypted attachments}
If an attachment is a plaintext PGP ASCII-armoured message, then Topal
will be invoked by Pine. You probably want to say ‘no’ when asked
here (beware of your configuration options here). Otherwise, you'll
get a decrypted file with the original attachment filename, plus the
various Topal headers.
\section{Locale problems}
GPG does not do any encoding of input data. This means that the
encoding is dependent on Pine/Alpine and Topal. If a message is sent
with one encoding and received by a user running in a different
locale, then we might end up with a good message not verifying (\ie,
bad signature).
I currently have no way to automatically fix this. However, the
\verb|--ask-charset| option will ask if you want to change the encoding. If you
know that the message was written by a UTF-8 user (and you're in a
different locale), this might help. (This only happens if a bad
signature is returned.)
I know it's a kludge. I'd be interested to hear success and failure
reports.
\section{“\texttt{Couldn't find certificate needed to sign.}”}
A regular query (for both Topal and other OpenPGP filters) concerns
the message “\texttt{Couldn't find certificate needed to sign.}” This message
is part of Alpine's S/MIME support: it is nothing to do with Topal.
One option is to turn off the internal S/ MIME support via the
(hidden) config option ("\verb|S/MIME -- Turn off S/ MIME|").
\section{Cleaning up the cache}
You might want to run something like
\begin{quote}
\verb|find ${HOME}/.topal/cache -mtime +7 | xargs rm|
\end{quote}
to remove all the cache files that are a bit old (in this example, 7
days old or older).
\section{Remote and server mode}
When remote is invoked in a sending menu:
\begin{itemize}
\item The host has to be chosen for \verb|ssh|/\verb|scp|. \item Because Topal
might be outside the normal path, you'll be asked for that too.
\item The sender \verb|scp|s the relevant files into
\verb|.topal/server|. \item The sender calls
\begin{quote}
\verb|ssh (server) -remotesend ...|
\end{quote}
or
\begin{quote}
\verb|ssh (server) -remotesendmime ...|\end{quote}
. \item The invocation of
\verb|-remotesend| or \verb|-remotesendmime| triggers the server to
run a new instance of Topal on the local computer. \item When
that instance is finished, the relevant files are copied back, along
with the return value.
\end{itemize}
For receiving: if decrypt-not-cached/decrypt-cached are set to 2
(ask), then as well as offering to decrypt (yes or no), it will also
offer remote decryption. The caching settings are irrelevant at this
point.
\section{Working with GPG Agent}
The \verb|use-agent| configuration option has three values:
(1) never use an agent, (2) only use it for decryption and (3) always use
it. Don't put GPG's \verb|--[no-]use-agent| options in any other
configuration options.
Notes:
\begin{enumerate}\item
\verb|--no-use-agent| is deprecated in some versions of GPG.
\item If you change \verb|trustlist.txt| (when using \verb|gpgsm|,
\ie, GnuPG for S/MIME) then remember to send the \verb|HUP| signal
to your current GPG agent.
\end{enumerate}
\section{Decryption prerequisite}
This relates to the configuration option \verb|decrypt-prereq|.
If empty (the default), this is
ignored. Otherwise, if decryption is required (\ie, a non-cached
encrypted block is found) it will run the command stated (this should
be just the command name, with no arguments). If the command's exit
status is
0, then decryption continues. If not, then no decryption is attempted.
I've introduced this for the case where decryption keys are not always
available. It is a nuisance for Topal to offer to decrypt when it
cannot. Example: the secret key ring is kept on removable media.
Then set
\begin{quote}
\verb|decrypt-prereq=/path/to/topal-decrypt-prereq|
\end{quote}
The
executable file \verb|/path/to/topal-decrypt-prereq| contains
something like
\begin{quote}
\verb|mount grep /path/of/keyring > /dev/null|
\end{quote}
This returns 0 if that path is found, and 1 otherwise.
\section{Crash with second patch when reading multipart messages}\label{sec:crash-second-patch}
Some Alpine crashes have been traced to the second Topal patch.
This occurs when you have compiled Alpine using this patch, but not
set up your \verb|.mailcap| configuration
appropriately.
\section{New releases}
To be notified of new releases of Topal, send an email to me.
\section{Interoperability}
I have tested Topal's interoperability with MS Outlook (both IMAP and
Exchange) and Thunderbird. It works in all tested cases, except as
follows.
\begin{itemize}
\item At least one instance of MS Exchange rewrites the content-*
headers of inbound clearsigned messages with attachments, which results in
the signature failing to verify. This also affects messages sent
from Thunderbird and MS Outlook. However, it does not apply to all MS
Exchange systems.
\item MS Outlook and Thunderbird do not handle clearsigned messages
properly when the clearsigned message is itself part of a
multipart/mixed message. The only way to reliably send messages to
users of these systems is via the \verb|sendmail-path| mode.
\end{itemize}
\section{Hints}
\begin{itemize}\item
Consider using GPG's \verb|--trusted-key| option in Topal's
\verb|gpg-options| configuration setting. This is useful if you keep your
secret keys offline. \item Use the \verb|--read-from| option (page~\pageref{pg:readFrom}), especially if you
use multiple roles rather than setting \verb|my-key|.
\end{itemize}
\chapter{Author}\label{sec:author}
Phil Brooke wrote this, partially out of boredom, but mostly because
he wanted a GPG/Pine add-on to do exactly what he wants. There are
many similar programs.
If you like this program, please tell me. If you'd like it better
with changes, please tell me what changes you want. If particular
items on the ‘To do’ list are important to you, let me know. In
particular, if you find bugs, feel free to tell me the details by
email.
I can be emailed on
\href{mailto:pjb@lothlann.freeserve.co.uk}{\tt pjb@lothlann.freeserve.co.uk}.
My key ID is 0x50973B91; the key is available from web pages and public key
servers.
If you want to send snailmail to me, email me for my (physical) address.
\chapter{Licence}
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see \url{http://www.gnu.org/licenses/}.
(See the file \verb|COPYING|.)
\chapter{To do}
\begin{itemize}\item
Planned releases:
\begin{itemize}\item
Improve attachments code (and add some
documentation).
\end{itemize}
\item Better error
handling, particularly when missing dependencies such as
mime-construct or metamail.
\item Add signal handlers.
\item
Catch GPG keyboard interrupt.
\item Should we check that the
infile matches the cache file even if the MD5 hash matches? (We'd
need to store the infile in the cache as well.)
\item Check
through code: all external calls should check return values.
\item Refactor code.
\item Add interrupt option at very beginning
of execution? (which would bring up the configuration menu?)
\item Associate extra options with particular keys?
\item
Configuration routine for managing keys/config/keylist?
\item
Implement rest of configuration menu.
\item Make a much nicer
interface all round....
\item Separate out all the constant
strings -- so that we can have internationalization.
\item
Context-sensitive help throughout (modify mkhelp to create multiple
procedures, or do it by number?); add COPYING option?
\item More
receiving/decrypt options: include both plaintext and
ciphertext.
\item Add periodic cache cleanup when Topal is
invoked?
\item Add logging for workaround mode (report time of
email processing (include PID); indicate if the file was changed or
not)?
\end{itemize}
\chapter{Change log}
The change log is kept in a separate file, \url{Changelog.html}.
\end{document}
topal-75/sending-clearsign.adb 0000644 0001750 0001750 00000022177 11722471751 014622 0 ustar pjb pjb -- Topal: GPG/GnuPG and Alpine/Pine integration
-- Copyright (C) 2001--2012 Phillip J. Brooke
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License version 3 as
-- published by the Free Software Foundation.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see .
separate(Sending)
procedure Clearsign (Tmpfile : in String;
Non_Pine : in Boolean;
Mime : in Boolean;
Mimefile : in String;
Selection : in Send_Modes;
Mime_Selection : in MIME_Modes;
AL : in Attachments.Attachment_List;
Hdrfile : in String;
Recipients : in UBS_Array;
Actual_Send : in Boolean;
New_Headers : out UVV;
AS_Content_Type : in String) is
Out_File : constant String := Temp_File_Name("out");
SFD_File : constant String := Temp_File_Name("sfd");
QP_File : constant String := Temp_File_Name("qp");
TDS_File : constant String := Temp_File_Name("tds");
SMIME_Opaque : YN_Index;
begin
-- Run GPG.
if Mime and then (Mime_Selection = Multipart
or Mime_Selection = SMIME) then
-- We need to do something different with Tmpfile.
-- First, we delete all trailing blank lines.
begin
Prepare_For_Clearsign(Tmpfile,
QP_File,
AS_Content_Type);
-- Call out to attachments in case we have to modify QP_File.
Attachments.Replace_Tmpfile(QP_File, AL);
-- Then we clearsign it.
if Mime_Selection = SMIME then
-- Offer to do this opaquely. Note that there isn't an
-- analogue of this for OpenPGP/MIME.
Ada.Text_IO.New_Line(3);
Ada.Text_IO.Put_Line("Some mail servers mangle clearsigned messages. Instead, you could");
Ada.Text_IO.Put_Line("send this message as an opaque signed message. However, if you send");
Ada.Text_IO.Put_Line("an opaque signed message, the recipient will need an S/MIME capable");
Ada.Text_IO.Put_Line("mail user agent to read it.");
Ada.Text_IO.New_Line;
SMIME_Opaque := YN_Menu("Send this as an opaque message? (Answer ‘n’ to send clearsigned.) ");
if SMIME_Opaque = Yes then
Externals.GPG.GPGSM_Wrap(" --base64 --sign --local-user "
& Value_Nonempty(Config.UBS_Opts(my_key))
& " "
& " --output "
& TDS_File
& " "
& QP_File,
TDS_File,
SFD_File);
else
Externals.GPG.GPGSM_Wrap(" --base64 --detach-sign --local-user "
& Value_Nonempty(Config.UBS_Opts(my_key))
& " "
& " --output "
& TDS_File
& " "
& QP_File,
TDS_File,
SFD_File);
end if;
else
Externals.GPG.GPG_Wrap(" --detach-sign --textmode --armor --local-user "
& Value_Nonempty(Config.UBS_Opts(my_key))
& " "
& UGA_Str(Signing => True)
& " "
& " --output "
& TDS_File
& " "
& QP_File,
TDS_File,
SFD_File);
end if;
exception
when others =>
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
"Exception raised in Sending.Clearsign (GPG MIME/3 block 1)");
raise;
end;
else
begin
Externals.GPG.GPG_Wrap(" --clearsign --textmode --local-user "
& Value_Nonempty(Config.UBS_Opts(my_key))
& " "
& UGA_Str(Signing => True)
& " --output "
& Out_File
& " "
& Tmpfile,
Out_File,
SFD_File);
exception
when others =>
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
"Exception raised in Sending.Clearsign (GPG block)");
raise;
end;
end if;
begin
if not (Mime and then (Mime_Selection = Multipart
or Mime_Selection = SMIME)) then
if Selection = ClearsignPO then
-- Rename the file appropriately.
Mv_F(Out_File, Tmpfile & ".asc");
else
Mv_F(Out_File, Tmpfile);
end if;
end if;
exception
when others =>
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
"Exception raised in Sending.Clearsign (MV block)");
raise;
end;
begin
if Mime then
case Mime_Selection is
when InlinePlain => -- Inline plain text
Echo_Out("Content-Type: text/plain", Mimefile);
New_Headers.Append(ToUBS("Content-Type: text/plain"));
when AppPGP => -- application/pgp
Echo_Out("Content-Type: application/pgp; format=text; x-action=sign",
Mimefile);
New_Headers.Append(ToUBS("Content-Type: application/pgp; format=text; x-action=sign"));
when Multipart => -- RFC2015 multipart
-- This is the _really_ nasty one.
-- At this point, we have QP_File, the quoted-printable, and TDS_File, then detached signature.
declare
Blk2 : constant String := Temp_File_Name("mp2");
MC : constant String := Temp_File_Name("mc");
begin
Externals.Mail.Mimeconstruct_Subpart(Infile => TDS_File,
Outfile => Blk2,
Content_Type => "application/pgp-signature",
Dos2UnixU => False,
Use_Encoding => False,
Attachment_Name => "signature.asc",
Disposition => Externals.Mail.Attachment);
Externals.Mail.Mimeconstruct2(Part1_Filename => QP_File,
Part2_Filename => Blk2,
Output_Filename => MC,
Content_Type => "multipart/signed; protocol=""application/pgp-signature""; micalg="""
& Externals.GPG.Micalg_From_Filename(TDS_File)
& """",
Prolog => "This is an OpenPGP/MIME signed message (RFC2440, RFC3156).");
-- Now we need to split these up.
Mail.Extract_Content_Type_From_Header(MC, Mimefile);
New_Headers.Append(Read_Fold(Mimefile));
Mail.Extract_Body(MC, Tmpfile);
end;
when MultipartEncap =>
Error("Menu should not have allowed MultipartEncap here");
when SMIME =>
if SMIME_Opaque = Yes then
declare
MM : constant String := Temp_File_Name("mm");
MM2 : constant String := Temp_File_Name("mm2");
begin
-- Write an opaque signed message.
-- We've got TDS file which is just a base64 blob.
if Actual_Send then
New_Headers.Append(ToUBS("Content-Type: application/pkcs7-mime; smime-type=signed-data; name=""smime.p7s"""));
New_Headers.Append(ToUBS("Content-Transfer-Encoding: base64"));
New_Headers.Append(ToUBS("Content-Disposition: attachment; filename=""smime.p7s"""));
New_Headers.Append(ToUBS("Content-Description: S/MIME cryptographically signed message"));
Externals.Simple.Mv_F(TDS_File, Tmpfile);
else
Echo_Out("Content-Type: application/pkcs7-mime; smime-type=signed-data; name=""smime.p7s""",
MM);
Echo_Append("Content-Transfer-Encoding: base64",
MM);
Echo_Append("Content-Disposition: attachment; filename=""smime.p7s""",
MM);
Echo_Append("Content-Description: S/MIME cryptographically signed message",
MM);
Echo_Append("", MM);
Cat_Append(TDS_File, MM);
Mail.Mimeconstruct_Mixed(UBS_Array'(1 => ToUBS(MM)),
MM2);
Mail.Extract_Content_Type_From_Header(MM2, Mimefile);
New_Headers.Append(Read_Fold(Mimefile));
Mail.Extract_Body(MM2, Tmpfile);
end if;
end;
else
-- Similar to RFC2015 multipart.
-- At this point, we have QP_File, the quoted-printable, and TDS_File, then detached signature.
declare
Blk2 : constant String := Temp_File_Name("mp2");
MC : constant String := Temp_File_Name("mc");
begin
Echo_Out("Content-Type: application/pkcs7-signature; name=""smime.p7s""",
Blk2);
Echo_Append("Content-Transfer-Encoding: base64",
Blk2);
Echo_Append("Content-Disposition: attachment; filename=""smime.p7s""",
Blk2);
Echo_Append("Content-Description: S/MIME Cryptographic Signature",
Blk2);
Echo_Append("", Blk2);
Cat_Append(TDS_File, Blk2);
Externals.Mail.Mimeconstruct2(Part1_Filename => QP_File,
Part2_Filename => Blk2,
Output_Filename => MC,
Content_Type => "multipart/signed; protocol=""application/pkcs7-signature""; micalg="""
& Externals.GPG.Micalg_From_Status(SFD_File)
& """",
Prolog => "This is an S/MIME clearsigned message.");
-- Now we need to split these up.
Mail.Extract_Content_Type_From_Header(MC, Mimefile);
New_Headers.Append(Read_Fold(Mimefile));
Mail.Extract_Body(MC, Tmpfile);
end;
end if;
end case;
end if;
exception
when others =>
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
"Exception raised in Sending.Clearsign (MIME block 2)");
raise;
end;
if not Actual_Send then
Check_Send(Tmpfile, Non_Pine, Mime, Mimefile, Hdrfile, Recipients);
end if;
exception
when others =>
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
"Exception raised in Sending.Clearsign");
raise;
end Clearsign;
topal-75/workaround.adb 0000644 0001750 0001750 00000022743 11722471751 013420 0 ustar pjb pjb -- Topal: GPG/GnuPG and Alpine/Pine integration
-- Copyright (C) 2001--2009 Phillip J. Brooke
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License version 3 as
-- published by the Free Software Foundation.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see .
with Ada.Command_Line;
with Ada.Exceptions;
with Ada.Text_IO;
with Externals.Mail;
with Externals.Simple;
with Misc; use Misc;
with Version_ID;
package body Workaround is
-- Read on stdin, write on stdout.
-- Take a single email.
-- If simple, then simply change the MIME Content-Type.
-- If not simple, rewrite it in a multipart/misc wrapper.
procedure Fix_Email is
Stdin : constant String := Temp_File_Name("wfestdin");
CT : constant String := Temp_File_Name("wfect");
Output : constant String := Temp_File_Name("wfeoutput");
Input2 : constant String := Temp_File_Name("wfeinput");
Header2 : constant String := Temp_File_Name("wfeheader");
Body2 : constant String := Temp_File_Name("wfebody");
Part1A : constant String := Temp_File_Name("wfepart1a");
Part1 : constant String := Temp_File_Name("wfepart1");
Part2 : constant String := Temp_File_Name("wfepart2");
MCO : constant String := Temp_File_Name("wfemco");
MCO2 : constant String := Temp_File_Name("wfemco2");
Mangle : Boolean := False;
Encrypted : Boolean := False;
begin
-- First, save off the standard input into a temp file.
Debug("Saving off stdin...");
Externals.Simple.Cat_Stdin_Out(Stdin);
Debug("Done save off of stdin.");
-- Get the content-type line.
Externals.Mail.Formail_Concat_Extract_InOut("Content-Type:",
Stdin,
CT);
-- Sort out the Mangle and Encrypted flags.
if Externals.Simple.Grep_I_InOut("multipart/signed",
CT,
"/dev/null") = 0 then
Mangle := True;
elsif Externals.Simple.Grep_I_InOut("multipart/encrypted",
CT,
"/dev/null") = 0 then
Mangle := True;
Encrypted := True;
end if;
-- Do we mangle?
if Mangle then
if Config.Boolean_Opts(FE_Simple) then
-- Simple mangling.
if Encrypted then
Externals.Simple.Sed_InOut("1,/^[:space:]*$/ { s!^Content-Type: *multipart/encrypted!Content-Type: application/x-topal-encrypted! ; }",
Source => Stdin,
Target => Output);
Externals.Simple.Cat(Output);
else
Externals.Simple.Sed_InOut("1,/^[:space:]*$/ { s!^Content-Type: *multipart/signed!Content-Type: application/x-topal-signed! ; }",
Source => Stdin,
Target => Output);
Externals.Simple.Cat(Output);
end if;
else
-- Rewrite mangling.
-- Drop the content-type header.
Externals.Mail.Formail_Drop_InOut(UBS_Array'(1 => ToUBS("Content-Type:"),
2 => ToUBS("Content-Transfer-Encoding:"),
3 => ToUBS("MIME-Version:")),
Source => Stdin,
Target => Input2);
-- Split the header and body apart.
Externals.Mail.Extract_Header(Input2,
Header2);
Externals.Mail.Extract_Body(Input2,
Body2);
-- Now, create a new email: all the same headers, except the
-- removed content-type. The body is a multipart/mixed,
-- comprising just the (slightly modified) original body.
-- Create a simple body.
Externals.Simple.Echo_Out("Multipart email processed by Topal "
& Version_ID.Release & ".",
Part1A);
Externals.Mail.Mimeconstruct_Subpart(Infile => Part1A,
Outfile => Part1,
Content_Type => "text/plain",
Dos2UnixU => True,
Use_Encoding => False,
Encoding => "");
-- Create this modified body, which is the original email
-- with just the content-type header.
Externals.Simple.Echo_Out_N("Content-Type: ", Part2);
Externals.Simple.Cat_Append(CT, Part2);
Externals.Simple.Echo_Append("", Part2);
Externals.Simple.Cat_Append(Body2, Part2);
Externals.Mail.Mimeconstruct_Mixed(Filenames =>
UBS_Array'(1 => ToUBS(Part1),
2 => ToUBS(Part2)),
Outfile => MCO);
Externals.Simple.Cat_Out(Header2, Output);
Externals.Simple.Echo_Append("X-Mangled-By: topal "
& Version_ID.Release,
Output);
-- We don't want the first part of the multipart mixed.
Externals.Simple.Sed_InOut("5,9 d", MCO, MCO2);
Externals.Simple.Cat_Append(MCO2, Output);
Externals.Simple.Cat(Output);
end if;
else
-- Just output the original input.
Externals.Simple.Cat(Stdin);
end if;
Ada.Command_Line.Set_Exit_Status(Ada.Command_Line.Success);
exception
when The_Exception: others =>
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
"Exception raised in Workaround.Fix_Email");
-- This is bad news. Write it all out to the emergency log.
declare
Log : constant String
:= ToStr(Topal_Directory) & "/workaround-error-log";
use Externals.Simple;
begin
Echo_Append(Integer'Image(Our_PID) &
"Exception raised in Workaround.Fix_Email",
Log);
Echo_Append(Integer'Image(Our_PID) &
"Exception raised: "
& Ada.Exceptions.Exception_Name(The_Exception),
Log);
Echo_Append(Integer'Image(Our_PID) &
Ada.Exceptions.Exception_Information(The_Exception),
Log);
end;
-- Dump put the original output. Let's hope that it all works okay.
Externals.Simple.Cat(Stdin);
raise;
end Fix_Email;
procedure Fix_Folder (Folder : in String;
Topal_Command : in String;
The_Date : in String) is
Backup_Name : constant String
:= Folder & ".topal-fix-folder-" & The_Date;
New_Name : constant String := Folder & ".topal-new";
begin
-- Backup.
Ada.Text_IO.Put_Line(" Backup file is `" & Backup_Name & "'");
Externals.Simple.Cat_Out(Folder, Backup_Name);
-- Invoke formail on this folder.
Externals.Mail.Formail_Action_InOut(Source => Folder,
Target => New_Name,
Action =>
Topal_Command & " --fix-email");
-- Do a diff.
if Externals.Simple.Diff_Brief(Folder, New_Name) then
Ada.Text_IO.Put_Line(" Made some changes!");
-- Overwrite original with mangled version.
Externals.Simple.Mv_F(New_Name, Folder);
else
Ada.Text_IO.Put_Line(" No changes made.");
Externals.Simple.Rm_File(New_Name);
end if;
-- Done.
Ada.Text_IO.Put_Line(" Finished with `" & Folder & "'");
exception
when others =>
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
"Exception raised in Workaround.Fix_Folder");
raise;
end Fix_Folder;
procedure Fix_Folders (Folders : in UBS_Array) is
Topal_Command : constant String := Ada.Command_Line.Command_Name;
The_Date : constant String := Externals.Simple.Date_String;
begin
-- Loop through each folder.
for I in Folders'Range loop
Ada.Text_IO.Put_Line("Processing folder `"
& ToStr(Folders(I)) & "'...");
Fix_Folder(ToStr(Folders(I)), Topal_Command, The_Date);
end loop;
Ada.Command_Line.Set_Exit_Status(Ada.Command_Line.Success);
exception
when others =>
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
"Exception raised in Workaround.Fix_Folders");
raise;
end Fix_Folders;
end Workaround;
topal-75/externals-ops.ads 0000644 0001750 0001750 00000001547 11722471751 014051 0 ustar pjb pjb -- Topal: GPG/GnuPG and Alpine/Pine integration
-- Copyright (C) 2001--2012 Phillip J. Brooke
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License version 3 as
-- published by the Free Software Foundation.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see .
package Externals.Ops is
function Get_MD5Sum_Of_File (Filename : String) return UBS;
function Test_Decrypt_Prerequisite return Integer;
procedure Open_TTY;
end Externals.Ops;
topal-75/alpine-2.02.patch-2 0000644 0001750 0001750 00000003675 11722471751 013567 0 ustar pjb pjb diff -cr alpine-2.02-orig/imap/src/c-client/mail.c alpine-2.02-p2/imap/src/c-client/mail.c
*** alpine-2.02-orig/imap/src/c-client/mail.c 2010-10-02 09:37:57.000000000 +0100
--- alpine-2.02-p2/imap/src/c-client/mail.c 2011-03-23 21:07:05.000000000 +0000
***************
*** 2712,2717 ****
--- 2712,2719 ----
BODY *b = NIL;
PART *pt;
unsigned long i;
+ /* Topal hack 2 */
+ mail_fetchstructure (stream,msgno,&b);
/* make sure have a body */
if (section && *section && mail_fetchstructure (stream,msgno,&b) && b)
while (*section) { /* find desired section */
diff -cr alpine-2.02-orig/pith/mailcap.c alpine-2.02-p2/pith/mailcap.c
*** alpine-2.02-orig/pith/mailcap.c 2010-10-02 09:37:57.000000000 +0100
--- alpine-2.02-p2/pith/mailcap.c 2011-03-23 21:07:05.000000000 +0000
***************
*** 582,589 ****
* typically two scans through the check_extension
* mechanism, the mailcap entry now takes precedence.
*/
! if((fname = get_filename_parameter(NULL, 0, body, &e2b.from.ext)) != NULL
! && e2b.from.ext && e2b.from.ext[0]){
if(strlen(e2b.from.ext) < sizeof(tmp_ext) - 2){
strncpy(ext = tmp_ext, e2b.from.ext - 1, sizeof(tmp_ext)); /* remember it */
tmp_ext[sizeof(tmp_ext)-1] = '\0';
--- 582,598 ----
* typically two scans through the check_extension
* mechanism, the mailcap entry now takes precedence.
*/
! /* Topal hack 2 */
! fname = get_filename_parameter(NULL, 0, body, &e2b.from.ext);
! if (fname == NULL) {
! if (body->type == TYPEMULTIPART &&
! ((body->subtype && !strucmp(body->subtype, "signed"))
! ||(body->subtype && !strucmp(body->subtype, "encrypted"))))
! fname = cpystr("openpgp.msg");
! }
!
! if(fname != NULL
! && e2b.from.ext && e2b.from.ext[0]){
if(strlen(e2b.from.ext) < sizeof(tmp_ext) - 2){
strncpy(ext = tmp_ext, e2b.from.ext - 1, sizeof(tmp_ext)); /* remember it */
tmp_ext[sizeof(tmp_ext)-1] = '\0';
topal-75/externals.ads 0000644 0001750 0001750 00000015312 11722471751 013245 0 ustar pjb pjb -- Topal: GPG/GnuPG and Alpine/Pine integration
-- Copyright (C) 2001--2012 Phillip J. Brooke
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License version 3 as
-- published by the Free Software Foundation.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see .
with Globals; use Globals;
package Externals is
-- Get our process ID.
function C_Get_Process_ID return Integer;
pragma Import (C, C_Get_Process_ID, "getpid");
-- Get the environment.
No_Such_Environment_Variable : exception;
function Get_Env (Name : String) return String;
-- Glob on a filename pattern.
function Glob (Pattern : in String) return UBS_Array;
-- Exceptions for external calls.
System_Abort_By_User : exception;
Exec_Failed : exception;
Pipe_Failed : exception;
Fork_Failed : exception;
Dup2_Failed : exception;
CClose_Failed : exception;
Waitpid_Failed : exception;
Open_Append_Failed : exception;
Open_Out_Failed : exception;
Open_In_Failed : exception;
private
-- Execute (via execvp) File with argument list Argv.
procedure Execvp (File : in String;
Argv : in UBS);
-- In this next variant, Argv had better be a UBS_Array with
-- elements 0, 1, ...
procedure Execvp (File : in String;
Argv : in UBS_Array);
-- Pipe binding.
procedure Pipe (Reading : out Integer;
Writing : out Integer);
-- Fork binding. Returns 0 to child; child_pid to parent.
function Fork return Integer;
-- Dup2 binding
procedure Dup2 (Oldfd, Newfd : in Integer);
-- Binding for C Close. We'll need this to tidy up nicely.
procedure CClose (FD : in Integer);
-- Binding for waitpid. We return the subprocess exit code.
function Waitpid (PID : Integer) return Integer;
-- Wrappers to open a file and get a file descriptor (e.g., for dup2).
function Open_Append (S : String) return Integer;
function Open_Out (S : String) return Integer;
function Open_In (S : String) return Integer;
-- ForkExec: a replacement for System.
function ForkExec (File : in String;
Argv : in UBS_Array) return Integer;
function ForkExec (File : in String;
Argv : in UBS) return Integer;
-- ForkExec: a replacement for System + append stdout to target.
function ForkExec_Append (File : in String;
Argv : in UBS_Array;
Target : in String) return Integer;
-- ForkExec: System with stdin.
function ForkExec_In (File : in String;
Argv : in UBS_Array;
Source : in String) return Integer;
-- ForkExec: a replacement for System + output stdout to target.
function ForkExec_Out (File : in String;
Argv : in UBS_Array;
Target : in String) return Integer;
function ForkExec_Out (File : in String;
Argv : in UBS;
Target : in String) return Integer;
-- ForkExec: a replacement for System + output stdout to target + input
-- from source.
function ForkExec_InOut (File : in String;
Argv : in UBS_Array;
Source : in String;
Target : in String) return Integer;
function ForkExec_InOut (File : in String;
Argv : in UBS;
Source : in String;
Target : in String) return Integer;
-- More ForkExec variants: the number indicates how many processes are
-- piped together. `In' means that a file is sent to the first process
-- on stdin; `Out' means that the last process sends stdout to a file;
-- `Append' is predictable! MergeStdErr => True is the bash-ism 2>&1.
procedure ForkExec2 (File1 : in String;
Argv1 : in UBS_Array;
Exit1 : out Integer;
File2 : in String;
Argv2 : in UBS_Array;
Exit2 : out Integer;
Merge_StdErr1 : in Boolean := False;
Report : in Boolean := False);
procedure ForkExec2 (File1 : in String;
Argv1 : in UBS;
Exit1 : out Integer;
File2 : in String;
Argv2 : in UBS;
Exit2 : out Integer;
Merge_StdErr1 : in Boolean := False;
Report : in Boolean := False);
procedure ForkExec2_Out (File1 : in String;
Argv1 : in UBS_Array;
Exit1 : out Integer;
File2 : in String;
Argv2 : in UBS_Array;
Exit2 : out Integer;
Target : in String);
procedure ForkExec2_Out (File1 : in String;
Argv1 : in UBS;
Exit1 : out Integer;
File2 : in String;
Argv2 : in UBS_Array;
Exit2 : out Integer;
Target : in String);
procedure ForkExec2_InOut (File1 : in String;
Argv1 : in UBS_Array;
Exit1 : out Integer;
File2 : in String;
Argv2 : in UBS_Array;
Exit2 : out Integer;
Source : in String;
Target : in String);
procedure ForkExec3_Out (File1 : in String;
Argv1 : in UBS;
Exit1 : out Integer;
File2 : in String;
Argv2 : in UBS_Array;
Exit2 : out Integer;
File3 : in String;
Argv3 : in UBS_Array;
Exit3 : out Integer;
Target : in String);
end Externals;
topal-75/command_line_wrapper.adb 0000644 0001750 0001750 00000012611 11722471751 015403 0 ustar pjb pjb -- Topal: GPG/GnuPG and Alpine/Pine integration
-- Copyright (C) 2001--2008 Phillip J. Brooke
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License version 3 as
-- published by the Free Software Foundation.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see .
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Text_IO;
package body Command_Line_Wrapper is
J : Integer := 1; -- A pointer into the argument list.
-- This deals with leading hyphens. As long as both have at least
-- one leading hyphen, then the leading hyphens will be treated as
-- the same.
function Compare (A, B : String) return Boolean is
-- Do A and B have hyphens?
AH, BH : Boolean := False;
-- Start points for A and B.
AS, BS : Integer;
begin
-- Get the start point, check for leading hyphen, advance past them.
AS := A'First;
AH := A(AS) = '-';
while A(AS) = '-' and AS <= A'Last loop
AS := AS + 1;
end loop;
-- Get the start point, check for leading hyphen, advance past them.
BS := B'First;
BH := B(BS) = '-';
while B(BS) = '-' and BS <= B'Last loop
BS := BS + 1;
end loop;
-- Now we can compare the remains....
return (AH = BH) and (A(AS..A'Last) = B(BS..B'Last));
end Compare;
-- Three functions for working through the command line.
-- The first only advances the pointer if the test was true.
-- Two forms, one taking a string, one taking a UBS_Array.
function Match (A : in String) return Boolean is
begin
if J <= Argument_Count then
if Compare(A, Argument(J)) then
J := J + 1;
return True;
else
return False;
end if;
else
raise Argument_Overrun;
return False; -- Never reached.
end if;
exception
when others =>
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
"Exception raised in Command_Line_Wrapper.Match (A)");
raise;
end Match;
function Match (A : in UBS_Array) return Boolean is
A_Match : Boolean := False;
begin
if J <= Argument_Count then
for I in A'First .. A'Last loop
A_Match := A_Match or Compare(ToStr(A(I)), Argument(J));
end loop;
if A_Match then
J := J + 1;
return True;
else
return False;
end if;
else
raise Argument_Overrun;
return False; -- Never reached.
end if;
exception
when others =>
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
"Exception raised in Command_Line_Wrapper.Match (B)");
raise;
end Match;
-- This second function always advances.
function Eat return UBS is
R : UBS;
begin
if J <= Argument_Count then
R := ToUBS(Argument(J));
J := J + 1;
return R;
else
raise Argument_Overrun;
return ToUBS(""); -- Never reached.
end if;
exception
when others =>
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
"Exception raised in Command_Line_Wrapper.Eat");
raise;
end Eat;
-- This last function returns true if there is still something to read.
function More (Needed : Positive := 1) return Boolean is
begin
return J + Needed - 1 <= Argument_Count;
exception
when others =>
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
"Exception raised in Command_Line_Wrapper.More");
raise;
end More;
-- Given J, the index of the first command line argument to drop into an
-- array, drop J, J+1, etc. into an array and return it.
function Eat_Remaining_Arguments return UBS_Array_Pointer is
-- The array we return starts at 1.
-- Command line index: J, J+1, ..., Argument_Count
-- Returned array index: 1, 2, ..., Argument_Count - J + 1
-- If I is the index into the return array index, then
-- I + J - 1 is the index into the command line index.
A : UBS_Array_Pointer;
begin
A := new UBS_Array(1..Argument_Count - J + 1);
for I in 1 .. Argument_Count - J + 1 loop
A(I) := ToUBS(Argument(I + J - 1));
end loop;
J := Argument_Count + 1;
return A;
exception
when others =>
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
"Exception raised in Command_Line_Wrapper.Eat_Remaining_Arguments");
raise;
end Eat_Remaining_Arguments;
-- Display the current argument.
function Current return String is
begin
if J <= Argument_Count then
return Argument(J);
else
raise Argument_Overrun;
return ""; -- Never reached.
end if;
exception
when others =>
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
"Exception raised in Command_Line_Wrapper.Current");
raise;
end Current;
end Command_Line_Wrapper;
topal-75/remote_mode.adb 0000644 0001750 0001750 00000046500 11722471751 013521 0 ustar pjb pjb -- Topal: GPG/GnuPG and Alpine/Pine integration
-- Copyright (C) 2001--2009 Phillip J. Brooke
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License version 3 as
-- published by the Free Software Foundation.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see .
with Ada.Command_Line;
with Ada.Text_IO;
with Externals.Simple;
with Invocation;
with Menus;
with Misc;
with Readline;
with Sending;
package body Remote_Mode is
function Merge_Recipients (Recipients : UBS_Array) return UBS is
Recips : UBS := NullUBS;
begin
for I in Recipients'Range loop
declare
use type UBS;
begin
Recips := Recips & Recipients(I);
if I /= Recipients'Last then
Recips := Recips & ' ';
end if;
end;
end loop;
return Recips;
exception
when others =>
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
"Exception raised in Remote_Mode.Merge_Recipients");
raise;
end Merge_Recipients;
procedure Get_Host_And_Topal (Host : in out UBS;
Topal_Command : in out UBS) is
begin
Host := ToUBS(Readline.Get_String("Which host? "));
Topal_Command := ToUBS(Readline.Get_String("Which topal (on remote host)? "));
exception
when others =>
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
"Exception raised in Remote_Mode.Get_Host_And_Topal");
raise;
end Get_Host_And_Topal;
procedure Trigger is
Server_Trigger : constant String := ToStr(Topal_Directory)
& "/server-trigger";
Reply_Trigger : constant String := ToStr(Topal_Directory)
& "/reply-trigger";
use Externals.Simple;
begin
Echo_Out("", Server_Trigger);
Ada.Text_IO.Put_Line("Waiting for Topal server...");
Reply_Trigger_Loop:
loop
exit Reply_Trigger_Loop when Test_F(Reply_Trigger);
delay 0.5;
end loop Reply_Trigger_Loop;
delay 0.1;
Rm_File(Reply_Trigger);
Ada.Text_IO.Put_Line("Topal server finished...");
exception
when others =>
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
"Exception raised in Remote_Mode.Trigger");
raise;
end Trigger;
procedure Send(Tmpfile : in String;
Mime : in Boolean;
Mimefile : in String;
Recipients : in UBS_Array) is
Host : UBS;
Topal_Command : UBS;
-- What names...?
-- FIXME: these should be variable....
R_Tmpfile : constant String := ".topal/server/tmpfile";
R_Resultfile : constant String := ".topal/server/resultfile";
R_Mimefile : constant String := ".topal/server/mimefile";
R_RVfile : constant String := ".topal/server/rvfile";
L_RVfile : constant String := Misc.Temp_File_Name("lrv");
L_Resultfile : constant String := Misc.Temp_File_Name("lrf");
RV : Integer;
Dummy : Integer;
RF : UBS;
Continue : Boolean := True;
use Ada.Text_IO;
use Externals.Simple;
pragma Unreferenced(Dummy);
begin
Get_Host_And_Topal(Host, Topal_Command);
if ToStr(Host)'Length > 0 and ToStr(Topal_Command)'Length > 0 then
-- Copy Tmpfile to host.
Put_Line("Copying " & Tmpfile & " to "
& ToStr(Host) & ":" & R_Tmpfile);
Dummy := System(ToStr(Config.Binary(Scp))
& " " & Tmpfile
& " " & ToStr(Host) & ":" & R_Tmpfile);
if Config.Boolean_Opts(Read_From) then
RF := ToUBS(" --read-from ");
else
RF := NullUBS;
end if;
-- Run ssh with remotesend(mime).
if Mime then
Put_Line("Attempting ssh " & ToStr(Host) & " "
& ToStr(Topal_Command) & " " & ToStr(RF) & " -remotesendmime "
& R_Tmpfile & " "
& R_Resultfile & " "
& R_RVfile & " "
& R_Mimefile & " "
& ToStr(Merge_Recipients(Recipients)));
Dummy := System(ToStr(Config.Binary(Ssh))
& " "
& ToStr(Host) & " "
& ToStr(Topal_Command) & " " & ToStr(RF) & " -remotesendmime "
& R_Tmpfile & " "
& R_Resultfile & " "
& R_RVfile & " "
& R_Mimefile & " "
& ToStr(Merge_Recipients(Recipients)));
else
Put_Line("Attempting ssh " & ToStr(Host) & " "
& ToStr(Topal_Command) & " " & ToStr(RF) & " -remotesend "
& R_Tmpfile & " "
& R_Resultfile & " "
& R_RVfile & " "
& ToStr(Merge_Recipients(Recipients)));
Dummy := System(ToStr(Config.Binary(Ssh))
& " "
& ToStr(Host) & " "
& ToStr(Topal_Command) & " " & ToStr(RF) & " -remotesend "
& R_Tmpfile & " "
& R_Resultfile & " "
& R_RVfile & " "
& ToStr(Merge_Recipients(Recipients)));
end if;
Put_Line("Copying " & ToStr(Host) & ":" & R_RVfile & " to "
& L_RVfile);
Dummy := System(ToStr(Config.Binary(Scp))
& " " & ToStr(Host) & ":" & R_RVfile
& " " & L_RVfile);
RV := Misc.String_To_Integer(Misc.Read_Fold(L_RVfile));
Put_Line("Read remote RV as " & Integer'Image(RV));
if RV = 0 then
Put_Line("Remote topal returned successfully.");
Ada.Command_Line.Set_Exit_Status(Ada.Command_Line.Success);
-- Copy Tmpfile, resultfile, perhaps mimefile back.
Put_Line("Copying " & ToStr(Host) & ":" & R_Tmpfile & " to "
& Tmpfile);
Dummy := System(ToStr(Config.Binary(Scp))
& " " & ToStr(Host) & ":" & R_Tmpfile
& " " & Tmpfile);
if Mime then
Put_Line("Copying " & ToStr(Host) & ":" & R_Mimefile & " to "
& Mimefile);
Dummy := System(ToStr(Config.Binary(Scp))
& " " & ToStr(Host) & ":" & R_Mimefile
& " " & Mimefile);
end if;
else
Put_Line("Remote topal failed.");
Ada.Command_Line.Set_Exit_Status(Ada.Command_Line.Failure);
Continue := False;
end if;
Put_Line("Copying " & ToStr(Host) & ":" & R_Resultfile & " to "
& L_Resultfile);
Dummy := System(ToStr(Config.Binary(Scp))
& " " & ToStr(Host) & ":" & R_Resultfile
& " " & L_Resultfile);
-- Append L_Resultfile...
Put(Result_File, ToStr(Misc.Read_Fold(L_Resultfile)));
-- Clean up.
Put_Line("Deleting remote copies of server files...");
Dummy := System(ToStr(Config.Binary(Ssh))
& " "
& ToStr(Host) & " rm "
& R_Tmpfile & " "
& R_Resultfile & " "
& R_Mimefile & " "
& R_RVfile);
-- For some reason, we're getting failures. Perhaps
-- from an scp call? Set explicit success,
-- although check_send can fail out later.
if Continue then
Sending.Check_Send(Tmpfile, False, Mime, Mimefile, "", Recipients);
else
Ada.Command_Line.Set_Exit_Status(Ada.Command_Line.Failure);
end if;
else
Ada.Command_Line.Set_Exit_Status(Ada.Command_Line.Failure);
end if;
exception
when others =>
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
"Exception raised in Remote_Mode.Send");
raise;
end Send;
procedure Remote_Send(Tmpfile : in String;
Resultfile : in String;
Mime : in Boolean;
Mimefile : in String;
Recipients : in UBS_Array) is
Command_Pipe : constant String := ToStr(Topal_Directory)
& "/server-commands";
RV_File : constant String := ToStr(Invocation.RVfile);
RF : UBS;
RV : Integer;
use Externals.Simple;
begin
-- This procedure is called by ssh.
if Config.Boolean_Opts(Read_From) then
RF := ToUBS("+");
else
RF := NullUBS;
end if;
if Mime then
Echo_Out("remotesendmime" & ToStr(RF) & " " & RV_File & " "
& Tmpfile & " "
& Resultfile & " "
& Mimefile & " "
& ToStr(Merge_Recipients(Recipients)),
Command_Pipe);
else
Echo_Out("remotesend" & ToStr(RF) & " " & RV_File & " "
& Tmpfile & " "
& Resultfile & " "
& ToStr(Merge_Recipients(Recipients)),
Command_Pipe);
end if;
Trigger;
-- Collect the return value.
declare
use Misc;
begin
if Test_F(RV_File) then
RV := String_To_Integer(Read_Fold(RV_File));
else
RV := 1;
end if;
Ada.Text_IO.Put_Line("Read remote RV as " & Integer'Image(RV));
if RV = 0 then
Ada.Text_IO.Put_Line("Remote send setting success");
Ada.Command_Line.Set_Exit_Status(Ada.Command_Line.Success);
else
Ada.Text_IO.Put_Line("Remote send setting failure");
Ada.Command_Line.Set_Exit_Status(Ada.Command_Line.Failure);
end if;
end;
exception
when others =>
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
"Exception raised in Remote_Mode.Remote_Send");
raise;
end Remote_Send;
procedure Decrypt(Infile : in String;
MIME : in Boolean;
Content_Type : in String := "") is
Host : UBS;
Topal_Command : UBS;
-- What names...?
-- FIXME: these should be variable....
R_Infile : constant String := ".topal/server/infile";
Dummy : Integer;
use Ada.Text_IO;
use Externals.Simple;
pragma Unreferenced(Dummy);
begin
Get_Host_And_Topal(Host, Topal_Command);
if ToStr(Host)'Length > 0 and ToStr(Topal_Command)'Length > 0 then
-- Copy Infile to host.
Put_Line("Copying " & Infile & " to "
& ToStr(Host) & ":" & R_Infile);
Dummy := System(ToStr(Config.Binary(Scp))
& " " & Infile
& " " & ToStr(Host) & ":" & R_Infile);
-- Run ssh with remotesend(mime).
if Mime then
Put_Line("Attempting ssh " & ToStr(Host) & " "
& ToStr(Topal_Command) & " -remotemimedecrypt "
& R_Infile);
Dummy := System(ToStr(Config.Binary(Ssh))
& " "
& ToStr(Host) & " "
& ToStr(Topal_Command) & " -remotemimedecrypt "
& R_Infile
& " "
& Content_Type);
else
Put_Line("Attempting ssh " & ToStr(Host) & " "
& ToStr(Topal_Command) & " -remotedecrypt "
& R_Infile);
Dummy := System(ToStr(Config.Binary(Ssh))
& " "
& ToStr(Host) & " "
& ToStr(Topal_Command) & " -remotedecrypt "
& R_Infile);
end if;
-- Clean up.
Put_Line("Deleting remote copies of server files...");
Dummy := System(ToStr(Config.Binary(Ssh))
& " "
& ToStr(Host) & " rm "
& R_Infile);
end if;
exception
when others =>
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
"Exception raised in Remote_Mode.Decrypt");
raise;
end Decrypt;
procedure Remote_Decrypt(Infile : in String;
MIME : in Boolean;
Content_Type : in String := "") is
Command_Pipe : constant String := ToStr(Topal_Directory)
& "/server-commands";
use Externals.Simple;
begin
-- This procedure is called by ssh.
if Mime then
Echo_Out("remotemimedecrypt " & Infile & " " & Content_Type,
Command_Pipe);
else
Echo_Out("remotedecrypt " & Infile,
Command_Pipe);
end if;
Trigger;
Ada.Text_IO.Put_Line("Remote decrypt finished (setting success)");
Ada.Command_Line.Set_Exit_Status(Ada.Command_Line.Success);
exception
when others =>
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
"Exception raised in Remote_Mode.Remote_Decrypt");
raise;
end Remote_Decrypt;
procedure Server is
Topal_Command : constant String := Ada.Command_Line.Command_Name;
Server_Dir : constant String := ToStr(Topal_Directory) & "/server";
Command_Pipe : constant String := ToStr(Topal_Directory)
& "/server-commands";
Server_Trigger : constant String := ToStr(Topal_Directory)
& "/server-trigger";
Reply_Trigger : constant String := ToStr(Topal_Directory)
& "/reply-trigger";
use Ada.Text_IO;
use Externals.Simple;
use Menus;
F : File_Type;
L : UBS;
begin
Put_Line("Running in server mode.");
Put_Line("Will re-dispatch calls to "
& Topal_Command);
-- Make sure that the server directory still exists.
Mkdir_P(Server_Dir);
-- We'll deal with SIGINTs.
Misc.Set_Sigint_Handler;
-- Loop, reading the command-line.
Server_Main_Loop:
loop
-- Triggered by presence of server-trigger file.
Server_Trigger_Loop:
loop
exit Server_Trigger_Loop when Test_F(Server_Trigger);
exit Server_Main_Loop when Misc.Signal_Handlers.Sigint_Pending;
delay 0.5;
end loop Server_Trigger_Loop;
delay 0.1;
Rm_File(Server_Trigger);
-- Open the file to read.
Open(File => F,
Mode => In_File,
Name => Command_Pipe);
-- Is this a blocking read? Let's hope so.
L := Misc.Unbounded_Get_Line(F);
declare
A : constant UBS_Array := Misc.Split_Arguments(L);
Refuse : Boolean := False;
Continue : Boolean := True;
RemoteRV : Integer;
CL : UBS := NullUBS;
Offset : Natural;
RemoteD : Boolean := False;
Tmpfile : UBS;
begin
-- Show the user what we propose to do:
New_Line(3);
Put_Line("Request received: to run `"
& Topal_Command
& "' with arguments `" & ToStr(L) & "'");
-- Six choices:
-- remotesend _RETURNVALUE_ _TMPFILE_ _RESULTFILE_ _RECIPIENTS_
-- remotesendmime _RETURNVALUE_ _TMPFILE_ _RESULTFILE_ _MIMETYPE_ _RECIPIENTS_
-- Then those same two, suffixed `+', e.g., remotesend+. + implies read-from (i.e., config.all_headers, config.read_from)
-- remotedecrypt _INFILE_
-- remotedecryptmime _INFILE_
if A'Length >= 5
and then ToStr(A(A'First)) = "remotesend" then
CL := ToUBS(Topal_Command & " -send");
Offset := 2;
elsif A'Length >= 5
and then ToStr(A(A'First)) = "remotesend+" then
CL := ToUBS(Topal_Command & " --read-from -send");
Offset := 2;
elsif A'Length >= 6
and then ToStr(A(A'First)) = "remotesendmime" then
CL := ToUBS(Topal_Command & " -sendmime");
Offset := 2;
elsif A'Length >= 6
and then ToStr(A(A'First)) = "remotesendmime+" then
CL := ToUBS(Topal_Command & " --read-from -sendmime");
Offset := 2;
elsif A'Length = 2
and then ToStr(A(A'First)) = "remotedecrypt" then
CL := ToUBS(Topal_Command & " -display");
Offset := 1;
RemoteD := True;
elsif A'Length = 3
and then ToStr(A(A'First)) = "remotemimedecrypt" then
CL := ToUBS(Topal_Command & " -mime");
Offset := 1;
else
Put_Line("Bogus!");
Continue := False;
end if;
if Continue then
for I in A'First+Offset..A'Last loop
declare
use type UBS;
begin
CL := CL & ' ';
CL := CL & A(I);
end;
end loop;
end if;
if RemoteD then
-- Generate a temporary file. This is a stand-in for
-- the result file.
Tmpfile := ToUBS(Misc.Temp_File_Name("srdt"));
declare
use type UBS;
begin
CL := CL & ' ';
CL := CL & Tmpfile;
end;
end if;
Put_Line("Will run `" & ToStr(CL) & "'");
if Continue and then YN_Menu("Proceed? ") = Yes then
begin
RemoteRV := System(CL);
Put_Line("RemoteRV=" & Integer'Image(RemoteRV));
if RemoteD then
-- Show the temporary file via the pager.
Pager(ToStr(A(A'First+1)));
end if;
end;
else
Refuse := True;
end if;
if Refuse then
Put_Line("Refused request; you may have to manually interrupt client.");
else
-- 2nd argument had better be the return value....
Echo_Out(Misc.Trim_Leading_Spaces(Integer'Image(RemoteRV)),
ToStr(A(A'First+1)));
end if;
end;
Close(F);
Echo_Out("", Reply_Trigger);
Put_Line("Server finished, client can continue.");
New_Line(2);
end loop Server_Main_Loop;
-- Never ends except by sigint.
exception
when others =>
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
"Exception raised in Remote_Mode.Server");
raise;
end Server;
end Remote_Mode;
topal-75/cygwin.patch 0000644 0001750 0001750 00000007612 11722471751 013074 0 ustar pjb pjb diff -cr topal-63.orig/Makefile topal-63.cyg/Makefile
*** topal-63.orig/Makefile Sun Aug 31 16:28:25 2008
--- topal-63.cyg/Makefile Wed Sep 3 08:06:11 2008
***************
*** 83,89 ****
./mkhelp
README.txt: README.html
! lynx -dont_wrap_pre -dump README.html > README.txt
install: all
install -d $(INSTALLPATHBIN) $(INSTALLPATHDOC) $(INSTALLPATHMAN)/man1 $(INSTALLPATHPATCHES)
--- 83,89 ----
./mkhelp
README.txt: README.html
! -lynx -dont_wrap_pre -dump README.html > README.txt
install: all
install -d $(INSTALLPATHBIN) $(INSTALLPATHDOC) $(INSTALLPATHMAN)/man1 $(INSTALLPATHPATCHES)
***************
*** 102,107 ****
--- 102,108 ----
distclean realclean: clean
-rm topal topal.gz topal.gz.asc topal-ps topal-ps.gz topal-ps.gz.asc README.txt topal-package*.{tgz,tgz.sig,tgz.asc} *~
+ -rm topal.exe
-rm -rf www www.bak
make -C MIME-tool realclean
diff -cr topal-63.orig/misc.adb topal-63.cyg/misc.adb
*** topal-63.orig/misc.adb Sun Aug 31 16:28:25 2008
--- topal-63.cyg/misc.adb Wed Sep 3 07:59:31 2008
***************
*** 16,23 ****
with Ada.Characters.Latin_1;
with Ada.Command_Line;
with Ada.Integer_Text_IO;
- with Ada.Interrupts;
- with Ada.Interrupts.Names;
with Ada.IO_Exceptions;
with Ada.Strings;
with Ada.Strings.Fixed;
--- 16,21 ----
***************
*** 496,523 ****
raise;
end Hex_Decode;
- -- Handle signals.
- Default_Sigint_Handler : Ada.Interrupts.Parameterless_Handler;
- protected body Signal_Handlers is
-
- procedure Sigint_Handler is
- begin
- Ada.Text_IO.Put_Line("User interrupt!");
- Sigint_Pending_Flag := True;
- raise User_Interrupt;
- end Sigint_Handler;
-
- function Sigint_Pending return Boolean is
- begin
- return Sigint_Pending_Flag;
- end Sigint_Pending;
-
- end Signal_Handlers;
-
procedure Set_Sigint_Handler is
begin
! Ada.Interrupts.Attach_Handler(Signal_Handlers.Sigint_Handler'Access,
! Ada.Interrupts.Names.SIGINT);
exception
when others =>
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
--- 494,502 ----
raise;
end Hex_Decode;
procedure Set_Sigint_Handler is
begin
! null;
exception
when others =>
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
***************
*** 525,530 ****
raise;
end Set_Sigint_Handler;
- begin
- Default_Sigint_Handler := Ada.Interrupts.Current_Handler(Ada.Interrupts.Names.SIGINT);
end Misc;
--- 504,507 ----
diff -cr topal-63.orig/misc.ads topal-63.cyg/misc.ads
*** topal-63.orig/misc.ads Sun Aug 31 16:28:25 2008
--- topal-63.cyg/misc.ads Wed Sep 3 07:59:42 2008
***************
*** 96,113 ****
-- Hexadecimal decoder.
function Hex_Decode (S : in String) return Natural;
- -- We turn SIGINT into an exception so that we can clean up
- -- temporary files.
- -- Handle interrupts, SIGINT, etc.
- pragma Unreserve_All_Interrupts;
- -- because we want to be able to handle ctrl-C.
- protected Signal_Handlers is
- procedure Sigint_Handler;
- function Sigint_Pending return Boolean;
- pragma Interrupt_Handler(Sigint_Handler);
- private
- Sigint_Pending_Flag : Boolean := False;
- end Signal_Handlers;
-- And a procedure for taking over sigint.
procedure Set_Sigint_Handler;
--- 96,101 ----
diff -cr topal-63.orig/remote_mode.adb topal-63.cyg/remote_mode.adb
*** topal-63.orig/remote_mode.adb Sun Aug 31 16:28:25 2008
--- topal-63.cyg/remote_mode.adb Wed Sep 3 08:02:32 2008
***************
*** 382,388 ****
Server_Trigger_Loop:
loop
exit Server_Trigger_Loop when Test_F(Server_Trigger);
- exit Server_Main_Loop when Misc.Signal_Handlers.Sigint_Pending;
delay 0.5;
end loop Server_Trigger_Loop;
delay 0.1;
--- 382,387 ----
topal-75/externals-ops.adb 0000644 0001750 0001750 00000005513 11722471751 014025 0 ustar pjb pjb -- Topal: GPG/GnuPG and Alpine/Pine integration
-- Copyright (C) 2001--2012 Phillip J. Brooke
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License version 3 as
-- published by the Free Software Foundation.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see .
with Ada.Text_IO;
with Misc; use Misc;
package body Externals.Ops is
function Get_MD5Sum_Of_File (Filename : String) return UBS is
CH : Ada.Text_IO.File_Type;
MD5 : UBS;
Cache_File : constant String := Temp_File_Name("cachename");
E1, E2 : Integer;
begin
ForkExec2_Out(Value_Nonempty(Config.Binary(Md5sum)),
UBS_Array'(0 => ToUBS("md5sum"),
1 => ToUBS(Filename)),
E1,
Value_Nonempty(Config.Binary(Sed)),
UBS_Array'(0 => ToUBS("sed"),
1 => ToUBS("s/ .*//")),
E2,
Target => Cache_File);
if E1 /= 0 then
Error("md5sum failed! (ff8)");
elsif E2 /= 0 then
Error("sed failed! (ff9)");
end if;
Ada.Text_IO.Open(File => CH,
Mode => Ada.Text_IO.In_File,
Name => Cache_File);
MD5 := Unbounded_Get_Line(CH);
Ada.Text_IO.Close(CH);
return MD5;
exception
when others =>
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
"Exception raised in Externals.Ops.Get_MD5Sum_Of_File");
raise;
end Get_MD5Sum_Of_File;
function Test_Decrypt_Prerequisite return Integer is
begin
return ForkExec(ToStr(Config.UBS_Opts(Decrypt_Prereq)),
Config.UBS_Opts(Decrypt_Prereq));
exception
when others =>
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
"Exception raised in Externals.Ops.Test_Decrypt_Prequisite");
raise;
end Test_Decrypt_Prerequisite;
procedure Open_TTY is
TTY_FD : Integer;
begin
CClose(0);
CClose(1);
CClose(2);
TTY_FD := Open_In("/dev/tty");
Dup2(TTY_FD, 0);
TTY_FD := Open_Out("/dev/tty");
Dup2(TTY_FD, 1);
Dup2(TTY_FD, 2);
exception
when others =>
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
"Exception raised in Externals.Ops.Open_TTY");
raise;
end Open_TTY;
end Externals.Ops;
topal-75/mkversionidtex 0000755 0001750 0001750 00000001365 11722471751 013553 0 ustar pjb pjb #!/bin/sh
# Topal: GPG/GnuPG and Alpine/Pine integration
# Copyright (C) 2001--2012 Phillip J. Brooke
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
cat > versionid.tex <