Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Script to Remove Attachments in Exchange Mailbox

Reply
Thread Tools

Script to Remove Attachments in Exchange Mailbox

 
 
KDawg44
Guest
Posts: n/a
 
      10-11-2007
Hi,

I am frustrated with my users who send large files around the office
instead of using the network shares.

For instance, this is one of many emails I have sent around:

"If you take the this kit it looks like J sent it to D, D sent it to
you, then you sent it to me. The problem with that is just that now
there are copies of this file:


On J's drive or Comm drive
J's sent items
D's inbox
D's sent items
Your inbox
Your sent items
My inbox
The comm. Drive once I save it there to be used.

Which means that there are 8 copies of the same file 4MB taking up
space, or a 4MB file turned into a 32MB file."

My users just aren't getting it! And then they complain when they get
quota messages! (and some people, when they are Important People, you
cannot argue with).

So, what I would like, is to write a script that parses the exchange
mailbox, and removes all attachments over a certain size (say 500K)
that are attached to messages that are more than 2 weeks old, or that
are in sent items. I would like to write to a log file all the
changes that are made then email that log file to the mailbox that was
just trimmed.

I will also like to have a verbose mode that allows the user when the
script is run to ok each removal.

I am trying to decide if I should do this in Python or VBScript. Any
suggestions?

Thanks.

 
Reply With Quote
 
 
 
 
Tim Golden
Guest
Posts: n/a
 
      10-11-2007
KDawg44 wrote:
> Hi,
>
> I am frustrated with my users who send large files around the office
> instead of using the network shares.


[...]

> Which means that there are 8 copies of the same file 4MB taking up
> space, or a 4MB file turned into a 32MB file."
>
> So, what I would like, is to write a script that parses the exchange
> mailbox, and removes all attachments over a certain size (say 500K)
> that are attached to messages that are more than 2 weeks old, or that
> are in sent items. I would like to write to a log file all the
> changes that are made then email that log file to the mailbox that was
> just trimmed.


I have something v. similar, only it's at work and I'm not. Maybe tomorrow.
What it does -- I think, it's been a while -- is to rip through any
mailboxes finding attachments over a certain size, saving them to some
kind of folder structure on the user's home drive and replacing the
attachment by a link to the attachment. I have another script which,
independently, rips through users' home shares finding duplicates and
linking them to one copy.

It's a while since they were last run to they're probably quite
dusty but it sounds like the kind of thing you're after.

TJG
 
Reply With Quote
 
 
 
 
KDawg44
Guest
Posts: n/a
 
      10-11-2007
On Oct 11, 10:03 am, Tim Golden <(E-Mail Removed)> wrote:
> KDawg44 wrote:
> > Hi,

>
> > I am frustrated with my users who send large files around the office
> > instead of using the network shares.

>
> [...]
>
> > Which means that there are 8 copies of the same file 4MB taking up
> > space, or a 4MB file turned into a 32MB file."

>
> > So, what I would like, is to write a script that parses the exchange
> > mailbox, and removes all attachments over a certain size (say 500K)
> > that are attached to messages that are more than 2 weeks old, or that
> > are in sent items. I would like to write to a log file all the
> > changes that are made then email that log file to the mailbox that was
> > just trimmed.

>
> I have something v. similar, only it's at work and I'm not. Maybe tomorrow.
> What it does -- I think, it's been a while -- is to rip through any
> mailboxes finding attachments over a certain size, saving them to some
> kind of folder structure on the user's home drive and replacing the
> attachment by a link to the attachment. I have another script which,
> independently, rips through users' home shares finding duplicates and
> linking them to one copy.
>
> It's a while since they were last run to they're probably quite
> dusty but it sounds like the kind of thing you're after.
>
> TJG


That sounds great!

Thanks!

 
Reply With Quote
 
Tim Golden
Guest
Posts: n/a
 
      10-12-2007
[KDawg44]

>>> I am frustrated with my users who send large files around the office
>>> instead of using the network shares.


[Tim Golden]
>> I have something v. similar, ...
>> It's a while since they were last run to they're probably quite
>> dusty but it sounds like the kind of thing you're after.


Well, here's[1] the first part -- running through folders and replacing
big attachments with links. Now I look, it's designed to be run by
a user on his/her own mailbox rather than by an administrator. Naturally
it's got some stuff which is specific to my setup but nothing, I think,
which isn't easily understood and adapted or removed.

One note is that, as it says in the comments, there doesn't seem to
be a way of identifying large attachments as such, only large messages.
So there may be some corner case where an attachment is stripped out
which is in fact quite small. Obviously you could adapt the
process_attachment function to do something fancier than it is based
on the saved file size etc.

There are no dependencies outside the stdlib except, of course, the
pywin32 package. (Which is, for me, part of the stdlib whenever I
install on Windows). Feel free to email me privately or on-list if
you wish if there's anything which isn't clear etc.

TJG

[1] http://timgolden.me.uk/python/downlo...attachments.py

 
Reply With Quote
 
Tim Golden
Guest
Posts: n/a
 
      10-12-2007
Tim Golden wrote:
> [KDawg44]
>
>>>> I am frustrated with my users who send large files around the office
>>>> instead of using the network shares.

>
> [Tim Golden]
>>> I have something v. similar, ...
>>> It's a while since they were last run to they're probably quite
>>> dusty but it sounds like the kind of thing you're after.

>
> Well, here's[1] the first part -- running through folders and replacing
> big attachments with links.


.... and here's [1] the second part -- running through folders on disk
and replacing duplicate files with a link to the first one found. For
obvious reasons, be careful with this: it deletes files and replaces
them with hardlinks, but there's no rollback. Nor is it so well
commented as the other, I'm afraid, but I think it is still fairly
clear what's going on.

You call it with a space-separated list of directories to search
(usually one in my own experience) and it walks down those directory
trees looking for files of type INCLUDE_EXTENSIONS except for files
called IGNORE_FILES. Its comparison is very simple: comparing md5
hashes with no optimisations; obviously a lot of work could be done
there if it were an issue.

It ends up with nested dictionaries, the outer one keyed by filename,
the inner one by size and containing a list of directories where
files of that name/size are found. The first in the list is considered
the master and all the others are deleted and replaced by NTFS
hardlinks. Probably safer to hardlink first to an alias, *then*
delete and then rename the alias, but I leave that up to you if
you want to use the script at all.

TJG

[1] http://timgolden.me.uk/python/downlo...icate_files.py
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Differentiating file attachments from inline attachments in Exchange Peter Green Python 0 11-05-2009 04:13 PM
Cannot send mail from Exchange 2007 mailbox to Exchange 2003 mailb =?Utf-8?B?am9zdWU=?= MCSE 3 08-15-2007 12:02 PM
remove mail from exchange mailbox XPD NZ Computing 10 08-09-2006 08:37 AM
Absolutely brand new mailbox - 2 emails with 'attachments' paora NZ Computing 2 05-30-2004 09:40 AM
Script to remove SoBig/F virus from POP3 mailbox Alex Python 5 08-25-2003 05:55 PM



Advertisments