I want to read E-Mails from an IMAP-Server with curl (BashScript, which is using curl).
My problem is: After moving an E-Mail the IMAP-Server does not update, so that, if I examine the inbox, the IMAP Server shows me the old amount of messages, containing in the INBOX.
To clear my problem, here is some example-Code:
function delete_mail_id() {
curl --insecure \
--url "${SERVER}/INBOX" \
--user "${USER}:${PASSWD}" \
-X "STORE ${1} +Flags \Deleted" 1>/dev/null 2>/dev/null
}
function copy_mail_id_to() {
curl --insecure \
--url "${SERVER}/INBOX;UID=${1}" \
--user "${USER}:${PASSWD}" \
-X "COPY ${1} INBOX/${2}" 1>/dev/null 2>/dev/null
}
function move_mail_id_to() {
copy_mail_id_to "${1}" "${2}"
delete_mail_id "${1}"
}
function wait_for_mail_move(){
TEMP=$( tempfile )
while true; do
fetch_first_mail > $TEMP
if [ "$( grep 'Message-ID:' $TEMP )" != "${1}" ]; then
break
else
sleep 1
fi
done
rm $TEMP
}
Now after moving an E-Mail I wait for the mail to move, but it seems to be an endless loop. Now the funny part: If I look the mails manually through my webmailer the loop ends and the mails are moved one by one (I have a loop, so all the mails should be sorted in other Folders).
Somehow the IMAP only moves the Mails if I check it through the webmailer, but doesn't do it, if I don't check it. This should be automated, so, can anyone explain to me, why this is happening and what I can do about it?