OT - Renaming Attachments

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

OT - Renaming Attachments

Jeremy Bowen-5
This one is a bit off-topic however I'm hoping that someone has come
across something similar and can point me in the right direction.

I would like to try to intercept certain outgoing emails which have an
attachment matching a particular set of criteria and then, on-the-fly,
rename the attachment (or extract, rename and re-attach it). Maybe
via a content filter - amavis or procmail ???

These emails have a MIME "Content-Type: application/pdf;" header but
the filename does not have a .pdf extension, which confuses the bulk of
Windows email clients.

I vaguely remember doing something similar with tnef/winmail.dat files
over a decade ago but I can't find any details now (and I may be
completely off base). Thanks in advance.

Reply | Threaded
Open this post in threaded view
|

Re: OT - Renaming Attachments

Noel Jones-2
On 2/2/2015 2:28 PM, Jeremy Bowen wrote:

> This one is a bit off-topic however I'm hoping that someone has come
> across something similar and can point me in the right direction.
>
> I would like to try to intercept certain outgoing emails which have an
> attachment matching a particular set of criteria and then, on-the-fly,
> rename the attachment (or extract, rename and re-attach it). Maybe
> via a content filter - amavis or procmail ???
>
> These emails have a MIME "Content-Type: application/pdf;" header but
> the filename does not have a .pdf extension, which confuses the bulk of
> Windows email clients.
>
> I vaguely remember doing something similar with tnef/winmail.dat files
> over a decade ago but I can't find any details now (and I may be
> completely off base). Thanks in advance.
>

The 'altermime' filter is often recommended for this.  Amavisd-new
has some hooks for using altermime built in.  Be aware that
altermime does not seem to be an active project, the last program
update was several years ago.

Alternately, there are numerous perl MIME modules available that can
be cobbled together if you can do some programming.



  -- Noel Jones


Reply | Threaded
Open this post in threaded view
|

Re: OT - Renaming Attachments

Jeremy Bowen-5
On Mon, 02 Feb 2015 14:42:47 -0600
Noel Jones <[hidden email]> wrote:

> On 2/2/2015 2:28 PM, Jeremy Bowen wrote:
> > I would like to try to intercept certain outgoing emails which have
> > an attachment matching a particular set of criteria and then,
> > on-the-fly, rename the attachment (or extract, rename and re-attach
> > it). Maybe via a content filter - amavis or procmail ???

> The 'altermime' filter is often recommended for this.  Amavisd-new
> has some hooks for using altermime built in.  Be aware that
> altermime does not seem to be an active project, the last program
> update was several years ago.
>
> Alternately, there are numerous perl MIME modules available that can
> be cobbled together if you can do some programming.

Thanks for that. I've just tried altermime but it appears that it only
operates on the message header and not the MIME headers in the body.
I played around modifying altermime to scan the body too but I think I'm
getting into the "thar be dragons" territory with that approach.

I think I can do what I need to accomplish more accurately & efficiently
with sed and procmail. I'm just not quite sure how I would go about
configuring postfix to make this operate on outgoing mail. Any advice ?
Reply | Threaded
Open this post in threaded view
|

Re: OT - Renaming Attachments

Jeremy Bowen-5
On Tue, 3 Feb 2015 11:21:17 +1300
Jeremy Bowen <[hidden email]> wrote:
> I think I can do what I need to accomplish more accurately &
> efficiently with sed and procmail. I'm just not quite sure how I
> would go about configuring postfix to make this operate on outgoing
> mail. Any advice ?

OK, I've started with the FILTER_README and, using the "Simple
Content Filter" example, have come up with a simple shell script which
modifies the message the way I need it.
I've tested this with:
% /usr/local/bin/myscript -f sender -- recipient... <message-file

From here it looks like I need to initially  add the following lines to
master.cf:
filter    unix  -       n       n       -       10      pipe
    flags=Rq user=filter null_sender=
    argv=/usr/local/bin/myscript -f ${sender} -- ${recipient}

This filter should pick up email from the "submission" service. What
do I need to do from here ? (I already have a
"-o content_filter=dksign:[127.0.0.1]:10027"
in the submission definition handling signing of outgoing email. )

Also, it appears that this approach may not be ideal as I don't think I
can restrict things to only apply this on mail with a certain Subject:
header. Am I on the right track here ?

Thanks again.
Reply | Threaded
Open this post in threaded view
|

Filtering Outgoing mail - Was: [OT - Renaming Attachments]

Jeremy Bowen-5
On Tue, 3 Feb 2015 17:06:14 +1300
Jeremy Bowen <[hidden email]> wrote:
> From here it looks like I need to initially  add the following lines
> to master.cf:
> filter    unix  -       n       n       -       10      pipe
>     flags=Rq user=filter null_sender=
>     argv=/usr/local/bin/myscript -f ${sender} -- ${recipient}

I've knocked up a quick-and-dirty solution in the interim but I would
like to improve on this.

I've added the above filter section and replaced the previous content
filter with "-o content_filter=filter:dummy" to my submission service in
master.cf
Outgoing mail is now being processed by my shell script and email is
being sent OK.

However, in implementing this, I've lost the DK signing ability
and I'm also concerned at scalability & performance as alluded to in the
FILTER_README. Also, ALL outgoing email is processed by my script
whether it needs to be or not.

I would really value some recommendations on how to improve this.
Thanks.