/**
 * File:
 *   mail_auto.ycp
 *
 * Package:
 *   Configuration of mail
 *
 * Summary:
 *   Client for autoinstallation
 *
 * Authors:
 *   Martin Vidner <mvidner@suse.cz>
 *
 * $Id: mail_auto.ycp 19078 2004-09-03 14:28:57Z mvidner $
 *
 * This is a client for autoinstallation. It takes its arguments,
 * goes through the configuration and return the setting.
 * Does not do any changes to the configuration.
 */

/**
 * @param first a function
 * @return any
 * @example map mm = $[ "FAIL_DELAY" : "77" ];
 * @example map ret = WFM::CallModule ("mail_auto", [ "Summary", mm ]);
 */

{
textdomain "mail";

y2milestone("----------------------------------------");
y2milestone("Mail auto started");

import "Mail";
import "Mode";
import "Mail";
include "mail/ui.ycp";

any ret = nil;
string func = "";
map param = $[];

/* Fallback for the old calling convention:
   Do nothing instead of looping endlessly */
if (size (WFM::Args ()) > 0 &&
    (is (WFM::Args(0), map) || is (WFM::Args(0), list)))
{
    y2error ("This new-style module won't work with the old autoyast");
    return (any) [UI::UserInput (), WFM::Args (0)];
}

/* Check arguments */
if(size(WFM::Args()) > 0 && is(WFM::Args(0), string)) {
    func = (string) WFM::Args(0);
    if(size(WFM::Args()) > 1 && is(WFM::Args(1), map))
	param = (map) WFM::Args(1);
}
y2debug("func=%1", func);
y2debug("param=%1", param);

block<boolean> abort_block = ``{ return false; };

/* Import */
if(func == "Import") {
    ret = Mail::Import(param);
}
/* Create a  summary*/
else if(func == "Summary") {
    ret = Mail::Summary();
}
/* Reset configuration */
else if (func == "Reset") {
    Mail::Import($[]);
    Mail::touched = false;
    ret = $[];
}
else if (func == "Packages") {
    ret = Mail::AutoPackages();
}
else if (func == "Read") {
    ret = Mail::Read (abort_block);
}
/* Change configuration (run AutoSequence) */
else if (func == "Change") {
    ret = MailAutoSequence();
}
/* Return actual state */
else if (func == "Export") {
    ret = Mail::Export();
}
/**
 * Return if configuration  was changed
 * return boolean
 */
else if (func == "GetModified") {
    ret = Mail::touched;
}
/**
 * Set modified flag
 * return boolean
 */
else if (func == "SetModified") {
    Mail::touched = true;
    ret = true;
}
/* Write givven settings */
else if (func == "Write") {
    import "Progress";
    Mail::write_only = true;
    Progress::off();
    ret = Mail::Write(abort_block);
    Progress::on();
    return ret;
}
/* Unknown function */
else {
    y2error("Unknown function: %1", func);
    ret = false;
}

y2debug("ret=%1", ret);
y2milestone("Mail auto finished");
y2milestone("----------------------------------------");

return ret;

/* EOF */
}
