Script to Remove Attachments in Exchange Mailbox

Discussion in 'Python' started by KDawg44, Oct 11, 2007.

  1. KDawg44

    KDawg44 Guest

    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.
     
    KDawg44, Oct 11, 2007
    #1
    1. Advertising

  2. KDawg44

    Tim Golden Guest

    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
     
    Tim Golden, Oct 11, 2007
    #2
    1. Advertising

  3. KDawg44

    KDawg44 Guest

    On Oct 11, 10:03 am, Tim Golden <> 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!
     
    KDawg44, Oct 11, 2007
    #3
  4. KDawg44

    Tim Golden Guest

    [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/downloads/strip_attachments.py
     
    Tim Golden, Oct 12, 2007
    #4
  5. KDawg44

    Tim Golden Guest

    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/downloads/find_duplicate_files.py
     
    Tim Golden, Oct 12, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. - Steve -

    Creating Exchange Mailbox

    - Steve -, Jun 14, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    572
    Trevor Benedict R
    Jun 15, 2004
  2. Alex
    Replies:
    5
    Views:
    588
    Kevin Altis
    Aug 25, 2003
  3. Lindstrom Greg - glinds

    Monitoring an MS Exchange mailbox

    Lindstrom Greg - glinds, Dec 29, 2003, in forum: Python
    Replies:
    2
    Views:
    350
    Tim Howarth
    Dec 30, 2003
  4. Tim Golden

    RE: Monitoring an MS Exchange mailbox

    Tim Golden, Dec 30, 2003, in forum: Python
    Replies:
    1
    Views:
    414
    Tim Golden
    Dec 30, 2003
  5. Peter Green
    Replies:
    0
    Views:
    648
    Peter Green
    Nov 5, 2009
Loading...

Share This Page