File: dump-att.py

package info (click to toggle)
kopanocore 8.7.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 15,400 kB
  • sloc: cpp: 175,422; python: 24,623; perl: 7,319; php: 6,056; sh: 2,172; makefile: 1,294; xml: 45; ansic: 1
file content (24 lines) | stat: -rwxr-xr-x 839 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/python3
# SPDX-License-Identifier: AGPL-3.0-only

# Dumps all attachments for a given user to files.
# This can be used to verify that attachments did not
# get corrupt during e.g. backup/restore.

# usage: ./dump-att.py -u username 

import md5
import kopano
from MAPI.Util import *

server = kopano.Server()

for user in server.users(): # checks command-line for -u/--user
    for folder in user.store.folders(): # checks command-line for -f/--folder
        for item in folder:
            for att in item.attachments():
                h = md5.new(item.subject + ' ' + att.filename + ' ' + item.sourcekey).hexdigest()
                filename = h + '_' + att.filename
                print 'file %s: %d bytes' % (filename, len(att.data))
                with open(filename, 'wb') as f:
                    f.write(att.data)