471,339 Members | 1,289 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,339 software developers and data experts.

Script to Remove Attachments in Exchange Mailbox

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.

Oct 11 '07 #1
4 6527
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
Oct 11 '07 #2
On Oct 11, 10:03 am, Tim Golden <m...@timgolden.me.ukwrote:
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!

Oct 11 '07 #3
[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

Oct 12 '07 #4
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
Oct 12 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Lindstrom Greg - glinds | last post: by
6 posts views Thread by chuck amadi | last post: by
reply views Thread by Manuel Krummenacher | last post: by
reply views Thread by Tim Sapp | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.