File: import_rfc.py

package info (click to toggle)
kopanocore 8.7.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, 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 (33 lines) | stat: -rwxr-xr-x 910 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
25
26
27
28
29
30
31
32
33
#!/usr/bin/python3
# SPDX-License-Identifier: AGPL-3.0-only

# import .eml/.ics/.vcf file

# usage: ./import-rfc.py -u username [-f folderpath] filename

from __future__ import print_function
import sys
import kopano

parser = kopano.parser('skpuf')
options, args = parser.parse_args()
server = kopano.Server(options)

for user in server.users():
    if options.folders:
        folders = list(user.folders())
    else:
        folders = [user.inbox]

    for folder in folders:
        for filename in args:
            data = open(filename, 'rb').read()
            if filename.endswith('.eml'):
                folder.create_item(eml=data)
            elif filename.endswith('.ics'):
                folder.create_item(ics=data)
            elif filename.endswith('.vcf'):
                folder.create_item(vcf=data)
            else:
                print('unknown filetype:')
                sys.exit(1)