diff --git a/man/freedombone-archive-mail.1.gz b/man/freedombone-archive-mail.1.gz
new file mode 100644
index 0000000000000000000000000000000000000000..ab90e298100246200ecffa7b831cf39d3002327d
Binary files /dev/null and b/man/freedombone-archive-mail.1.gz differ
diff --git a/src/freedombone b/src/freedombone
index 9063063e69e58ccfa94b8af640e78fbe28ae2cbd..33a121bca4009d5c1cba1586d4fb43f1c9a67320 100755
--- a/src/freedombone
+++ b/src/freedombone
@@ -5187,6 +5187,19 @@ function email_archiving {
       return
   fi
 
+  # ensure that the mail archive script is up to date
+  if [ -f /usr/local/bin/${PROJECT_NAME}-archive-mail ]; then
+      cp /usr/local/bin/${PROJECT_NAME}-archive-mail /etc/cron.daily/archivemail
+  else
+      if [ -f /usr/bin/${PROJECT_NAME}-archive-mail ]; then
+          cp /usr/bin/${PROJECT_NAME}-archive-mail /etc/cron.daily/archivemail
+      else
+          echo "/usr/bin/${PROJECT_NAME}-archive-email was not found. ${PROJECT_NAME} might not have fully installed."
+          exit 62379
+      fi
+  fi
+  chmod +x /etc/cron.daily/archivemail
+
   # update to the next commit
   if [ -d $INSTALL_DIR/cleanup-maildir ]; then
       if grep -q "cleanup-maildir commit" $COMPLETION_FILE; then
@@ -5222,28 +5235,6 @@ function email_archiving {
   fi
 
   cp $INSTALL_DIR/cleanup-maildir/cleanup-maildir /usr/bin
-  echo '#!/bin/bash' > /etc/cron.daily/archivemail
-  echo 'for d in /home/*/ ; do' >> /etc/cron.daily/archivemail
-  echo '  USERNAME=$(echo "$d" | awk -F '"'"'/'"'"' '"'"'{print $3}'"'"')' >> /etc/cron.daily/archivemail
-  echo '  if [[ $USERNAME != "git" ]]; then' >> /etc/cron.daily/archivemail
-  echo '    if [ -d /home/$USERNAME/Maildir ]; then' >> /etc/cron.daily/archivemail
-  echo '      MUTTRC=/home/$USERNAME/.muttrc' >> /etc/cron.daily/archivemail
-  echo '      python /usr/bin/cleanup-maildir --archive-folder="archive" --maildir-root="/home/$USERNAME/Maildir" archive ""' >> /etc/cron.daily/archivemail
-  echo '      chown -R $USERNAME:$USERNAME /home/$USERNAME/Maildir/archive-*' >> /etc/cron.daily/archivemail
-  echo '      if [ -f $MUTTRC ]; then' >> /etc/cron.daily/archivemail
-  echo '        MUTT_MAILBOXES=$(grep "mailboxes =" $MUTTRC)' >> /etc/cron.daily/archivemail
-  echo '        BACKUP_DIRECTORY=archive-$(date +"%Y")' >> /etc/cron.daily/archivemail
-  echo '        if [[ $MUTT_MAILBOXES != *$BACKUP_DIRECTORY* ]]; then' >> /etc/cron.daily/archivemail
-  echo '          sed -i "s|$MUTT_MAILBOXES|$MUTT_MAILBOXES =$BACKUP_DIRECTORY|g" $MUTTRC' >> /etc/cron.daily/archivemail
-  echo '          chown $USERNAME:$USERNAME $MUTTRC' >> /etc/cron.daily/archivemail
-  echo '        fi' >> /etc/cron.daily/archivemail
-  echo '      fi' >> /etc/cron.daily/archivemail
-  echo '    fi' >> /etc/cron.daily/archivemail
-  echo '  fi' >> /etc/cron.daily/archivemail
-  echo 'done' >> /etc/cron.daily/archivemail
-
-  echo 'exit 0' >> /etc/cron.daily/archivemail
-  chmod +x /etc/cron.daily/archivemail
 
   echo 'email_archiving' >> $COMPLETION_FILE
 }
diff --git a/src/freedombone-archive-mail b/src/freedombone-archive-mail
new file mode 100755
index 0000000000000000000000000000000000000000..ee9e6a19e23c0825eac93d540013f3143a5021ff
--- /dev/null
+++ b/src/freedombone-archive-mail
@@ -0,0 +1,61 @@
+#!/bin/bash
+#
+# .---.                  .              .
+# |                      |              |
+# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
+# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
+# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
+#
+#                    Freedom in the Cloud
+#
+# Archives old email
+
+# License
+# =======
+#
+# Copyright (C) 2015 Bob Mottram <bob@robotics.uk.to>
+#
+# 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 3 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, see <http://www.gnu.org/licenses/>.
+
+PROJECT_NAME='freedombone'
+
+export TEXTDOMAIN=${PROJECT_NAME}-archive-mail
+export TEXTDOMAINDIR="/usr/share/locale"
+
+for d in /home/*/ ; do
+    USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
+    if [[ $USERNAME != "git" ]]; then
+        # for every user who has a mail directory
+        if [ -d /home/$USERNAME/Maildir ]; then
+            MUTTRC=/home/$USERNAME/.muttrc
+            # update archives
+            python /usr/bin/cleanup-maildir --archive-folder="archive" --maildir-root="/home/$USERNAME/Maildir" archive ""
+            # ensure the user has permissions on the archives
+            for archive_dir in /home/$USERNAME/Maildir/archive-* ; do
+                chown -R $USERNAME:$USERNAME $archive_dir
+            done
+            # add the archive to .muttrc if needed
+            if [ -f $MUTTRC ]; then
+                MUTT_MAILBOXES=$(grep "mailboxes =" $MUTTRC)
+                BACKUP_DIRECTORY=archive-$(date +"%Y")
+                if [[ $MUTT_MAILBOXES != *$BACKUP_DIRECTORY* ]]; then
+                    sed -i "s|$MUTT_MAILBOXES|$MUTT_MAILBOXES =$BACKUP_DIRECTORY|g" $MUTTRC
+                    chown $USERNAME:$USERNAME $MUTTRC
+                fi
+            fi
+        fi
+    fi
+done
+
+exit 0