Implemented complete configuration loading for accounts
This commit is contained in:
parent
7df68d3123
commit
973d52eab1
@ -96,6 +96,42 @@ int account_set_title(Account * account, char const * title)
|
|||||||
|
|
||||||
|
|
||||||
/* useful */
|
/* useful */
|
||||||
|
/* account_config_load */
|
||||||
|
int account_config_load(Account * account, Config * config)
|
||||||
|
{
|
||||||
|
AccountConfig * p;
|
||||||
|
char * value;
|
||||||
|
char * q;
|
||||||
|
long l;
|
||||||
|
|
||||||
|
for(p = account->plugin->config; p->name != NULL; p++)
|
||||||
|
{
|
||||||
|
if((value = config_get(config, account->title, p->name))
|
||||||
|
== NULL)
|
||||||
|
continue;
|
||||||
|
switch(p->type)
|
||||||
|
{
|
||||||
|
case ACT_FILE:
|
||||||
|
case ACT_STRING:
|
||||||
|
case ACT_PASSWORD: /* FIXME unscramble */
|
||||||
|
free(p->value);
|
||||||
|
p->value = strdup(value);
|
||||||
|
break;
|
||||||
|
case ACT_UINT16:
|
||||||
|
l = strtol(value, &q, 0);
|
||||||
|
if(value[0] != '\0' && *q == '\0')
|
||||||
|
(long)p->value = l;
|
||||||
|
break;
|
||||||
|
/* FIXME implement the rest */
|
||||||
|
case ACT_BOOLEAN:
|
||||||
|
case ACT_NONE:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* account_disable */
|
/* account_disable */
|
||||||
int account_disable(Account * account)
|
int account_disable(Account * account)
|
||||||
{
|
{
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
#ifndef MAILER_ACCOUNT_H
|
#ifndef MAILER_ACCOUNT_H
|
||||||
# define MAILER_ACCOUNT_H
|
# define MAILER_ACCOUNT_H
|
||||||
|
|
||||||
|
# include <System.h>
|
||||||
|
|
||||||
|
|
||||||
/* types */
|
/* types */
|
||||||
typedef struct _AccountIdentity
|
typedef struct _AccountIdentity
|
||||||
@ -84,6 +86,8 @@ void account_delete(Account * account);
|
|||||||
int account_set_title(Account * account, char const * title);
|
int account_set_title(Account * account, char const * title);
|
||||||
|
|
||||||
/* useful */
|
/* useful */
|
||||||
|
int account_config_load(Account * account, Config * config);
|
||||||
|
|
||||||
int account_disable(Account * account);
|
int account_disable(Account * account);
|
||||||
int account_enable(Account * account);
|
int account_enable(Account * account);
|
||||||
/* FIXME wrong we just need receive, then it calls callbacks */
|
/* FIXME wrong we just need receive, then it calls callbacks */
|
||||||
|
29
src/mailer.c
29
src/mailer.c
@ -127,6 +127,7 @@ static int _mailer_config_load_account(Mailer * mailer, char const * name)
|
|||||||
return 1;
|
return 1;
|
||||||
if((account = account_new(type, name)) == NULL)
|
if((account = account_new(type, name)) == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
|
account_config_load(account, mailer->config);
|
||||||
mailer_account_add(mailer, account);
|
mailer_account_add(mailer, account);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -458,3 +459,31 @@ int mailer_account_add(Mailer * mailer, Account * account)
|
|||||||
mailer->account_cnt++;
|
mailer->account_cnt++;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* mailer_account_disable */
|
||||||
|
int mailer_account_disable(Mailer * mailer, Account * account)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
for(i = 0; i < mailer->account_cnt; i++)
|
||||||
|
if(mailer->account[i] == account)
|
||||||
|
break;
|
||||||
|
if(i == mailer->account_cnt)
|
||||||
|
return 1;
|
||||||
|
return account_disable(account);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* mailer_account_enable */
|
||||||
|
int mailer_account_enable(Mailer * mailer, Account * account)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
for(i = 0; i < mailer->account_cnt; i++)
|
||||||
|
if(mailer->account[i] == account)
|
||||||
|
break;
|
||||||
|
if(i == mailer->account_cnt)
|
||||||
|
return 1;
|
||||||
|
return account_enable(account);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user