File: gotmail4evolution

package info (click to toggle)
gotmail 0.8.9-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 196 kB
  • ctags: 39
  • sloc: perl: 1,047; makefile: 81; sh: 69
file content (174 lines) | stat: -rw-r--r-- 3,932 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
#!/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: Clean up the code significantly.
# TODO: Do file tests.
#
#


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


testRetVal ()
{
    # 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
}

# procMbox ()
#
# This sub processes a passed old mbox and moves to the proper location.
#
procMbox ()
{
    # $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
#
getMyHotmail ()
{
    # $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=$?
        testRetVal "$RETURN"

        gotmail -u $1 -p $2 --folder-dir $TMP_PATH --mark-messages-as-read \
	    --delete
        RETURN=$?
	testRetVal "$RETURN"
       

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

    fi

    return 0
}



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

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

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

if [ -z "$1" ] || [ -z "$2" ] || [ "$1" = '-h' ] || [ "$1" = '--help' ]
then :
    echo ""
    echo "Usage: gethotmail <username> <password>"
    echo ""

elif [ ! -z "$1" ] && [ ! -z "$2" ]
then :
    getMyHotmail "$1" "$2"
fi