<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://web-harvest.sourceforge.net/schema/1.0/config" scriptlang="groovy">

    <script><![CDATA[
        import com.workfusion.odf.core.Intake
        import com.workfusion.odf.impl.connector.EmailTransactionConnector;


        String mailProtocol = mail_protocol.toString();
        def params = [
                'mail_protocol': mail_protocol.toString(),
                "input_folder": input_folder.toString(),
                "mail_credential_alias": mail_credential_alias.toString(),
                "mark_as_read": mark_as_read.toString(),
                "post_action": post_action.toString(),
                "target_folder": target_folder.toString()
        ];

        if (mailProtocol.equals("exchange")) {
            params << [
                "mail_server": mail_server.toString(),
                "mail_domain": mail_domain.toString(),             
                "exchange_version": exchange_version.toString()
            ]
        } else if (mailProtocol.equals("imap") || mailProtocol.equals("pop3")) {
            params << [
                "mail_host": mail_host.toString(),
                "mail_port": mail_port.toString(),                
                "mail_ssl": mail_ssl.toString()
            ]
        } else {
            throw new IllegalArgumentException("Wrong mail protocol: " + mailProtocol);
        }


        def transactions = Intake.init(binding).params(params).get().loadTransactions(EmailTransactionConnector.class);

        result = [];
        transactions.each {
            result << ['transaction_id': it.id];
        }
        ]]></script>

    <export include-original-data="true">
        <multi-column list="${result}" split-results="true">
            <put-to-column-getter name="_sys_transaction_id" property="transaction_id"/>
        </multi-column>
    </export>
</config>
