473,387 Members | 1,318 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 6627
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Lindstrom Greg - glinds | last post by:
I'm using python 2.3 and Windows 2000 "Professional" to access a Microsoft Exchange Server to monitor messages and perform various tasks around the office. My little program is attracted quite a...
6
by: chuck amadi | last post by:
Hi , Im trying to parse a specific users mailbox (testwwws) and output the body of the messages to a file ,that file will then be loaded into a PostGresql DB at some point . I have read the...
2
by: Ken Fine | last post by:
I've read about how to use CDO/CDONTs to manipulate mail sent to a server computer, and how to configure DNS so that the SMTP server will get the mail that you want it to. Using CDO/CDONTS, can...
0
by: Manuel Krummenacher | last post by:
Hello! I'm trying to develop an application to manage email-forwardings on an Exchange 2000 Server. Forwardings to external Addresses are requiring a contact with an Exchange account. I can...
0
by: Tim Sapp | last post by:
Guys, I am working on a new web site for our company and have started to move my code from VB.Net to C#. I have ran into a snag that I can't seem to figure out. I am trying to create an...
0
by: Suman | last post by:
Hello Group, I am relatively new to .NET. I am trying to create a user in AD and a corresponding email account in the exchange server from an ASP.NET, C# application. ...
0
by: arjen1984 | last post by:
I want to create a mailbox-enabled mailbox. First i have used the toturial from microsoft: http://support.microsoft.com/kb/313114 Then my homeMDB string was incorrect. I saw an article , link:...
4
by: pjblecha | last post by:
Hello all: I'm working on a non-web-based (darn it...) application that will be set up as a scheduled task on an Exchange server to run against a mailbox 2-3 times per day. What the app needs to...
20
realin
by: realin | last post by:
hiya guys, I have a question, i want to display the image which is above the page, while my script loads in the background. This is a simple script which check for new messages in my mailbox,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.