File: gotmail4evolution

package info (click to toggle)
gotmail 0.9.0-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, lenny, squeeze, wheezy
  • size: 196 kB
  • ctags: 36
  • sloc: perl: 1,051; sh: 101; makefile: 76
file content (213 lines) | stat: -rw-r--r-- 4,877 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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/bin/bash

#
#    gotmail4evolution - gets hotmail and makes ready for evolution.
#
#    Copyright (C) 2005 Jon Phillips <jon@rejon.org>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#
#
# This is an ugly script to get hotmail email and put them in the proper 
# place by force to be used inside Evolution
#
#
# INSTALL NOTE: Put this into you local scripts directory like:
#
#    ~/bin
# 
# After that, then run on your own evolution folder.
#
#
# TODO: Make this work for multiple non-hotmail.com domains
# TODO: Make this work for more than Inbox and Junk Mail folders.
# TODO: Do file tests.
#
#


# for debugging
VERBOSE=

#MAILPATH=""
MAILPATH="$HOME/.evolution/mail/local"

USERNAME=
PASSWORD=

GOTMAIL=gotmail

test_ret_val ()
{
    # arg 1 is error code and optional arg 2 is message indicating error

    if [ $1 != 0 ]
    then :
        if [ "$2" ]
	then :
	    echo $2
	else :
            echo "There seemed to be a problem with the script (error code $1)."
        fi
	echo ""
        exit 1
    fi
    
    #fi
}

# proc_mbox ()
#
# This sub processes a passed old mbox and moves to the proper location.
#
proc_mbox ()
{
    # $1 is tmp box and $2 is new box
    if [ -z "$1" ] && [ -z "$2" ]
    then :
        # echo "$1 $2"
        #echo "You must provide username and password for accounts"
        return 1
    else :
        # Process vars

        if [ -e "$1" ] # if the mbox exists
	then :
	    cat "$1" >> "$2"
	    chmod 600 "$1"
	    chmod 600 "$2"
	fi

    fi

    return 0
}

#
# getMyHotmail ()
#
# This sub uses the gotmail script to get my two main hotmail accounts
#
get_my_hotmail ()
{
    # $1 is username and $2 is password
    if [ -z "$1" ] && [ -z "$2" ]
#    if [ $1 ]
    then :
        echo "$1 $2"
        #echo "You must provide username and password for accounts"
        #return 1
    else :
        #OLD:  MAILPATH="$HOME/evolution/local/$1@hotmail.com"
        TMP_PATH="/tmp/$1@hotmail.com"
        INBOX="$MAILPATH/$1@hotmail.com"
        JUNKMAIL="$INBOX.sbd/Junk"


        # If it doesn't exist, then create, otherwise clear out the stuff in it
        if [ ! -e "$TMP_PATH" ] # if it doesn't exist
        then :
            mkdir $TMP_PATH
	else :
 	    rm -Rf $TMP_PATH/*
        fi

        RETURN=$?
        test_ret_val "$RETURN"

        if [ ! -z $VERBOSE ]; then
	   VERBOSECMD="-v"
        fi
        $GOTMAIL -u $1 -p $2 --folder-dir $TMP_PATH --mark-messages-as-read \
	    --delete $VERBOSECMD
        RETURN=$?
	test_ret_val "$RETURN"
       

	# deal with 
        proc_mbox "$TMP_PATH/Inbox" "$INBOX"
        RETURN=$?
	test_ret_val "$RETURN"
		
	proc_mbox "$TMP_PATH/Junk E-Mail" "$JUNKMAIL"
        RETURN=$?
	test_ret_val "$RETURN"

    fi

    return 0
}


print_help ()
{
    echo -e "\nGets hotmail and puts it somewhere evolution can see it."
    echo -e "\nUSAGE:\n`basename $0` [-hqv] [-u USERNAME ] [-p PASSWORD]" \
        " [-m PATH_TO_EVO_MAIL]\n"
    echo -e "\t-h help"
    echo -e "\t-v verbose output"
    echo -e "\t-q quiet output"
    echo -e "\t-u username"
    echo -e "\t-p password"
    echo -e "\t-m path to evolution mail\n"
    exit 1
}


# This is the main driver code
# First need to check if we are online and getting hotmail.com
#

# ping -c 1 hotmail.com
# RETURN=$?
# test_ret_val "$RETURN" "Your Internet connection or hotmail.com is offline."

###############################################################################
# MAIN DRIVER CODE
###############################################################################

# deal with commandline args (a : at the beginning suppresses some errors)
# put the : after a flag to grab next parameter as option
while getopts  "hvqu:p:m" flag
do
    # echo "$flag" $OPTIND $OPTARG
    case "$flag" in
	v) VERBOSE=1;;
	q) VERBOSE=;;
	u) USERNAME="$OPTARG";;
	p) PASSWORD="$OPTARG";;
	m) MAILPATH="$OPTARG";;
        h) print_help;;
        \? ) print_help;;
	* ) print_help;;
    esac
done
# if no arguments, then do this (don't need currently)
#if [ "$#" == 0 ]
#then :
#    print_help

if [ -z $USERNAME ] && [ -z $PASSWORD ]
then :
    echo $USERNAME
    echo $PASSWORD
    print_help
fi

get_my_hotmail $USERNAME $PASSWORD

exit 0