#!/bin/bash

balsa_setup() {
    if [ -d ~/.balsa ]; then
        printf >&2 '~/.balsa already exists, will not run test.\n'
        exit 1
    fi

    if [ -n "$AUTOPKGTEST_ARTIFACTS" ]; then
        export workdir=$AUTOPKGTEST_ARTIFACTS
    else
        export workdir=$(mktemp -d)
    fi

    mkdir ~/.balsa
    mkdir -p "$workdir/mail/"{mailbox/,outbox/,sent/,drafts/,trash/}{cur,new,tmp}
    cat > ~/.balsa/config <<EOF
[Globals]
MailDir=$workdir/mail

[Notifications]
GtkUIManager=true

[mailbox-Inbox]
Path=$workdir/mail/mailbox
Type=LibBalsaMailboxMaildir
Name=Inbox

[mailbox-Outbox]
Path=$workdir/mail/outbox
Type=LibBalsaMailboxMaildir
Name=Outbox

[mailbox-Sentbox]
Path=$workdir/mail/sent
Type=LibBalsaMailboxMaildir
Name=Sent

[mailbox-Draftbox]
Path=$workdir/mail/drafts
Type=LibBalsaMailboxMaildir
Name=Drafts

[mailbox-Trash]
Path=$workdir/mail/trash
Type=LibBalsaMailboxMaildir
Name=Trash

[identity]
CurrentIdentity=user

[identity-user]
FullName=Example User
Address=user@example.com

[smtp-server-Default]
Server=localhost:25
Anonymous=true
EOF
    cat > ~/.balsa/config-private <<EOF
EOF
}

balsa_teardown() {
    rm -rf ~/.balsa
}
