/* this program builds up a talktopop config file.
   If the file exists it uses the information if there as a default, 
   otherwise it tries to give some sensible information */
#include "talktopop.h"
#include <stdio.h>
#include <string.h>
#include <pwd.h>
char popserver[100] ;
char popname [100] ;
char protname [100] ;
char uname[100] ;
char passwd[100] ;
int filestartno = 0 ;
int dodel = FALSE ;
int direction = FALSE ;
int verbose = FALSE ;
int maxsize = MAXSIZE ;
int maxemail = MAXCOUNT ;
int hnset, pwset, unset ;

main ()
{
	confinit() ;
	readconf() ;
	newconf() ;
	writeconf() ;
}

newconf()
{
	char tmp[1024] ;
	/* say hi etc. */
	printf("This program builds or modifies you %s configuration file\n", POPCONF) ;
	printf("If the %s file exists it uses the data in that file for defaults\n") ;
	printf("Otherwise it provides its own.\n") ;
	printf("Where a value is given in brackets (e.g. [tim]) you just have to\n") ;
	printf("hit return to accept this of enter a new value if you want to change it\n") ;
	printf("In the password field if there is an existing value you want to remove just enter -\n") ;
	/* get the users name */
	getuname(uname) ;
	getstr(uname, "your username", FALSE) ;
	printf("WARNING. If you enter a password it will be stored in clear\ntext format in a configuration file. This is a potential security\nhole. If you chose not to enter a password you will be prompted\nfor it each time you run talktopop\n") ;
	getstr(passwd, "your password", TRUE) ;
	getstr(popserver, "the name of the machine running the POP-3 server", FALSE) ;
	getno(&filestartno, "the number you want to use as the starting point for retrieved file names") ;
	getyn("true if you want talktopop to delete emails from the mailbox once they are downloaded, false if you want them to be kept", &dodel) ;
	getyn("true if you want talktopop to retrieve emails from the start of your mailbox, false if you want it to retrieve them from the end", &direction) ;
	getyn("true if you want talktopop to be verbose, false otherwise", &verbose) ;
	getno(&maxsize, "the maximum email size (in bytes) to be downloaded") ;
	getno(&maxemail, "the maximum number of emails to be downloaded to the psion") ;
	getstr(popname, "the name of the pop-3 server in the services file / map", FALSE) ;
	getstr(protname, "the name of the transport mechanism used to talk to pop (Leave as tcp unless you REALY know better)", FALSE) ;
}
