Re: [exim] Replacing attachments with URLs

Pàgina inicial
Delete this message
Reply to this message
Autor: Michelle Konzack
Data:  
A: exim-users
Assumpte: Re: [exim] Replacing attachments with URLs
Hello David,

Replacing some Attachment with Links is not realy trivial, but I have
written a small script which help me to analyze the message which is
attached.

Call it with: td_get_mimeparts <complete_message_file>

You will encounter several problems:

1) Message is a mimepart/related
2) has a mimepart/alternative
3) some attachments...

The message striped will look something like (check it with my script):

----[ command 'td_get_mimeparts test.msg' ]-----------------------------
BOUNDARY  ----=_NextPart_000_0375_01C8B1F9.AC33FB40
PARTS     3


#### The Full Message #########################################################

Content-Type: multipart/related; type="multipart/alternative"; boundary="----=_NextPart_000_0375_01C8B1F9.AC33FB40"
Content-Length: 1224904

1------=_NextPart_000_0375_01C8B1F9.AC33FB40
Content-Type: multipart/alternative; boundary="----=_NextPart_001_0376_01C8B1F9.AC33FB40"

------=_NextPart_001_0376_01C8B1F9.AC33FB40
Content-Type: text/plain; charset="big5"
Content-Transfer-Encoding: quoted-printable

------=_NextPart_001_0376_01C8B1F9.AC33FB40
Content-Type: text/html; charset="big5"
Content-Transfer-Encoding: quoted-printable

------=_NextPart_001_0376_01C8B1F9.AC33FB40--

2------=_NextPart_000_0375_01C8B1F9.AC33FB40
Content-Type: image/jpeg; name="LOGO.jpg"
Content-Transfer-Encoding: base64
Content-ID: <BF1DBF8B43434455B7AC207565B4B854@???>

3------=_NextPart_000_0375_01C8B1F9.AC33FB40
Content-Type: image/jpeg; name="=?big5?B?NqTrLUVETS1IZGRDYXNlLmpwZw==?="
Content-Transfer-Encoding: base64
Content-ID: <031571FFA74B4183821B562F6474B668@???>

4------=_NextPart_000_0375_01C8B1F9.AC33FB40--

#### Pull out multipart/alternative ##########################################

Content-Type: multipart/alternative; boundary="----=_NextPart_001_0376_01C8B1F9.AC33FB40"

1------=_NextPart_001_0376_01C8B1F9.AC33FB40
Content-Type: text/plain; charset="big5"
Content-Transfer-Encoding: quoted-printable

2------=_NextPart_001_0376_01C8B1F9.AC33FB40
Content-Type: text/html; charset="big5"
Content-Transfer-Encoding: quoted-printable

3------=_NextPart_001_0376_01C8B1F9.AC33FB40--

########################################################################

------------------------------------------------------------------------

The problems continue: WHERE do you want to place the strings:

----8<----------------------------------------------
The message has following MEGA-Attachments:
    http://www.example.com/user/12345678790.jpg
    http://www.example.com/user/abcdefghijk.jpg
----8<----------------------------------------------


You have the

----8<------------------------------------------------------------------
1------=_NextPart_000_0375_01C8B1F9.AC33FB40
Content-Type: multipart/alternative; boundary="----=_NextPart_001_0376_01C8B1F9.AC33FB40"

------=_NextPart_001_0376_01C8B1F9.AC33FB40
Content-Type: text/plain; charset="big5"
Content-Transfer-Encoding: quoted-printable

------=_NextPart_001_0376_01C8B1F9.AC33FB40
Content-Type: text/html; charset="big5"
Content-Transfer-Encoding: quoted-printable
----8<------------------------------------------------------------------

If it is in the "text/plain" it is easy. You can sed it into but if it
is in the "text/html" you need to find the END of the message by
searching for the CLOSING </BODY> gad and place the message above it
like:

    TEXT="<HR><B>The message has following MEGA-Attachments:</B><P>
    <A href="http://www.example.com/user/12345678790.jpg">http://www.example.com/user/12345678790.jpg</A><P>
    <A href="http://www.example.com/user/abcdefghijk.jpg">http://www.example.com/user/abcdefghijk.jpg</A><P>"


    sed "s|</[Bb][Oo][Dd][Yy]>|${TEXT}</BODY>|"


and as you can see in the script I have numbered the mimeparts, which
make it easier to cut it out the parts of the message and then pipe it
through mimedecode (with the mime headers) into the desired file.

Thanks, Greetings and nice Day
    Michelle Konzack
    Systemadministrator
    24V Electronic Engineer
    Tamay Dogan Network
    Debian GNU/Linux Consultant



-- 
Linux-User #280138 with the Linux Counter, http://counter.li.org/
##################### Debian GNU/Linux Consultant #####################
Michelle Konzack   Apt. 917                  ICQ #328449886
+49/177/9351947    50, rue de Soultz         MSN LinuxMichi
+33/6/61925193     67100 Strasbourg/France   IRC #Debian (irc.icq.com)

#!/bin/bash

reset

INFILE=$1

BOUNDARY1=$(sed '/^$/q' ${INFILE} |grep --ignore-case 'boundary=' |sed -e 's|.*boundary=||' |tr -d '"')
PARTS=$(egrep --regexp="^--${BOUNDARY1}" ${INFILE} |grep -v --regexp="^--.*--$" |wc --lines)

echo "BOUNDARY  ${BOUNDARY1}"
echo "PARTS     ${PARTS}"


echo
echo "#### The Full Message #########################################################"
echo

MESSAGE1=`sed ':a;/;$/N;s/\n/ /;ta' ${INFILE} |
           egrep "^(Content-|--|$)" |
           tr '\t' ' ' |
           tr -s ' ' |
           sed '/./,/^$/!d' |
           awk "/^--${BOUNDARY1}/{printf ++a};1"`
echo "${MESSAGE1}"


for PB in $(seq 1 ${PARTS}) ; do
  PE=$((PB+1))
  MESSAGE2=`echo "${MESSAGE1}" |
            sed -n "/^${PB}--${BOUNDARY1}/,/^${PE}--${BOUNDARY1}/p" `
  if [ -n "$(echo "${MESSAGE2}" |grep --ignore-case 'boundary=' 2>/dev/null)" ] &&
     [ -n "$(echo "${MESSAGE2}" |grep --ignore-case 'multipart/alternative' 2>/dev/null)" ] ; then
    BOUNDARY2=`echo "${MESSAGE3}" |
               grep --invert-match --regexp="${BOUNDARY1}"|
               grep "boundary=" |
               sed -e 's|.*boundary=||' |
               tr -d '"'`
    MESSAGE3=`echo "${MESSAGE2}"  |
             egrep "^(Content-|--|$)" |
             sed '/./,/^$/!d' |
             awk "/^--${BOUNDARY2}/{printf ++a};1"`
    echo
    echo "#### Pull out multipart/alternative  ##########################################"
    echo
    echo "${MESSAGE3}"
  fi
done


echo
echo "########################################################################"
echo