summaryrefslogtreecommitdiff
path: root/upgrade-to-3.0-native-from-2.3-openpkg/33-attempt-groupware-messages-formatupgrade.sh
blob: 702d3e7435be89e6014746b5d7b2254c38a208e2 (plain)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash

# Interesting Annotations
declare -a ia

ia[${#ia[@]}]="/shared/vendor/kolab/folder-type"

export total_num=`./21-count-groupware-messages.sh`
export done_num=0
export last_percent=0

pushd /root/pykolab.git >/dev/null 2>&1

for folder_search in user/*@kolabsys.com shared/*@kolabsys.com; do
    ./kolab.py list-mailbox-metadata "${folder_search}" | while read line; do
        if [ ! -z "$(echo $line | grep ^Folder)" ]; then
            current_folder=$(echo $line | cut -d' ' -f2-)
        else
            annotation_key=$(echo $line | awk '{print $1}')
            annotation_value=$(echo $line | awk '{print $2}')

            # See if it is indeed interesting metadata
            i=0
            interesting_annotation=0
            while [ $i -lt ${#ia[@]} ]; do
                if [ "${ia[$i]}" == "${annotation_key}" ]; then
                    case "${annotation_value}" in
                        contact|contact.default)
                            interesting_annotation=1
                        ;;

                        event|event.default)
                            interesting_annotation=1
                        ;;

                        journal|journal.default)
                            interesting_annotation=1
                        ;;

                        note|note.default)
                            interesting_annotation=1
                        ;;

                        task|task.default)
                            interesting_annotation=1
                        ;;

                    esac
                fi
                let i++
            done

            if [ ${interesting_annotation} -eq 0 ]; then
                continue
            fi

            /usr/lib/cyrus-imapd/mbpath "${current_folder}"

        fi

    done | \

    while read folder2; do
        find "${folder2}" -mindepth 1 -maxdepth 1 -type f -name "*." | \
            sort | \
            while read file; do
                kolab-formatupgrade --mime "${file}" > /tmp/upgrade.log 2>&1
                fail_dir="/root/conversion-fail/"
                if [ ! -z "$(grep "^X-Kolab-Type:" "${file}")" ]; then
                    fail_dir="${fail_dir}/$(grep "^X-Kolab-Type:" "${file}" | cut -d':' -f2-)"
                elif [ ! -z "$(grep "^X-Mailer:" "${file}")" ]; then
                    fail_dir="${fail_dir}/$(grep "^X-Mailer:" "${file}" | cut -d':' -f2-)"
                fi

                fail_dir=$(echo ${fail_dir} | sed -r -e 's/\s*//g' -e 's/\s*\n*\r*$//g')

                if [ ! -d "${fail_dir}" ]; then
                    mkdir -p "${fail_dir}"
                fi

                if [ ! -z "$(grep 'failed to read mime file' /tmp/upgrade.log)" ]; then
                    cp -a "${file}" ${fail_dir}/$(md5sum "${file}" | awk '{print $1}').msg
                    mv /tmp/upgrade.log ${fail_dir}/$(md5sum "${file}" | awk '{print $1}').log
                elif [ ! -z "$(grep 'invalid object type' /tmp/upgrade.log)" ]; then
                    cp -a "${file}" ${fail_dir}/$(md5sum "${file}" | awk '{print $1}').msg
                    mv /tmp/upgrade.log ${fail_dir}/$(md5sum "${file}" | awk '{print $1}').log
                else
                    echo "${file}"
                fi

                let done_num++

                percent=$(( ${done_num} * 100 / ${total_num} ))
                if [ ${percent} -gt ${last_percent} ]; then
                    echo "${percent}% completed."
                    last_percent=${percent}
                fi
            done
    done
done

popd >/dev/null 2>&1