-
Notifications
You must be signed in to change notification settings - Fork 1
/
maildir2mboxloop
162 lines (131 loc) · 4.86 KB
/
maildir2mboxloop
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
What this script does.
Allows elm or other M.U.A. without Maildir
support to use elm in conjunction with pop mail.
It retrieves email as it arrives.
You don't have to run elm again to see the
mail that arrived while you were running elm
And avoids the problem of a a duplicate /tmp/mbox.Mailbox
by using a unique name i.e.
MAIL=$HOME/Mailbox.$USER
in /tmp/mbox.Mailbox.*
The "*" is derived by elm from the $MAIL env var
The whole script can be used or parts can be used.
for example an elm that doesn't need to be used with
pop3 but can retrieve newmail - or visa-versa
Though I didn't manage to spell my name right
in my letter to Ivan. The script seems reliable
I have replaced the script with a final version.
Final because I am done - not because the script is the
best it can be.
Chris Mosley
> Thanks for the script; I will install it today. I've Cc:'ed the qmail list
> as well.
>
> At 09:13 PM 9/27/97 -0400, you wrote:
> >
> >This script will work. I have tested it in parts
> >(to make sure all conditional statements are working -
> >they were all not working as I had assumed they would)
> >and alltogether. Asyncronous process will self-destruct if
> >it becomes detached. There is no loss of mail. I have tested it
> >with many and long emails.
> > I wonder about giving this and mbox2maildir to qmail so they can
> >make it available in the utility section of their www site.
> >
> >Ivan,
> >Please email me back about this even if you don't decide to install it
> >globally. But I'm having difficulty receiving email <g>. It could
> >also be installed under an alternate name.
> > Thanks
> > Chistopher Mosley
> >--------------------------------------------------------------------------
> >
This elm wrapper seems to work well after a lot of testing. If there
is a mailbox hanging around change its name to Mailbox.$USER before
using this wrapper. It should have the functionality of elm
when sendmail was being used (pop3 and ability to retrieve new email.)
It can take considerable abuse and should work well under most
conditions. There is one change from my last posting, the line:
PROCESS=`ps -x$SCRIPT_PROCESS | wc -l`
should be
PROCESS=`ps $SCRIPT_PROCESS | wc -l`
if the loop is detached from terminal it might as well not exist.
The first conversion from mbox to maildir is also probably an
unneeded and probably ineffective redundancy
(way of ending an escaped asyncronous loop).
Since iteration of loop also depends on the existence of $MAIL.
There should probably be a "sleep" as long as the sleep in the loop
after the conversion. What is important that the script works
in practice - and I have to stop ammending the script sometime.
mbox2maildir is derived from the public domain perl script
convert_and_create by Russell Nelson and can be supplied
if anyone is interested.
________________________________________________________________________
#!/bin/sh
MAILDIR=$HOME/Maildir
MAIL=$HOME/Mailbox.$USER
MAILTMP=$HOME/Mailbox.tmp
SCRIPT_PROCESS=$$
export MAILDIR MAIL MAILTMP
export SCRIPT_PROCESS
#------------------------------
# In case mailbox wasn't deleted last elm session,
# this should rarely if ever happen.
# $MAIL must not use PID so name of mailbox will remain the same
# from session to session.
if test -f $MAIL
then
if test -s $MAIL
then /usr/local/bin/mbox2maildir
else
rm -f $MAIL
fi
fi
#------------------------------
# Create a mailbox even if there isn't any mail
# in order to receive mail.
MAIL_DIR_EMPTY=`ls $MAILDIR/new | sed q`
if test THE = "THE$MAIL_DIR_EMPTY"
then /usr/bin/echo -n > $MAIL
else
/var/qmail/bin/maildir2mbox
fi
#------------------------------
# Background process to retrieve new mail.
# Process will end if mailbox deleted (as in mbox2maildir)
# or will self destruct when the script
# process no longer exists
(DONE=false
while test -f $MAIL -a $DONE = false
do
sleep 15
NEWMAIL=`ls $MAILDIR/new | sed q`
PROCESS=`ps $SCRIPT_PROCESS | wc -l`
if test $PROCESS -eq 1
then DONE=true
else
DONE=false
fi
if test -f $MAIL -a "A$NEWMAIL" != A -a $DONE = false
then /var/qmail/bin/maildir2mbox
fi
done)&
#------------------------------
elm.real $@
#------------------------------
# Simply delete mailbox if file length zero,
# mbox2maildir does not work with empty file.
# kill asynchronous process to prevent conflicts
# between mbox2maildir and maildir2mbox.
# "sleep" so script can rest from its labors
# before running mbox2maildir.
kill $!
sleep 1
if test -s $MAIL
then /usr/local/bin/mbox2maildir
else
rm -f $MAIL
fi
# "wait" can be used here but script takes
# longer to end. It is not critical.
#---------------------------