diff --git a/e_mod_config.c b/e_mod_config.c index 0ceffde..7fc12e6 100644 --- a/e_mod_config.c +++ b/e_mod_config.c @@ -1,323 +1,356 @@ #include #include "e_mod_main.h" -struct _E_Config_Dialog_Data +struct _E_Config_Dialog_Data { - int show_label; - double check_time; - Evas_List *boxes; + int show_label; + double check_time; + Evas_List *boxes; - /* Evas Object References */ - Evas_Object *il; - Evas_Object *del; - Evas_Object *configure; + /* Evas Object References */ + Evas_Object *il; + Evas_Object *del; + Evas_Object *configure; }; -static void *_create_data(E_Config_Dialog *cfd); -static void _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata); -static Evas_Object *_basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata); -static int _basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata); +static void *_create_data (E_Config_Dialog * cfd); +static void _free_data (E_Config_Dialog * cfd, E_Config_Dialog_Data * cfdata); +static Evas_Object *_basic_create_widgets (E_Config_Dialog * cfd, Evas * evas, + E_Config_Dialog_Data * cfdata); +static int _basic_apply_data (E_Config_Dialog * cfd, + E_Config_Dialog_Data * cfdata); -static void _load_boxes(E_Config_Dialog *cfd); -static int _ilist_header_exists(Evas_Object *il, const char *name); -static void _ilist_cb_selected(void *data); -static void _cb_add_box(void *data, void *data2); -static void _cb_edit_box(void *data, void *data2); -static void _cb_del_box(void *data, void *data2); +static void _load_boxes (E_Config_Dialog * cfd); +static int _ilist_header_exists (Evas_Object * il, const char *name); +static void _ilist_cb_selected (void *data); +static void _cb_add_box (void *data, void *data2); +static void _cb_edit_box (void *data, void *data2); +static void _cb_del_box (void *data, void *data2); void -_config_mail_module(Config_Item *ci) +_config_mail_module (Config_Item * ci) { - E_Config_Dialog *cfd; - E_Config_Dialog_View *v; - E_Container *con; - char buf[4096]; - - v = E_NEW(E_Config_Dialog_View, 1); - if (!v) return; - - v->create_cfdata = _create_data; - v->free_cfdata = _free_data; - v->basic.apply_cfdata = _basic_apply_data; - v->basic.create_widgets = _basic_create_widgets; + E_Config_Dialog *cfd; + E_Config_Dialog_View *v; + E_Container *con; + char buf[4096]; - snprintf(buf, sizeof(buf), "%s/module.eap", e_module_dir_get(mail_config->module)); - con = e_container_current_get(e_manager_current_get()); - cfd = e_config_dialog_new(con, _("Mail Configuration"), buf, 0, v, ci); - mail_config->config_dialog = cfd; + v = E_NEW (E_Config_Dialog_View, 1); + if (!v) + return; + + v->create_cfdata = _create_data; + v->free_cfdata = _free_data; + v->basic.apply_cfdata = _basic_apply_data; + v->basic.create_widgets = _basic_create_widgets; + + snprintf (buf, sizeof (buf), "%s/module.eap", + e_module_dir_get (mail_config->module)); + con = e_container_current_get (e_manager_current_get ()); + cfd = e_config_dialog_new (con, _("Mail Configuration"), buf, 0, v, ci); + mail_config->config_dialog = cfd; } static void -_fill_data(Config_Item *ci, E_Config_Dialog_Data *cfdata) +_fill_data (Config_Item * ci, E_Config_Dialog_Data * cfdata) { - cfdata->show_label = ci->show_label; - cfdata->check_time = ci->check_time; - cfdata->boxes = ci->boxes; + cfdata->show_label = ci->show_label; + cfdata->check_time = ci->check_time; + cfdata->boxes = ci->boxes; } static void * -_create_data(E_Config_Dialog *cfd) +_create_data (E_Config_Dialog * cfd) { - E_Config_Dialog_Data *cfdata; - Config_Item *ci; - - ci = cfd->data; - cfdata = E_NEW(E_Config_Dialog_Data, 1); - _fill_data(ci, cfdata); - return cfdata; + E_Config_Dialog_Data *cfdata; + Config_Item *ci; + + ci = cfd->data; + cfdata = E_NEW (E_Config_Dialog_Data, 1); + _fill_data (ci, cfdata); + return cfdata; } static void -_free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata) +_free_data (E_Config_Dialog * cfd, E_Config_Dialog_Data * cfdata) { - if (!mail_config) return; - mail_config->config_dialog = NULL; - free(cfdata); - cfdata = NULL; + if (!mail_config) + return; + mail_config->config_dialog = NULL; + free (cfdata); + cfdata = NULL; } static Evas_Object * -_basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata) +_basic_create_widgets (E_Config_Dialog * cfd, Evas * evas, + E_Config_Dialog_Data * cfdata) { - Evas_Object *o, *of, *ob, *ot; + Evas_Object *o, *of, *ob, *ot; - o = e_widget_list_add(evas, 0, 0); - of = e_widget_framelist_add(evas, _("General Settings"), 0); - ob = e_widget_check_add(evas, _("Always Show Labels"), &(cfdata->show_label)); - e_widget_framelist_object_append(of, ob); - ob = e_widget_label_add(evas, _("Check Interval")); - e_widget_framelist_object_append(of, ob); - ob = e_widget_slider_add(evas, 1, 0, _("%2.0f minutes"), 1.0, 60.0, 1.0, 0, &(cfdata->check_time), NULL, 100); - e_widget_framelist_object_append(of, ob); - e_widget_list_object_append(o, of, 1, 1, 0.5); + o = e_widget_list_add (evas, 0, 0); + of = e_widget_framelist_add (evas, _("General Settings"), 0); + ob = + e_widget_check_add (evas, _("Always Show Labels"), &(cfdata->show_label)); + e_widget_framelist_object_append (of, ob); + ob = e_widget_label_add (evas, _("Check Interval")); + e_widget_framelist_object_append (of, ob); + ob = + e_widget_slider_add (evas, 1, 0, _("%2.0f minutes"), 1.0, 60.0, 1.0, 0, + &(cfdata->check_time), NULL, 100); + e_widget_framelist_object_append (of, ob); + e_widget_list_object_append (o, of, 1, 1, 0.5); - of = e_widget_frametable_add(evas, _("Mail Boxes"), 0); - ob = e_widget_ilist_add(evas, 32, 32, NULL); - e_widget_ilist_selector_set(ob, 1); - cfdata->il = ob; - _load_boxes(cfd); - e_widget_min_size_set(ob, 160, 140); - e_widget_frametable_object_append(of, ob, 0, 0, 1, 4, 1, 1, 1, 1); + of = e_widget_frametable_add (evas, _("Mail Boxes"), 0); + ob = e_widget_ilist_add (evas, 32, 32, NULL); + e_widget_ilist_selector_set (ob, 1); + cfdata->il = ob; + _load_boxes (cfd); + e_widget_min_size_set (ob, 160, 140); + e_widget_frametable_object_append (of, ob, 0, 0, 1, 4, 1, 1, 1, 1); - ot = e_widget_table_add(evas, 0); - ob = e_widget_button_add(evas, _("Add"), "widget/add", _cb_add_box, cfd, NULL); - e_widget_table_object_append(ot, ob, 0, 0, 1, 1, 1, 1, 1, 0); - ob = e_widget_button_add(evas, _("Delete"), "widget/del", _cb_del_box, cfd, NULL); - e_widget_disabled_set(ob, 1); - cfdata->del = ob; - e_widget_table_object_append(ot, ob, 0, 1, 1, 1, 1, 1, 1, 0); - ob = e_widget_button_add(evas, _("Configure..."), "widget/config", _cb_edit_box, cfd, NULL); - e_widget_disabled_set(ob, 1); - cfdata->configure = ob; - e_widget_table_object_append(ot, ob, 0, 2, 1, 1, 1, 1, 1, 0); - e_widget_frametable_object_append(of, ot, 1, 0, 1, 1, 1, 0, 1, 0); - - e_widget_list_object_append(o, of, 1, 1, 0.5); - - return o; + ot = e_widget_table_add (evas, 0); + ob = + e_widget_button_add (evas, _("Add"), "widget/add", _cb_add_box, cfd, + NULL); + e_widget_table_object_append (ot, ob, 0, 0, 1, 1, 1, 1, 1, 0); + ob = + e_widget_button_add (evas, _("Delete"), "widget/del", _cb_del_box, cfd, + NULL); + e_widget_disabled_set (ob, 1); + cfdata->del = ob; + e_widget_table_object_append (ot, ob, 0, 1, 1, 1, 1, 1, 1, 0); + ob = + e_widget_button_add (evas, _("Configure..."), "widget/config", + _cb_edit_box, cfd, NULL); + e_widget_disabled_set (ob, 1); + cfdata->configure = ob; + e_widget_table_object_append (ot, ob, 0, 2, 1, 1, 1, 1, 1, 0); + e_widget_frametable_object_append (of, ot, 1, 0, 1, 1, 1, 0, 1, 0); + + e_widget_list_object_append (o, of, 1, 1, 0.5); + + return o; } static int -_basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata) +_basic_apply_data (E_Config_Dialog * cfd, E_Config_Dialog_Data * cfdata) { - Config_Item *ci; - - ci = cfd->data; - ci->show_label = cfdata->show_label; - ci->check_time = cfdata->check_time; - e_config_save_queue(); - _mail_config_updated(ci->id); - return 1; + Config_Item *ci; + + ci = cfd->data; + ci->show_label = cfdata->show_label; + ci->check_time = cfdata->check_time; + e_config_save_queue (); + _mail_config_updated (ci->id); + return 1; } -static void -_load_boxes(E_Config_Dialog *cfd) +static void +_load_boxes (E_Config_Dialog * cfd) { - E_Config_Dialog_Data *cfdata; - Evas_Object *il; - Config_Item *ci; - int i; - char buf[4096]; - - cfdata = cfd->cfdata; - il = cfdata->il; - if (!il) return; - - ci = cfd->data; - if (!ci) return; - if (!ci->boxes) return; - if (evas_list_count(ci->boxes) <= 0) return; + E_Config_Dialog_Data *cfdata; + Evas_Object *il; + Config_Item *ci; + int i; + char buf[4096]; - snprintf(buf, sizeof(buf), "%s/module.eap", e_module_dir_get(mail_config->module)); - - e_widget_ilist_clear(il); + cfdata = cfd->cfdata; + il = cfdata->il; + if (!il) + return; - for (i = 0; i <= 3; i++) - { - Evas_List *box; - int found = -1; - char *name; - - switch (i) - { - case MAIL_TYPE_POP: - name = "Pop3"; - break; - case MAIL_TYPE_IMAP: - name = "Imap"; - break; - case MAIL_TYPE_MDIR: - name = "Maildir"; - break; - case MAIL_TYPE_MBOX: - name = "Mailbox"; - break; - } - found = _ilist_header_exists(il, name); - if (found <= 0) - e_widget_ilist_header_append(il, NULL, name); - - for (box = ci->boxes; box; box = box->next) - { - Config_Box *cb; - Evas_Object *ic; - - cb = box->data; - if (cb->type != i) continue; - if (!cb->name) continue; - ic = edje_object_add(cfd->dia->win->evas); - edje_object_file_set(ic, buf, "icon"); - e_widget_ilist_append(il, ic, cb->name, _ilist_cb_selected, cfd, NULL); - } - } - e_widget_ilist_go(il); + ci = cfd->data; + if (!ci) + return; + if (!ci->boxes) + return; + if (evas_list_count (ci->boxes) <= 0) + return; + + snprintf (buf, sizeof (buf), "%s/module.eap", + e_module_dir_get (mail_config->module)); + + e_widget_ilist_clear (il); + + for (i = 0; i <= 3; i++) + { + Evas_List *box; + int found = -1; + char *name; + + switch (i) + { + case MAIL_TYPE_POP: + name = "Pop3"; + break; + case MAIL_TYPE_IMAP: + name = "Imap"; + break; + case MAIL_TYPE_MDIR: + name = "Maildir"; + break; + case MAIL_TYPE_MBOX: + name = "Mailbox"; + break; + } + found = _ilist_header_exists (il, name); + if (found <= 0) + e_widget_ilist_header_append (il, NULL, name); + + for (box = ci->boxes; box; box = box->next) + { + Config_Box *cb; + Evas_Object *ic; + + cb = box->data; + if (cb->type != i) + continue; + if (!cb->name) + continue; + ic = edje_object_add (cfd->dia->win->evas); + edje_object_file_set (ic, buf, "icon"); + e_widget_ilist_append (il, ic, cb->name, _ilist_cb_selected, cfd, + NULL); + } + } + e_widget_ilist_go (il); } -static int -_ilist_header_exists(Evas_Object *il, const char *name) +static int +_ilist_header_exists (Evas_Object * il, const char *name) { - int c, i, found = 0; - - if (!il) return -1; + int c, i, found = 0; - c = e_widget_ilist_count(il); - if (c <= 0) return -1; + if (!il) + return -1; - for (i = 0; i < c; i++) - { - const char *n; - - n = e_widget_ilist_nth_label_get(il, i); - if (!n) continue; - if (!strcmp(n, name)) - { - found = 1; - break; - } - } - if (found) return i; - return -1; + c = e_widget_ilist_count (il); + if (c <= 0) + return -1; + + for (i = 0; i < c; i++) + { + const char *n; + + n = e_widget_ilist_nth_label_get (il, i); + if (!n) + continue; + if (!strcmp (n, name)) + { + found = 1; + break; + } + } + if (found) + return i; + return -1; } -static void -_ilist_cb_selected(void *data) +static void +_ilist_cb_selected (void *data) { - E_Config_Dialog *cfd; - E_Config_Dialog_Data *cfdata; - - cfd = data; - cfdata = cfd->cfdata; - - e_widget_disabled_set(cfdata->del, 0); - e_widget_disabled_set(cfdata->configure, 0); + E_Config_Dialog *cfd; + E_Config_Dialog_Data *cfdata; + + cfd = data; + cfdata = cfd->cfdata; + + e_widget_disabled_set (cfdata->del, 0); + e_widget_disabled_set (cfdata->configure, 0); } -static void -_cb_add_box(void *data, void *data2) +static void +_cb_add_box (void *data, void *data2) { - E_Config_Dialog *cfd; - E_Config_Dialog_Data *cfdata; - Config_Item *ci; - - cfd = data; - if (!cfd) return; + E_Config_Dialog *cfd; + E_Config_Dialog_Data *cfdata; + Config_Item *ci; - ci = cfd->data; - cfdata = cfd->cfdata; + cfd = data; + if (!cfd) + return; - _config_box(ci, NULL, cfd); + ci = cfd->data; + cfdata = cfd->cfdata; + + _config_box (ci, NULL, cfd); } -static void -_cb_edit_box(void *data, void *data2) +static void +_cb_edit_box (void *data, void *data2) { - E_Config_Dialog *cfd; - E_Config_Dialog_Data *cfdata; - Evas_Object *il; - Evas_List *l; - Config_Item *ci; - const char *s; - - cfd = data; - if (!cfd) return; + E_Config_Dialog *cfd; + E_Config_Dialog_Data *cfdata; + Evas_Object *il; + Evas_List *l; + Config_Item *ci; + const char *s; - ci = cfd->data; - cfdata = cfd->cfdata; - il = cfdata->il; - s = e_widget_ilist_selected_label_get(il); + cfd = data; + if (!cfd) + return; - if (!s) return; - - for (l = ci->boxes; l; l = l->next) - { - Config_Box *cb; - - cb = l->data; - if (!cb->name) continue; - if (!strcmp(s, cb->name)) - { - _config_box(ci, cb, cfd); - break; - } - } + ci = cfd->data; + cfdata = cfd->cfdata; + il = cfdata->il; + s = e_widget_ilist_selected_label_get (il); + + if (!s) + return; + + for (l = ci->boxes; l; l = l->next) + { + Config_Box *cb; + + cb = l->data; + if (!cb->name) + continue; + if (!strcmp (s, cb->name)) + { + _config_box (ci, cb, cfd); + break; + } + } } -static void -_cb_del_box(void *data, void *data2) +static void +_cb_del_box (void *data, void *data2) { - E_Config_Dialog *cfd; - E_Config_Dialog_Data *cfdata; - Evas_Object *il; - Evas_List *l; - Config_Item *ci; - const char *s; - - cfd = data; - if (!cfd) return; + E_Config_Dialog *cfd; + E_Config_Dialog_Data *cfdata; + Evas_Object *il; + Evas_List *l; + Config_Item *ci; + const char *s; - ci = cfd->data; - cfdata = cfd->cfdata; - il = cfdata->il; - s = e_widget_ilist_selected_label_get(il); - - for (l = ci->boxes; l; l = l->next) - { - Config_Box *cb; - - cb = l->data; - if (!cb->name) continue; - if (!strcmp(s, cb->name)) - { - _mail_box_deleted(ci->id, cb->name); - break; - } - } - _load_boxes(cfd); + cfd = data; + if (!cfd) + return; + + ci = cfd->data; + cfdata = cfd->cfdata; + il = cfdata->il; + s = e_widget_ilist_selected_label_get (il); + + for (l = ci->boxes; l; l = l->next) + { + Config_Box *cb; + + cb = l->data; + if (!cb->name) + continue; + if (!strcmp (s, cb->name)) + { + _mail_box_deleted (ci->id, cb->name); + break; + } + } + _load_boxes (cfd); } -void -_mail_box_config_updated(E_Config_Dialog *cfd) +void +_mail_box_config_updated (E_Config_Dialog * cfd) { - _load_boxes(cfd); - return; + _load_boxes (cfd); + return; } diff --git a/e_mod_config_box.c b/e_mod_config_box.c index 392ce82..4f57567 100644 --- a/e_mod_config_box.c +++ b/e_mod_config_box.c @@ -1,369 +1,388 @@ #include #include "e_mod_main.h" -struct _E_Config_Dialog_Data +struct _E_Config_Dialog_Data { - char *name; - int type; - int use_exec; - char *port; - int ssl; - char *host; - char *user; - char *pass; - char *new_path; - char *cur_path; - char *exec; - - /* Evas_Object References */ - Evas_Object *exec_label; - Evas_Object *exec_entry; - Evas_Object *port_entry; - Evas_Object *new_path_label; - Evas_Object *new_path_entry; - Evas_Object *cur_path_label; - Evas_Object *cur_path_entry; + char *name; + int type; + int use_exec; + char *port; + int ssl; + char *host; + char *user; + char *pass; + char *new_path; + char *cur_path; + char *exec; + + /* Evas_Object References */ + Evas_Object *exec_label; + Evas_Object *exec_entry; + Evas_Object *port_entry; + Evas_Object *new_path_label; + Evas_Object *new_path_entry; + Evas_Object *cur_path_label; + Evas_Object *cur_path_entry; }; -static void *_create_data(E_Config_Dialog *cfd); -static void _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata); -static Evas_Object *_basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata); -static int _basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata); -static void _type_cb_change(void *data, Evas_Object *obj); -static void _use_exec_cb_change(void *data, Evas_Object *obj); +static void *_create_data (E_Config_Dialog * cfd); +static void _free_data (E_Config_Dialog * cfd, E_Config_Dialog_Data * cfdata); +static Evas_Object *_basic_create_widgets (E_Config_Dialog * cfd, Evas * evas, + E_Config_Dialog_Data * cfdata); +static int _basic_apply_data (E_Config_Dialog * cfd, + E_Config_Dialog_Data * cfdata); +static void _type_cb_change (void *data, Evas_Object * obj); +static void _use_exec_cb_change (void *data, Evas_Object * obj); static E_Config_Dialog *prev_dlg; static Config_Item *mail_ci; -void -_config_box(Config_Item *ci, Config_Box *cb, E_Config_Dialog *mcfd) +void +_config_box (Config_Item * ci, Config_Box * cb, E_Config_Dialog * mcfd) { - E_Config_Dialog *cfd; - E_Config_Dialog_View *v; - E_Container *con; - - v = E_NEW(E_Config_Dialog_View, 1); - if (!v) return; + E_Config_Dialog *cfd; + E_Config_Dialog_View *v; + E_Container *con; - prev_dlg = mcfd; - mail_ci = ci; - - v->create_cfdata = _create_data; - v->free_cfdata = _free_data; - v->basic.apply_cfdata = _basic_apply_data; - v->basic.create_widgets = _basic_create_widgets; - - con = e_container_current_get(e_manager_current_get()); - cfd = e_config_dialog_new(con, _("Mailbox Configuration"), NULL, 0, v, cb); -} + v = E_NEW (E_Config_Dialog_View, 1); + if (!v) + return; -static void -_fill_data(Config_Box *cb, E_Config_Dialog_Data *cfdata) -{ - char buf[1024]; + prev_dlg = mcfd; + mail_ci = ci; - if (!cb) - { - cfdata->type = 0; - cfdata->ssl = 0; - cfdata->use_exec = 0; - snprintf(buf, sizeof(buf), "110"); - cfdata->port = strdup(buf); - return; - } - - if (cb->name) - cfdata->name = strdup(cb->name); + v->create_cfdata = _create_data; + v->free_cfdata = _free_data; + v->basic.apply_cfdata = _basic_apply_data; + v->basic.create_widgets = _basic_create_widgets; - cfdata->type = cb->type; - cfdata->ssl = cb->ssl; - cfdata->use_exec = cb->use_exec; - - snprintf(buf, sizeof(buf), "%d", cb->port); - cfdata->port = strdup(buf); - - if (cb->exec) - cfdata->exec = strdup(cb->exec); - if (cb->host) - cfdata->host = strdup(cb->host); - if (cb->user) - cfdata->user = strdup(cb->user); - if (cb->pass) - cfdata->pass = strdup(cb->pass); - - if (cb->new_path) - cfdata->new_path = strdup(cb->new_path); - if (cb->cur_path) - cfdata->cur_path = strdup(cb->cur_path); -} - -static void * -_create_data(E_Config_Dialog *cfd) -{ - E_Config_Dialog_Data *cfdata; - Config_Box *cb; - - cb = cfd->data; - cfdata = E_NEW(E_Config_Dialog_Data, 1); - _fill_data(cb, cfdata); - return cfdata; + con = e_container_current_get (e_manager_current_get ()); + cfd = e_config_dialog_new (con, _("Mailbox Configuration"), NULL, 0, v, cb); } static void -_free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata) +_fill_data (Config_Box * cb, E_Config_Dialog_Data * cfdata) { - E_FREE(cfdata->name); - E_FREE(cfdata->port); - E_FREE(cfdata->host); - E_FREE(cfdata->user); - E_FREE(cfdata->pass); - E_FREE(cfdata->new_path); - E_FREE(cfdata->cur_path); - E_FREE(cfdata->exec); + char buf[1024]; - free(cfdata); + if (!cb) + { + cfdata->type = 0; + cfdata->ssl = 0; + cfdata->use_exec = 0; + snprintf (buf, sizeof (buf), "110"); + cfdata->port = strdup (buf); + return; + } + + if (cb->name) + cfdata->name = strdup (cb->name); + + cfdata->type = cb->type; + cfdata->ssl = cb->ssl; + cfdata->use_exec = cb->use_exec; + + snprintf (buf, sizeof (buf), "%d", cb->port); + cfdata->port = strdup (buf); + + if (cb->exec) + cfdata->exec = strdup (cb->exec); + if (cb->host) + cfdata->host = strdup (cb->host); + if (cb->user) + cfdata->user = strdup (cb->user); + if (cb->pass) + cfdata->pass = strdup (cb->pass); + + if (cb->new_path) + cfdata->new_path = strdup (cb->new_path); + if (cb->cur_path) + cfdata->cur_path = strdup (cb->cur_path); +} + +static void * +_create_data (E_Config_Dialog * cfd) +{ + E_Config_Dialog_Data *cfdata; + Config_Box *cb; + + cb = cfd->data; + cfdata = E_NEW (E_Config_Dialog_Data, 1); + _fill_data (cb, cfdata); + return cfdata; +} + +static void +_free_data (E_Config_Dialog * cfd, E_Config_Dialog_Data * cfdata) +{ + E_FREE (cfdata->name); + E_FREE (cfdata->port); + E_FREE (cfdata->host); + E_FREE (cfdata->user); + E_FREE (cfdata->pass); + E_FREE (cfdata->new_path); + E_FREE (cfdata->cur_path); + E_FREE (cfdata->exec); + + free (cfdata); } static Evas_Object * -_basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata) +_basic_create_widgets (E_Config_Dialog * cfd, Evas * evas, + E_Config_Dialog_Data * cfdata) { - Evas_Object *o, *of, *ob, *ot; - E_Radio_Group *rg; - - o = e_widget_list_add(evas, 0, 0); - of = e_widget_framelist_add(evas, _("General Settings"), 0); - ob = e_widget_check_add(evas, _("Start Program When New Mail Arrives"), &(cfdata->use_exec)); - e_widget_framelist_object_append(of, ob); - e_widget_on_change_hook_set(ob, _use_exec_cb_change, cfdata); - ot = e_widget_table_add(evas, 1); - cfdata->exec_label = e_widget_label_add(evas, _("Program:")); - e_widget_table_object_append(ot, cfdata->exec_label, 0, 0, 1, 1, 0, 0, 1, 0); - cfdata->exec_entry = e_widget_entry_add(evas, &cfdata->exec); - e_widget_table_object_append(ot, cfdata->exec_entry, 1, 0, 1, 1, 0, 0, 1, 0); - e_widget_framelist_object_append(of, ot); - e_widget_list_object_append(o, of, 1, 1, 0.5); + Evas_Object *o, *of, *ob, *ot; + E_Radio_Group *rg; - e_widget_disabled_set(cfdata->exec_label, !cfdata->use_exec); - e_widget_disabled_set(cfdata->exec_entry, !cfdata->use_exec); + o = e_widget_list_add (evas, 0, 0); + of = e_widget_framelist_add (evas, _("General Settings"), 0); + ob = + e_widget_check_add (evas, _("Start Program When New Mail Arrives"), + &(cfdata->use_exec)); + e_widget_framelist_object_append (of, ob); + e_widget_on_change_hook_set (ob, _use_exec_cb_change, cfdata); + ot = e_widget_table_add (evas, 1); + cfdata->exec_label = e_widget_label_add (evas, _("Program:")); + e_widget_table_object_append (ot, cfdata->exec_label, 0, 0, 1, 1, 0, 0, 1, + 0); + cfdata->exec_entry = e_widget_entry_add (evas, &cfdata->exec); + e_widget_table_object_append (ot, cfdata->exec_entry, 1, 0, 1, 1, 0, 0, 1, + 0); + e_widget_framelist_object_append (of, ot); + e_widget_list_object_append (o, of, 1, 1, 0.5); - of = e_widget_framelist_add(evas, _("Mailbox Type"), 0); - rg = e_widget_radio_group_new(&(cfdata->type)); - ob = e_widget_radio_add(evas, _("Pop3"), 0, rg); - e_widget_on_change_hook_set(ob, _type_cb_change, cfdata); - e_widget_framelist_object_append(of, ob); - ob = e_widget_radio_add(evas, _("Imap"), 1, rg); - e_widget_on_change_hook_set(ob, _type_cb_change, cfdata); - e_widget_framelist_object_append(of, ob); - ob = e_widget_radio_add(evas, _("Maildir"), 2, rg); - e_widget_on_change_hook_set(ob, _type_cb_change, cfdata); - e_widget_framelist_object_append(of, ob); - ob = e_widget_radio_add(evas, _("Mbox"), 3, rg); - e_widget_on_change_hook_set(ob, _type_cb_change, cfdata); - e_widget_framelist_object_append(of, ob); - e_widget_list_object_append(o, of, 1, 1, 0.5); + e_widget_disabled_set (cfdata->exec_label, !cfdata->use_exec); + e_widget_disabled_set (cfdata->exec_entry, !cfdata->use_exec); - of = e_widget_frametable_add(evas, _("Port Settings"), 1); + of = e_widget_framelist_add (evas, _("Mailbox Type"), 0); + rg = e_widget_radio_group_new (&(cfdata->type)); + ob = e_widget_radio_add (evas, _("Pop3"), 0, rg); + e_widget_on_change_hook_set (ob, _type_cb_change, cfdata); + e_widget_framelist_object_append (of, ob); + ob = e_widget_radio_add (evas, _("Imap"), 1, rg); + e_widget_on_change_hook_set (ob, _type_cb_change, cfdata); + e_widget_framelist_object_append (of, ob); + ob = e_widget_radio_add (evas, _("Maildir"), 2, rg); + e_widget_on_change_hook_set (ob, _type_cb_change, cfdata); + e_widget_framelist_object_append (of, ob); + ob = e_widget_radio_add (evas, _("Mbox"), 3, rg); + e_widget_on_change_hook_set (ob, _type_cb_change, cfdata); + e_widget_framelist_object_append (of, ob); + e_widget_list_object_append (o, of, 1, 1, 0.5); - ob = e_widget_label_add(evas, _("Use SSL:")); - e_widget_frametable_object_append(of, ob, 0, 0, 1, 1, 0, 0, 1, 0); - ob = e_widget_check_add(evas, "", &(cfdata->ssl)); - e_widget_on_change_hook_set(ob, _type_cb_change, cfdata); - e_widget_frametable_object_append(of, ob, 1, 0, 1, 1, 0, 0, 1, 0); - - ob = e_widget_label_add(evas, _("Port:")); - e_widget_frametable_object_append(of, ob, 0, 1, 1, 1, 0, 0, 1, 0); - ob = e_widget_entry_add(evas, &cfdata->port); - cfdata->port_entry = ob; - e_widget_frametable_object_append(of, ob, 1, 1, 1, 1, 0, 0, 1, 0); - e_widget_list_object_append(o, of, 1, 1, 0.5); + of = e_widget_frametable_add (evas, _("Port Settings"), 1); - of = e_widget_frametable_add(evas, _("Mailbox Settings"), 1); - ob = e_widget_label_add(evas, _("Name:")); - e_widget_frametable_object_append(of, ob, 0, 0, 1, 1, 0, 0, 1, 0); - ob = e_widget_entry_add(evas, &cfdata->name); - e_widget_frametable_object_append(of, ob, 1, 0, 1, 1, 0, 0, 1, 0); + ob = e_widget_label_add (evas, _("Use SSL:")); + e_widget_frametable_object_append (of, ob, 0, 0, 1, 1, 0, 0, 1, 0); + ob = e_widget_check_add (evas, "", &(cfdata->ssl)); + e_widget_on_change_hook_set (ob, _type_cb_change, cfdata); + e_widget_frametable_object_append (of, ob, 1, 0, 1, 1, 0, 0, 1, 0); - ob = e_widget_label_add(evas, _("Mail Host:")); - e_widget_frametable_object_append(of, ob, 0, 1, 1, 1, 0, 0, 1, 0); - ob = e_widget_entry_add(evas, &cfdata->host); - e_widget_frametable_object_append(of, ob, 1, 1, 1, 1, 0, 0, 1, 0); + ob = e_widget_label_add (evas, _("Port:")); + e_widget_frametable_object_append (of, ob, 0, 1, 1, 1, 0, 0, 1, 0); + ob = e_widget_entry_add (evas, &cfdata->port); + cfdata->port_entry = ob; + e_widget_frametable_object_append (of, ob, 1, 1, 1, 1, 0, 0, 1, 0); + e_widget_list_object_append (o, of, 1, 1, 0.5); - ob = e_widget_label_add(evas, _("Username:")); - e_widget_frametable_object_append(of, ob, 0, 2, 1, 1, 0, 0, 1, 0); - ob = e_widget_entry_add(evas, &cfdata->user); - e_widget_frametable_object_append(of, ob, 1, 2, 1, 1, 0, 0, 1, 0); + of = e_widget_frametable_add (evas, _("Mailbox Settings"), 1); + ob = e_widget_label_add (evas, _("Name:")); + e_widget_frametable_object_append (of, ob, 0, 0, 1, 1, 0, 0, 1, 0); + ob = e_widget_entry_add (evas, &cfdata->name); + e_widget_frametable_object_append (of, ob, 1, 0, 1, 1, 0, 0, 1, 0); - ob = e_widget_label_add(evas, _("Password:")); - e_widget_frametable_object_append(of, ob, 0, 3, 1, 1, 0, 0, 1, 0); - ob = e_widget_entry_add(evas, &cfdata->pass); - e_widget_frametable_object_append(of, ob, 1, 3, 1, 1, 0, 0, 1, 0); + ob = e_widget_label_add (evas, _("Mail Host:")); + e_widget_frametable_object_append (of, ob, 0, 1, 1, 1, 0, 0, 1, 0); + ob = e_widget_entry_add (evas, &cfdata->host); + e_widget_frametable_object_append (of, ob, 1, 1, 1, 1, 0, 0, 1, 0); - cfdata->new_path_label = e_widget_label_add(evas, _("New Mail Path:")); - e_widget_frametable_object_append(of, cfdata->new_path_label, 0, 4, 1, 1, 0, 0, 1, 0); - cfdata->new_path_entry = e_widget_entry_add(evas, &cfdata->new_path); - e_widget_frametable_object_append(of, cfdata->new_path_entry, 1, 4, 1, 1, 0, 0, 1, 0); - if (cfdata->type == 0) - { - e_widget_disabled_set(cfdata->new_path_label, 1); - e_widget_disabled_set(cfdata->new_path_entry, 1); - } + ob = e_widget_label_add (evas, _("Username:")); + e_widget_frametable_object_append (of, ob, 0, 2, 1, 1, 0, 0, 1, 0); + ob = e_widget_entry_add (evas, &cfdata->user); + e_widget_frametable_object_append (of, ob, 1, 2, 1, 1, 0, 0, 1, 0); - cfdata->cur_path_label = e_widget_label_add(evas, _("Current Mail Path:")); - e_widget_frametable_object_append(of, cfdata->cur_path_label, 0, 5, 1, 1, 0, 0, 1, 0); - cfdata->cur_path_entry = e_widget_entry_add(evas, &cfdata->cur_path); - e_widget_frametable_object_append(of, cfdata->cur_path_entry, 1, 5, 1, 1, 0, 0, 1, 0); - if ((cfdata->type == 1) || (cfdata->type == 3)) - { - e_widget_disabled_set(cfdata->cur_path_label, 1); - e_widget_disabled_set(cfdata->cur_path_entry, 1); - } - - e_widget_list_object_append(o, of, 1, 1, 0.5); - return o; + ob = e_widget_label_add (evas, _("Password:")); + e_widget_frametable_object_append (of, ob, 0, 3, 1, 1, 0, 0, 1, 0); + ob = e_widget_entry_add (evas, &cfdata->pass); + e_widget_frametable_object_append (of, ob, 1, 3, 1, 1, 0, 0, 1, 0); + + cfdata->new_path_label = e_widget_label_add (evas, _("New Mail Path:")); + e_widget_frametable_object_append (of, cfdata->new_path_label, 0, 4, 1, 1, + 0, 0, 1, 0); + cfdata->new_path_entry = e_widget_entry_add (evas, &cfdata->new_path); + e_widget_frametable_object_append (of, cfdata->new_path_entry, 1, 4, 1, 1, + 0, 0, 1, 0); + if (cfdata->type == 0) + { + e_widget_disabled_set (cfdata->new_path_label, 1); + e_widget_disabled_set (cfdata->new_path_entry, 1); + } + + cfdata->cur_path_label = e_widget_label_add (evas, _("Current Mail Path:")); + e_widget_frametable_object_append (of, cfdata->cur_path_label, 0, 5, 1, 1, + 0, 0, 1, 0); + cfdata->cur_path_entry = e_widget_entry_add (evas, &cfdata->cur_path); + e_widget_frametable_object_append (of, cfdata->cur_path_entry, 1, 5, 1, 1, + 0, 0, 1, 0); + if ((cfdata->type == 1) || (cfdata->type == 3)) + { + e_widget_disabled_set (cfdata->cur_path_label, 1); + e_widget_disabled_set (cfdata->cur_path_entry, 1); + } + + e_widget_list_object_append (o, of, 1, 1, 0.5); + return o; } static int -_basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata) +_basic_apply_data (E_Config_Dialog * cfd, E_Config_Dialog_Data * cfdata) { - Config_Box *cb; - int is_new = 0; + Config_Box *cb; + int is_new = 0; - if (cfdata->name == NULL) - return 0; - - cb = cfd->data; - if (!cb) - { - cb = E_NEW(Config_Box, 1); - cb->type = 0; - cb->port = 110; - cb->ssl = 0; - is_new = 1; - } - - if (cb->name) evas_stringshare_del(cb->name); - if (cfdata->name != NULL) - cb->name = evas_stringshare_add(cfdata->name); - else - cb->name = evas_stringshare_add(""); - - cb->type = cfdata->type; - cb->port = atoi(cfdata->port); - cb->ssl = cfdata->ssl; - cb->use_exec = cfdata->use_exec; - if (cb->exec) evas_stringshare_del(cb->exec); - if (cfdata->exec != NULL) - cb->exec = evas_stringshare_add(cfdata->exec); - else - cb->exec = evas_stringshare_add(""); + if (cfdata->name == NULL) + return 0; - if (cb->host) evas_stringshare_del(cb->host); - if (cfdata->host != NULL) - cb->host = evas_stringshare_add(cfdata->host); - else - cb->host = evas_stringshare_add(""); - - if (cb->user) evas_stringshare_del(cb->user); - if (cfdata->user != NULL) - cb->user = evas_stringshare_add(cfdata->user); - else - cb->user = evas_stringshare_add(""); + cb = cfd->data; + if (!cb) + { + cb = E_NEW (Config_Box, 1); + cb->type = 0; + cb->port = 110; + cb->ssl = 0; + is_new = 1; + } - if (cb->pass) evas_stringshare_del(cb->pass); - if (cfdata->pass != NULL) - cb->pass = evas_stringshare_add(cfdata->pass); - else - cb->pass = evas_stringshare_add(""); - - if (cb->new_path) evas_stringshare_del(cb->new_path); - if (cfdata->new_path != NULL) - cb->new_path = evas_stringshare_add(cfdata->new_path); - else - cb->new_path = evas_stringshare_add(""); + if (cb->name) + evas_stringshare_del (cb->name); + if (cfdata->name != NULL) + cb->name = evas_stringshare_add (cfdata->name); + else + cb->name = evas_stringshare_add (""); - if (cb->cur_path) evas_stringshare_del(cb->cur_path); - if (cfdata->cur_path != NULL) - cb->cur_path = evas_stringshare_add(cfdata->cur_path); - else - cb->cur_path = evas_stringshare_add(""); + cb->type = cfdata->type; + cb->port = atoi (cfdata->port); + cb->ssl = cfdata->ssl; + cb->use_exec = cfdata->use_exec; + if (cb->exec) + evas_stringshare_del (cb->exec); + if (cfdata->exec != NULL) + cb->exec = evas_stringshare_add (cfdata->exec); + else + cb->exec = evas_stringshare_add (""); - if (!is_new) - e_config_save_queue(); + if (cb->host) + evas_stringshare_del (cb->host); + if (cfdata->host != NULL) + cb->host = evas_stringshare_add (cfdata->host); + else + cb->host = evas_stringshare_add (""); - if (is_new) - { -// cfd->data = cb; - mail_ci->boxes = evas_list_append(mail_ci->boxes, cb); - e_config_save_queue(); - _mail_box_added(mail_ci->id, cb->name); - } - - _mail_box_config_updated(prev_dlg); - return 1; + if (cb->user) + evas_stringshare_del (cb->user); + if (cfdata->user != NULL) + cb->user = evas_stringshare_add (cfdata->user); + else + cb->user = evas_stringshare_add (""); + + if (cb->pass) + evas_stringshare_del (cb->pass); + if (cfdata->pass != NULL) + cb->pass = evas_stringshare_add (cfdata->pass); + else + cb->pass = evas_stringshare_add (""); + + if (cb->new_path) + evas_stringshare_del (cb->new_path); + if (cfdata->new_path != NULL) + cb->new_path = evas_stringshare_add (cfdata->new_path); + else + cb->new_path = evas_stringshare_add (""); + + if (cb->cur_path) + evas_stringshare_del (cb->cur_path); + if (cfdata->cur_path != NULL) + cb->cur_path = evas_stringshare_add (cfdata->cur_path); + else + cb->cur_path = evas_stringshare_add (""); + + if (!is_new) + e_config_save_queue (); + + if (is_new) + { +// cfd->data = cb; + mail_ci->boxes = evas_list_append (mail_ci->boxes, cb); + e_config_save_queue (); + _mail_box_added (mail_ci->id, cb->name); + } + + _mail_box_config_updated (prev_dlg); + return 1; } -static void -_type_cb_change(void *data, Evas_Object *obj) +static void +_type_cb_change (void *data, Evas_Object * obj) { - E_Config_Dialog_Data *cfdata; - - cfdata = data; - if (cfdata->type == 0) - { - e_widget_disabled_set(cfdata->new_path_label, 1); - e_widget_disabled_set(cfdata->new_path_entry, 1); - e_widget_disabled_set(cfdata->cur_path_label, 1); - e_widget_disabled_set(cfdata->cur_path_entry, 1); - e_widget_entry_text_set(cfdata->new_path_entry, ""); - e_widget_entry_text_set(cfdata->cur_path_entry, ""); - if (cfdata->ssl) - { - e_widget_entry_text_set(cfdata->port_entry, "995"); - cfdata->port = strdup("995"); - } - else - { - e_widget_entry_text_set(cfdata->port_entry, "110"); - cfdata->port = strdup("110"); - } - } - else if ((cfdata->type == 1) || (cfdata->type == 3)) - { - e_widget_disabled_set(cfdata->new_path_label, 0); - e_widget_disabled_set(cfdata->new_path_entry, 0); - e_widget_disabled_set(cfdata->cur_path_label, 1); - e_widget_disabled_set(cfdata->cur_path_entry, 1); - e_widget_entry_text_set(cfdata->cur_path_entry, ""); - e_widget_entry_text_set(cfdata->new_path_entry, _("Inbox")); - if (cfdata->ssl) - { - e_widget_entry_text_set(cfdata->port_entry, "993"); - cfdata->port = strdup("993"); - } - else - { - e_widget_entry_text_set(cfdata->port_entry, "143"); - cfdata->port = strdup("143"); - } - } - else if (cfdata->type == 2) - { - e_widget_disabled_set(cfdata->new_path_label, 0); - e_widget_disabled_set(cfdata->new_path_entry, 0); - e_widget_disabled_set(cfdata->cur_path_label, 0); - e_widget_disabled_set(cfdata->cur_path_entry, 0); - e_widget_entry_text_set(cfdata->port_entry, ""); - } + E_Config_Dialog_Data *cfdata; + + cfdata = data; + if (cfdata->type == 0) + { + e_widget_disabled_set (cfdata->new_path_label, 1); + e_widget_disabled_set (cfdata->new_path_entry, 1); + e_widget_disabled_set (cfdata->cur_path_label, 1); + e_widget_disabled_set (cfdata->cur_path_entry, 1); + e_widget_entry_text_set (cfdata->new_path_entry, ""); + e_widget_entry_text_set (cfdata->cur_path_entry, ""); + if (cfdata->ssl) + { + e_widget_entry_text_set (cfdata->port_entry, "995"); + cfdata->port = strdup ("995"); + } + else + { + e_widget_entry_text_set (cfdata->port_entry, "110"); + cfdata->port = strdup ("110"); + } + } + else if ((cfdata->type == 1) || (cfdata->type == 3)) + { + e_widget_disabled_set (cfdata->new_path_label, 0); + e_widget_disabled_set (cfdata->new_path_entry, 0); + e_widget_disabled_set (cfdata->cur_path_label, 1); + e_widget_disabled_set (cfdata->cur_path_entry, 1); + e_widget_entry_text_set (cfdata->cur_path_entry, ""); + e_widget_entry_text_set (cfdata->new_path_entry, _("Inbox")); + if (cfdata->ssl) + { + e_widget_entry_text_set (cfdata->port_entry, "993"); + cfdata->port = strdup ("993"); + } + else + { + e_widget_entry_text_set (cfdata->port_entry, "143"); + cfdata->port = strdup ("143"); + } + } + else if (cfdata->type == 2) + { + e_widget_disabled_set (cfdata->new_path_label, 0); + e_widget_disabled_set (cfdata->new_path_entry, 0); + e_widget_disabled_set (cfdata->cur_path_label, 0); + e_widget_disabled_set (cfdata->cur_path_entry, 0); + e_widget_entry_text_set (cfdata->port_entry, ""); + } } -static void -_use_exec_cb_change(void *data, Evas_Object *obj) +static void +_use_exec_cb_change (void *data, Evas_Object * obj) { - E_Config_Dialog_Data *cfdata; - - cfdata = data; - e_widget_disabled_set(cfdata->exec_label, !cfdata->use_exec); - e_widget_disabled_set(cfdata->exec_entry, !cfdata->use_exec); - if (!cfdata->use_exec) - e_widget_entry_text_set(cfdata->exec_entry, ""); + E_Config_Dialog_Data *cfdata; + + cfdata = data; + e_widget_disabled_set (cfdata->exec_label, !cfdata->use_exec); + e_widget_disabled_set (cfdata->exec_entry, !cfdata->use_exec); + if (!cfdata->use_exec) + e_widget_entry_text_set (cfdata->exec_entry, ""); } diff --git a/e_mod_main.c b/e_mod_main.c index c57c806..7d226de 100644 --- a/e_mod_main.c +++ b/e_mod_main.c @@ -25,24 +25,29 @@ #include "mbox.h" /* Func Protos for Gadcon */ -static E_Gadcon_Client *_gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style); -static void _gc_shutdown(E_Gadcon_Client *gcc); -static void _gc_orient(E_Gadcon_Client *gcc); -static char *_gc_label(void); -static Evas_Object *_gc_icon(Evas *evas); +static E_Gadcon_Client *_gc_init (E_Gadcon * gc, const char *name, + const char *id, const char *style); +static void _gc_shutdown (E_Gadcon_Client * gcc); +static void _gc_orient (E_Gadcon_Client * gcc); +static char *_gc_label (void); +static Evas_Object *_gc_icon (Evas * evas); /* Func Protos for Module */ -static void _mail_cb_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info); -static void _mail_cb_mouse_in(void *data, Evas *e, Evas_Object *obj, void *event_info); -static void _mail_cb_mouse_out(void *data, Evas *e, Evas_Object *obj, void *event_info); -static void _mail_menu_cb_configure(void *data, E_Menu *m, E_Menu_Item *mi); -static void _mail_menu_cb_post(void *data, E_Menu *m); -static void _mail_menu_cb_exec(void *data, E_Menu *m, E_Menu_Item *mi); -static Config_Item *_mail_config_item_get(const char *id); -static Mail *_mail_new(Evas *evas); -static void _mail_free(Mail *mail); -static int _mail_cb_check(void *data); -static int _mail_cb_exe_exit(void *data, int type, void *event); +static void _mail_cb_mouse_down (void *data, Evas * e, Evas_Object * obj, + void *event_info); +static void _mail_cb_mouse_in (void *data, Evas * e, Evas_Object * obj, + void *event_info); +static void _mail_cb_mouse_out (void *data, Evas * e, Evas_Object * obj, + void *event_info); +static void _mail_menu_cb_configure (void *data, E_Menu * m, + E_Menu_Item * mi); +static void _mail_menu_cb_post (void *data, E_Menu * m); +static void _mail_menu_cb_exec (void *data, E_Menu * m, E_Menu_Item * mi); +static Config_Item *_mail_config_item_get (const char *id); +static Mail *_mail_new (Evas * evas); +static void _mail_free (Mail * mail); +static int _mail_cb_check (void *data); +static int _mail_cb_exe_exit (void *data, int type, void *event); static E_Config_DD *conf_edd = NULL; static E_Config_DD *conf_item_edd = NULL; @@ -52,680 +57,736 @@ Config *mail_config = NULL; static Ecore_Event_Handler *exit_handler; -static const E_Gadcon_Client_Class _gc_class = -{ - GADCON_CLIENT_CLASS_VERSION, - "mail", {_gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon} +static const E_Gadcon_Client_Class _gc_class = { + GADCON_CLIENT_CLASS_VERSION, + "mail", {_gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon} }; static E_Gadcon_Client * -_gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style) +_gc_init (E_Gadcon * gc, const char *name, const char *id, const char *style) { - E_Gadcon_Client *gcc; - Instance *inst; - Mail *mail; - Config_Item *ci; - Evas_List *l, *j; - int have_pop = 0, have_imap = 0; - - inst = E_NEW(Instance, 1); - ci = _mail_config_item_get(id); - if (!ci->id) ci->id = evas_stringshare_add(id); - - mail = _mail_new(gc->evas); - mail->inst = inst; - inst->mail = mail; - - gcc = e_gadcon_client_new(gc, name, id, style, mail->mail_obj); - gcc->data = inst; - inst->gcc = gcc; - inst->mail_obj = mail->mail_obj; + E_Gadcon_Client *gcc; + Instance *inst; + Mail *mail; + Config_Item *ci; + Evas_List *l, *j; + int have_pop = 0, have_imap = 0; - evas_object_event_callback_add(inst->mail_obj, EVAS_CALLBACK_MOUSE_DOWN, _mail_cb_mouse_down, inst); - evas_object_event_callback_add(inst->mail_obj, EVAS_CALLBACK_MOUSE_IN, _mail_cb_mouse_in, inst); - evas_object_event_callback_add(inst->mail_obj, EVAS_CALLBACK_MOUSE_OUT, _mail_cb_mouse_out, inst); + inst = E_NEW (Instance, 1); + ci = _mail_config_item_get (id); + if (!ci->id) + ci->id = evas_stringshare_add (id); - if (ci->show_label) - edje_object_signal_emit(inst->mail_obj, "label_active", ""); - else - edje_object_signal_emit(inst->mail_obj, "label_passive", ""); + mail = _mail_new (gc->evas); + mail->inst = inst; + inst->mail = mail; - mail_config->instances = evas_list_append(mail_config->instances, inst); - for (l = mail_config->items; l; l = l->next) - { - Config_Item *ci; - - ci = l->data; - for (j = ci->boxes; j; j = j->next) - { - Config_Box *cb; - - cb = j->data; - switch (cb->type) - { - case MAIL_TYPE_IMAP: - have_imap = 1; - _mail_imap_add_mailbox(cb); - if (!inst->check_timer) - inst->check_timer = ecore_timer_add((ci->check_time * 60.0), _mail_cb_check, inst); - break; - case MAIL_TYPE_POP: - have_pop = 1; - _mail_pop_add_mailbox(cb); - if (!inst->check_timer) - inst->check_timer = ecore_timer_add((ci->check_time * 60.0), _mail_cb_check, inst); - break; - case MAIL_TYPE_MDIR: - _mail_mdir_add_mailbox(inst, cb); - break; - case MAIL_TYPE_MBOX: - _mail_mbox_add_mailbox(inst, cb); - break; - } - } - if (have_pop) _mail_pop_check_mail(inst); - if (have_imap) _mail_imap_check_mail(inst); - } - return gcc; + gcc = e_gadcon_client_new (gc, name, id, style, mail->mail_obj); + gcc->data = inst; + inst->gcc = gcc; + inst->mail_obj = mail->mail_obj; + + evas_object_event_callback_add (inst->mail_obj, EVAS_CALLBACK_MOUSE_DOWN, + _mail_cb_mouse_down, inst); + evas_object_event_callback_add (inst->mail_obj, EVAS_CALLBACK_MOUSE_IN, + _mail_cb_mouse_in, inst); + evas_object_event_callback_add (inst->mail_obj, EVAS_CALLBACK_MOUSE_OUT, + _mail_cb_mouse_out, inst); + + if (ci->show_label) + edje_object_signal_emit (inst->mail_obj, "label_active", ""); + else + edje_object_signal_emit (inst->mail_obj, "label_passive", ""); + + mail_config->instances = evas_list_append (mail_config->instances, inst); + for (l = mail_config->items; l; l = l->next) + { + Config_Item *ci; + + ci = l->data; + for (j = ci->boxes; j; j = j->next) + { + Config_Box *cb; + + cb = j->data; + switch (cb->type) + { + case MAIL_TYPE_IMAP: + have_imap = 1; + _mail_imap_add_mailbox (cb); + if (!inst->check_timer) + inst->check_timer = + ecore_timer_add ((ci->check_time * 60.0), _mail_cb_check, + inst); + break; + case MAIL_TYPE_POP: + have_pop = 1; + _mail_pop_add_mailbox (cb); + if (!inst->check_timer) + inst->check_timer = + ecore_timer_add ((ci->check_time * 60.0), _mail_cb_check, + inst); + break; + case MAIL_TYPE_MDIR: + _mail_mdir_add_mailbox (inst, cb); + break; + case MAIL_TYPE_MBOX: + _mail_mbox_add_mailbox (inst, cb); + break; + } + } + if (have_pop) + _mail_pop_check_mail (inst); + if (have_imap) + _mail_imap_check_mail (inst); + } + return gcc; } static void -_gc_shutdown(E_Gadcon_Client *gcc) +_gc_shutdown (E_Gadcon_Client * gcc) { - Instance *inst; - - inst = gcc->data; - - evas_object_event_callback_del(inst->mail_obj, EVAS_CALLBACK_MOUSE_DOWN, _mail_cb_mouse_down); - evas_object_event_callback_del(inst->mail_obj, EVAS_CALLBACK_MOUSE_IN, _mail_cb_mouse_in); - evas_object_event_callback_del(inst->mail_obj, EVAS_CALLBACK_MOUSE_OUT, _mail_cb_mouse_out); - - mail_config->instances = evas_list_remove(mail_config->instances, inst); - _mail_free(inst->mail); - free(inst); - inst = NULL; + Instance *inst; + + inst = gcc->data; + + evas_object_event_callback_del (inst->mail_obj, EVAS_CALLBACK_MOUSE_DOWN, + _mail_cb_mouse_down); + evas_object_event_callback_del (inst->mail_obj, EVAS_CALLBACK_MOUSE_IN, + _mail_cb_mouse_in); + evas_object_event_callback_del (inst->mail_obj, EVAS_CALLBACK_MOUSE_OUT, + _mail_cb_mouse_out); + + mail_config->instances = evas_list_remove (mail_config->instances, inst); + _mail_free (inst->mail); + free (inst); + inst = NULL; } static void -_gc_orient(E_Gadcon_Client *gcc) +_gc_orient (E_Gadcon_Client * gcc) { - e_gadcon_client_aspect_set(gcc, 16, 16); - e_gadcon_client_min_size_set(gcc, 16, 16); + e_gadcon_client_aspect_set (gcc, 16, 16); + e_gadcon_client_min_size_set (gcc, 16, 16); } static char * -_gc_label(void) +_gc_label (void) { - return D_("Mail"); + return D_ ("Mail"); } static Evas_Object * -_gc_icon(Evas *evas) +_gc_icon (Evas * evas) { - Evas_Object *o; - char buf[4096]; - - o = edje_object_add(evas); - snprintf(buf, sizeof(buf), "%s/module.eap", e_module_dir_get(mail_config->module)); - edje_object_file_set(o, buf, "icon"); - return o; + Evas_Object *o; + char buf[4096]; + + o = edje_object_add (evas); + snprintf (buf, sizeof (buf), "%s/module.eap", + e_module_dir_get (mail_config->module)); + edje_object_file_set (o, buf, "icon"); + return o; } static void -_mail_cb_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info) +_mail_cb_mouse_down (void *data, Evas * e, Evas_Object * obj, + void *event_info) { - Instance *inst = data; - Config_Item *ci; - Evas_Event_Mouse_Down *ev = event_info; - Evas_List *l; - - if (!inst) return; - if ((ev->button == 3) && (!mail_config->menu)) - { - E_Menu *mn, *sn; - E_Menu_Item *mi; - int x, y, w, h; - char buf[1024]; - - mn = e_menu_new(); - e_menu_post_deactivate_callback_set(mn, _mail_menu_cb_post, inst); - mail_config->menu = mn; + Instance *inst = data; + Config_Item *ci; + Evas_Event_Mouse_Down *ev = event_info; + Evas_List *l; - ci = _mail_config_item_get(inst->gcc->id); - if ((ci->boxes) && (evas_list_count(ci->boxes) > 0)) - { - E_Menu_Item *mm; - - snprintf(buf, sizeof(buf), "%s/module.eap", e_module_dir_get(mail_config->module)); - mm = e_menu_item_new(mn); - e_menu_item_label_set(mm, _("Mailboxes")); - e_menu_item_icon_edje_set(mm, buf, "icon"); - - sn = e_menu_new(); - for (l = ci->boxes; l; l = l->next) - { - Config_Box *cb; - - cb = l->data; - if (!cb) continue; - mi = e_menu_item_new(sn); - snprintf(buf, sizeof(buf), "%s: %d/%d", cb->name, cb->num_new, cb->num_total); - e_menu_item_label_set(mi, buf); - if ((cb->exec) && (cb->use_exec)) - e_menu_item_callback_set(mi, _mail_menu_cb_exec, cb); - } - e_menu_item_submenu_set(mm, sn); - mi = e_menu_item_new(mn); - e_menu_item_separator_set(mi, 1); - } - - mi = e_menu_item_new(mn); - e_menu_item_label_set(mi, _("Configuration")); - e_util_menu_item_edje_icon_set(mi, "enlightenment/configuration"); - e_menu_item_callback_set(mi, _mail_menu_cb_configure, inst); - - mi = e_menu_item_new(mn); - e_menu_item_separator_set(mi, 1); - - e_gadcon_client_util_menu_items_append(inst->gcc, mn, 0); - e_gadcon_canvas_zone_geometry_get(inst->gcc->gadcon, &x, &y, &w, &h); - e_menu_activate_mouse(mn, - e_util_zone_current_get(e_manager_current_get()), - x + ev->output.x, y + ev->output.y, 1, 1, E_MENU_POP_DIRECTION_DOWN, - ev->timestamp); - evas_event_feed_mouse_up(inst->gcc->gadcon->evas, ev->button, EVAS_BUTTON_NONE, ev->timestamp, NULL); - } - else if (ev->button == 1) - _mail_cb_check(inst); -} + if (!inst) + return; + if ((ev->button == 3) && (!mail_config->menu)) + { + E_Menu *mn, *sn; + E_Menu_Item *mi; + int x, y, w, h; + char buf[1024]; -static void -_mail_cb_mouse_in(void *data, Evas *e, Evas_Object *obj, void *event_info) -{ - Instance *inst = data; - - if (!inst) return; - edje_object_signal_emit(inst->mail_obj, "label_active", ""); -} + mn = e_menu_new (); + e_menu_post_deactivate_callback_set (mn, _mail_menu_cb_post, inst); + mail_config->menu = mn; -static void -_mail_cb_mouse_out(void *data, Evas *e, Evas_Object *obj, void *event_info) -{ - Instance *inst = data; - Config_Item *ci; - - if (!inst) return; - ci = _mail_config_item_get(inst->gcc->id); - if (!ci->show_label) - edje_object_signal_emit(inst->mail_obj, "label_passive", ""); + ci = _mail_config_item_get (inst->gcc->id); + if ((ci->boxes) && (evas_list_count (ci->boxes) > 0)) + { + E_Menu_Item *mm; + + snprintf (buf, sizeof (buf), "%s/module.eap", + e_module_dir_get (mail_config->module)); + mm = e_menu_item_new (mn); + e_menu_item_label_set (mm, _("Mailboxes")); + e_menu_item_icon_edje_set (mm, buf, "icon"); + + sn = e_menu_new (); + for (l = ci->boxes; l; l = l->next) + { + Config_Box *cb; + + cb = l->data; + if (!cb) + continue; + mi = e_menu_item_new (sn); + snprintf (buf, sizeof (buf), "%s: %d/%d", cb->name, cb->num_new, + cb->num_total); + e_menu_item_label_set (mi, buf); + if ((cb->exec) && (cb->use_exec)) + e_menu_item_callback_set (mi, _mail_menu_cb_exec, cb); + } + e_menu_item_submenu_set (mm, sn); + mi = e_menu_item_new (mn); + e_menu_item_separator_set (mi, 1); + } + + mi = e_menu_item_new (mn); + e_menu_item_label_set (mi, _("Configuration")); + e_util_menu_item_edje_icon_set (mi, "enlightenment/configuration"); + e_menu_item_callback_set (mi, _mail_menu_cb_configure, inst); + + mi = e_menu_item_new (mn); + e_menu_item_separator_set (mi, 1); + + e_gadcon_client_util_menu_items_append (inst->gcc, mn, 0); + e_gadcon_canvas_zone_geometry_get (inst->gcc->gadcon, &x, &y, &w, &h); + e_menu_activate_mouse (mn, + e_util_zone_current_get (e_manager_current_get + ()), x + ev->output.x, + y + ev->output.y, 1, 1, + E_MENU_POP_DIRECTION_DOWN, ev->timestamp); + evas_event_feed_mouse_up (inst->gcc->gadcon->evas, ev->button, + EVAS_BUTTON_NONE, ev->timestamp, NULL); + } + else if (ev->button == 1) + _mail_cb_check (inst); } static void -_mail_menu_cb_post(void *data, E_Menu *m) +_mail_cb_mouse_in (void *data, Evas * e, Evas_Object * obj, void *event_info) { - if (!mail_config->menu) return; - e_object_del(E_OBJECT(mail_config->menu)); - mail_config->menu = NULL; + Instance *inst = data; + + if (!inst) + return; + edje_object_signal_emit (inst->mail_obj, "label_active", ""); } static void -_mail_menu_cb_configure(void *data, E_Menu *m, E_Menu_Item *mi) +_mail_cb_mouse_out (void *data, Evas * e, Evas_Object * obj, void *event_info) { - Instance *inst = data; - Config_Item *ci; - - if (!inst) return; - ci = _mail_config_item_get(inst->gcc->id); - _config_mail_module(ci); + Instance *inst = data; + Config_Item *ci; + + if (!inst) + return; + ci = _mail_config_item_get (inst->gcc->id); + if (!ci->show_label) + edje_object_signal_emit (inst->mail_obj, "label_passive", ""); +} + +static void +_mail_menu_cb_post (void *data, E_Menu * m) +{ + if (!mail_config->menu) + return; + e_object_del (E_OBJECT (mail_config->menu)); + mail_config->menu = NULL; +} + +static void +_mail_menu_cb_configure (void *data, E_Menu * m, E_Menu_Item * mi) +{ + Instance *inst = data; + Config_Item *ci; + + if (!inst) + return; + ci = _mail_config_item_get (inst->gcc->id); + _config_mail_module (ci); } static Config_Item * -_mail_config_item_get(const char *id) +_mail_config_item_get (const char *id) { - Evas_List *l; - Config_Item *ci; - - for (l = mail_config->items; l; l = l->next) - { - ci = l->data; - if (!ci->id) continue; - if (!strcmp(ci->id, id)) return ci; - } - - ci = E_NEW(Config_Item, 1); - ci->id = evas_stringshare_add(id); - ci->show_label = 1; - ci->check_time = 15.0; - ci->boxes = NULL; - - mail_config->items = evas_list_append(mail_config->items, ci); - return ci; + Evas_List *l; + Config_Item *ci; + + for (l = mail_config->items; l; l = l->next) + { + ci = l->data; + if (!ci->id) + continue; + if (!strcmp (ci->id, id)) + return ci; + } + + ci = E_NEW (Config_Item, 1); + ci->id = evas_stringshare_add (id); + ci->show_label = 1; + ci->check_time = 15.0; + ci->boxes = NULL; + + mail_config->items = evas_list_append (mail_config->items, ci); + return ci; } -EAPI E_Module_Api e_modapi = -{ - E_MODULE_API_VERSION, - "Mail" +EAPI E_Module_Api e_modapi = { + E_MODULE_API_VERSION, + "Mail" }; EAPI void * -e_modapi_init(E_Module *m) +e_modapi_init (E_Module * m) { - conf_box_edd = E_CONFIG_DD_NEW("Mail_Box_Config", Config_Box); - #undef T - #undef D - #define T Config_Box - #define D conf_box_edd - E_CONFIG_VAL(D, T, name, STR); - E_CONFIG_VAL(D, T, type, INT); - E_CONFIG_VAL(D, T, port, INT); - E_CONFIG_VAL(D, T, ssl, UCHAR); - E_CONFIG_VAL(D, T, host, STR); - E_CONFIG_VAL(D, T, user, STR); - E_CONFIG_VAL(D, T, pass, STR); - E_CONFIG_VAL(D, T, new_path, STR); - E_CONFIG_VAL(D, T, cur_path, STR); - E_CONFIG_VAL(D, T, use_exec, UCHAR); - E_CONFIG_VAL(D, T, exec, STR); - - conf_item_edd = E_CONFIG_DD_NEW("Mail_Config_Item", Config_Item); - #undef T - #undef D - #define T Config_Item - #define D conf_item_edd - E_CONFIG_VAL(D, T, id, STR); - E_CONFIG_VAL(D, T, show_label, UCHAR); - E_CONFIG_VAL(D, T, check_time, DOUBLE); - E_CONFIG_LIST(D, T, boxes, conf_box_edd); - - conf_edd = E_CONFIG_DD_NEW("Mail_Config", Config); - #undef T - #undef D - #define T Config - #define D conf_edd - E_CONFIG_LIST(D, T, items, conf_item_edd); - - mail_config = e_config_domain_load("module.mail", conf_edd); - if (!mail_config) - { - Config_Item *ci; - - mail_config = E_NEW(Config, 1); - ci = E_NEW(Config_Item, 1); - - ci->id = evas_stringshare_add("0"); - ci->show_label = 1; - ci->check_time = 15.0; - ci->boxes = NULL; - - mail_config->items = evas_list_append(mail_config->items, ci); - } - mail_config->module = m; - e_gadcon_provider_register(&_gc_class); - return m; + conf_box_edd = E_CONFIG_DD_NEW ("Mail_Box_Config", Config_Box); +#undef T +#undef D +#define T Config_Box +#define D conf_box_edd + E_CONFIG_VAL (D, T, name, STR); + E_CONFIG_VAL (D, T, type, INT); + E_CONFIG_VAL (D, T, port, INT); + E_CONFIG_VAL (D, T, ssl, UCHAR); + E_CONFIG_VAL (D, T, host, STR); + E_CONFIG_VAL (D, T, user, STR); + E_CONFIG_VAL (D, T, pass, STR); + E_CONFIG_VAL (D, T, new_path, STR); + E_CONFIG_VAL (D, T, cur_path, STR); + E_CONFIG_VAL (D, T, use_exec, UCHAR); + E_CONFIG_VAL (D, T, exec, STR); + + conf_item_edd = E_CONFIG_DD_NEW ("Mail_Config_Item", Config_Item); +#undef T +#undef D +#define T Config_Item +#define D conf_item_edd + E_CONFIG_VAL (D, T, id, STR); + E_CONFIG_VAL (D, T, show_label, UCHAR); + E_CONFIG_VAL (D, T, check_time, DOUBLE); + E_CONFIG_LIST (D, T, boxes, conf_box_edd); + + conf_edd = E_CONFIG_DD_NEW ("Mail_Config", Config); +#undef T +#undef D +#define T Config +#define D conf_edd + E_CONFIG_LIST (D, T, items, conf_item_edd); + + mail_config = e_config_domain_load ("module.mail", conf_edd); + if (!mail_config) + { + Config_Item *ci; + + mail_config = E_NEW (Config, 1); + ci = E_NEW (Config_Item, 1); + + ci->id = evas_stringshare_add ("0"); + ci->show_label = 1; + ci->check_time = 15.0; + ci->boxes = NULL; + + mail_config->items = evas_list_append (mail_config->items, ci); + } + mail_config->module = m; + e_gadcon_provider_register (&_gc_class); + return m; } EAPI int -e_modapi_shutdown(E_Module *m) +e_modapi_shutdown (E_Module * m) { - mail_config->module = NULL; - e_gadcon_provider_unregister(&_gc_class); + mail_config->module = NULL; + e_gadcon_provider_unregister (&_gc_class); - if (exit_handler) - ecore_event_handler_del(exit_handler); - - if (mail_config->config_dialog) - e_object_del(E_OBJECT(mail_config->config_dialog)); - if (mail_config->menu) - { - e_menu_post_deactivate_callback_set(mail_config->menu, NULL, NULL); - e_object_del(E_OBJECT(mail_config->menu)); - mail_config->menu = NULL; - } - while (mail_config->items) - { - Config_Item *ci; - - ci = mail_config->items->data; - while (ci->boxes) - { - Config_Box *cb; - - cb = ci->boxes->data; - switch (cb->type) - { - case MAIL_TYPE_IMAP: - _mail_imap_del_mailbox(cb); - break; - case MAIL_TYPE_POP: - _mail_pop_del_mailbox(cb); - break; - case MAIL_TYPE_MDIR: - _mail_mdir_del_mailbox(cb); - break; - case MAIL_TYPE_MBOX: - _mail_mbox_del_mailbox(cb); - break; - } - if (cb->name) evas_stringshare_del(cb->name); - if (cb->host) evas_stringshare_del(cb->host); - if (cb->user) evas_stringshare_del(cb->user); - if (cb->pass) evas_stringshare_del(cb->pass); - if (cb->new_path) evas_stringshare_del(cb->new_path); - if (cb->cur_path) evas_stringshare_del(cb->cur_path); - if (cb->exec) evas_stringshare_del(cb->exec); - ci->boxes = evas_list_remove_list(ci->boxes, ci->boxes); - free(cb); - cb = NULL; - } - if (ci->id) evas_stringshare_del(ci->id); - mail_config->items = evas_list_remove_list(mail_config->items, mail_config->items); - free(ci); - ci = NULL; - } - _mail_imap_shutdown(); - _mail_pop_shutdown(); - _mail_mdir_shutdown(); - _mail_mbox_shutdown(); - free(mail_config); - mail_config = NULL; - E_CONFIG_DD_FREE(conf_box_edd); - E_CONFIG_DD_FREE(conf_item_edd); - E_CONFIG_DD_FREE(conf_edd); - return 1; + if (exit_handler) + ecore_event_handler_del (exit_handler); + + if (mail_config->config_dialog) + e_object_del (E_OBJECT (mail_config->config_dialog)); + if (mail_config->menu) + { + e_menu_post_deactivate_callback_set (mail_config->menu, NULL, NULL); + e_object_del (E_OBJECT (mail_config->menu)); + mail_config->menu = NULL; + } + while (mail_config->items) + { + Config_Item *ci; + + ci = mail_config->items->data; + while (ci->boxes) + { + Config_Box *cb; + + cb = ci->boxes->data; + switch (cb->type) + { + case MAIL_TYPE_IMAP: + _mail_imap_del_mailbox (cb); + break; + case MAIL_TYPE_POP: + _mail_pop_del_mailbox (cb); + break; + case MAIL_TYPE_MDIR: + _mail_mdir_del_mailbox (cb); + break; + case MAIL_TYPE_MBOX: + _mail_mbox_del_mailbox (cb); + break; + } + if (cb->name) + evas_stringshare_del (cb->name); + if (cb->host) + evas_stringshare_del (cb->host); + if (cb->user) + evas_stringshare_del (cb->user); + if (cb->pass) + evas_stringshare_del (cb->pass); + if (cb->new_path) + evas_stringshare_del (cb->new_path); + if (cb->cur_path) + evas_stringshare_del (cb->cur_path); + if (cb->exec) + evas_stringshare_del (cb->exec); + ci->boxes = evas_list_remove_list (ci->boxes, ci->boxes); + free (cb); + cb = NULL; + } + if (ci->id) + evas_stringshare_del (ci->id); + mail_config->items = + evas_list_remove_list (mail_config->items, mail_config->items); + free (ci); + ci = NULL; + } + _mail_imap_shutdown (); + _mail_pop_shutdown (); + _mail_mdir_shutdown (); + _mail_mbox_shutdown (); + free (mail_config); + mail_config = NULL; + E_CONFIG_DD_FREE (conf_box_edd); + E_CONFIG_DD_FREE (conf_item_edd); + E_CONFIG_DD_FREE (conf_edd); + return 1; } EAPI int -e_modapi_save(E_Module *m) +e_modapi_save (E_Module * m) { - Evas_List *l; - - for (l = mail_config->instances; l; l = l->next) - { - Instance *inst; - Config_Item *ci; - - inst = l->data; - ci = _mail_config_item_get(inst->gcc->id); - if (ci->id) evas_stringshare_del(ci->id); - ci->id = evas_stringshare_add(inst->gcc->id); - } - e_config_domain_save("module.mail", conf_edd, mail_config); - return 1; + Evas_List *l; + + for (l = mail_config->instances; l; l = l->next) + { + Instance *inst; + Config_Item *ci; + + inst = l->data; + ci = _mail_config_item_get (inst->gcc->id); + if (ci->id) + evas_stringshare_del (ci->id); + ci->id = evas_stringshare_add (inst->gcc->id); + } + e_config_domain_save ("module.mail", conf_edd, mail_config); + return 1; } EAPI int -e_modapi_about(E_Module *m) +e_modapi_about (E_Module * m) { - e_module_dialog_show(m, D_("Enlightenment Mail Module"), - D_("This is a module to notify when you have new mail.")); - return 1; + e_module_dialog_show (m, D_ ("Enlightenment Mail Module"), + D_ + ("This is a module to notify when you have new mail.")); + return 1; } static Mail * -_mail_new(Evas *evas) +_mail_new (Evas * evas) { - Mail *mail; - char buf[4096]; + Mail *mail; + char buf[4096]; - mail = E_NEW(Mail, 1); - mail->mail_obj = edje_object_add(evas); + mail = E_NEW (Mail, 1); + mail->mail_obj = edje_object_add (evas); - snprintf(buf, sizeof(buf), "%s/mail.edj", e_module_dir_get(mail_config->module)); - if (!e_theme_edje_object_set(mail->mail_obj, "base/theme/modules/mail", "modules/mail/main")) - edje_object_file_set(mail->mail_obj, buf, "modules/mail/main"); - evas_object_show(mail->mail_obj); - - return mail; + snprintf (buf, sizeof (buf), "%s/mail.edj", + e_module_dir_get (mail_config->module)); + if (!e_theme_edje_object_set + (mail->mail_obj, "base/theme/modules/mail", "modules/mail/main")) + edje_object_file_set (mail->mail_obj, buf, "modules/mail/main"); + evas_object_show (mail->mail_obj); + + return mail; } static void -_mail_free(Mail *mail) +_mail_free (Mail * mail) { - evas_object_del(mail->mail_obj); - free(mail); - mail = NULL; + evas_object_del (mail->mail_obj); + free (mail); + mail = NULL; } -static int -_mail_cb_check(void *data) +static int +_mail_cb_check (void *data) { - Instance *inst = data; - Config_Item *ci; - Evas_List *l; - int have_imap = 0, have_pop = 0; - - if (!inst) return 1; - - ci = _mail_config_item_get(inst->gcc->id); - if (!ci->boxes) return 1; + Instance *inst = data; + Config_Item *ci; + Evas_List *l; + int have_imap = 0, have_pop = 0; - edje_object_signal_emit(inst->mail->mail_obj, "check_mail", ""); - - for (l = ci->boxes; l; l = l->next) - { - Config_Box *cb; - - cb = l->data; - if (!cb) continue; - switch (cb->type) - { - case MAIL_TYPE_MDIR: - break; - case MAIL_TYPE_MBOX: - break; - case MAIL_TYPE_POP: - have_pop = 1; - break; - case MAIL_TYPE_IMAP: - have_imap = 1; - break; - } - } - if (have_imap) _mail_imap_check_mail(inst); - if (have_pop) _mail_pop_check_mail(inst); - return 1; -} + if (!inst) + return 1; -void -_mail_set_text(void *data) -{ - Instance *inst = data; - Config_Item *ci; - Evas_List *l; - char buf[1024]; - int count = 0; - - if (!inst) return; + ci = _mail_config_item_get (inst->gcc->id); + if (!ci->boxes) + return 1; - ci = _mail_config_item_get(inst->gcc->id); - if (!ci) return; - for (l = ci->boxes; l; l = l->next) - { - Config_Box *cb; - - cb = l->data; - if (!cb) continue; - count += cb->num_new; - } - - if (count > 0) - { - snprintf(buf, sizeof(buf), "%d", count); - edje_object_part_text_set(inst->mail->mail_obj, "new_label", buf); - edje_object_signal_emit(inst->mail->mail_obj, "new_mail", ""); - } - else - { - edje_object_signal_emit(inst->mail->mail_obj, "no_mail", ""); - edje_object_part_text_set(inst->mail->mail_obj, "new_label", ""); - } + edje_object_signal_emit (inst->mail->mail_obj, "check_mail", ""); + + for (l = ci->boxes; l; l = l->next) + { + Config_Box *cb; + + cb = l->data; + if (!cb) + continue; + switch (cb->type) + { + case MAIL_TYPE_MDIR: + break; + case MAIL_TYPE_MBOX: + break; + case MAIL_TYPE_POP: + have_pop = 1; + break; + case MAIL_TYPE_IMAP: + have_imap = 1; + break; + } + } + if (have_imap) + _mail_imap_check_mail (inst); + if (have_pop) + _mail_pop_check_mail (inst); + return 1; } void -_mail_start_exe(void *data) +_mail_set_text (void *data) { - Config_Box *cb; - - cb = data; - if (!cb) return; - - exit_handler = ecore_event_handler_add(ECORE_EXE_EVENT_DEL, _mail_cb_exe_exit, cb); - cb->exe = ecore_exe_run(cb->exec, cb); -} + Instance *inst = data; + Config_Item *ci; + Evas_List *l; + char buf[1024]; + int count = 0; -static int -_mail_cb_exe_exit(void *data, int type, void *event) -{ - Config_Box *cb; - - cb = data; - if (!cb) return 0; - cb->exe = NULL; - ecore_event_handler_del(exit_handler); - return 0; + if (!inst) + return; + + ci = _mail_config_item_get (inst->gcc->id); + if (!ci) + return; + for (l = ci->boxes; l; l = l->next) + { + Config_Box *cb; + + cb = l->data; + if (!cb) + continue; + count += cb->num_new; + } + + if (count > 0) + { + snprintf (buf, sizeof (buf), "%d", count); + edje_object_part_text_set (inst->mail->mail_obj, "new_label", buf); + edje_object_signal_emit (inst->mail->mail_obj, "new_mail", ""); + } + else + { + edje_object_signal_emit (inst->mail->mail_obj, "no_mail", ""); + edje_object_part_text_set (inst->mail->mail_obj, "new_label", ""); + } } void -_mail_box_added(const char *ci_name, const char *box_name) +_mail_start_exe (void *data) { - Evas_List *l, *b; - - for (l = mail_config->instances; l; l = l->next) - { - Instance *inst; - Config_Item *ci; - - inst = l->data; - ci = _mail_config_item_get(inst->gcc->id); - if ((ci->id) && (!strcmp(ci->id, ci_name))) - { - for (b = ci->boxes; b; b = b->next) - { - Config_Box *cb; - - cb = b->data; - if ((cb->name) && (!strcmp(cb->name, box_name))) - { - switch (cb->type) - { - case MAIL_TYPE_IMAP: - _mail_imap_add_mailbox(cb); - break; - case MAIL_TYPE_POP: - _mail_pop_add_mailbox(cb); - break; - case MAIL_TYPE_MDIR: - _mail_mdir_add_mailbox(inst, cb); - break; - case MAIL_TYPE_MBOX: - _mail_mbox_add_mailbox(inst, cb); - break; - } - break; - } - } - break; - } - } + Config_Box *cb; + + cb = data; + if (!cb) + return; + + exit_handler = + ecore_event_handler_add (ECORE_EXE_EVENT_DEL, _mail_cb_exe_exit, cb); + cb->exe = ecore_exe_run (cb->exec, cb); } -void -_mail_box_deleted(const char *ci_name, const char *box_name) +static int +_mail_cb_exe_exit (void *data, int type, void *event) { - Evas_List *d, *i; - Config_Box *cb; - int found = 0; - - for (i = mail_config->instances; i; i = i->next) - { - Instance *inst; - - inst = i->data; - if (!inst->gcc->id) continue; - if (!strcmp(inst->gcc->id, ci_name)) - { - Config_Item *ci; - - ci = _mail_config_item_get(inst->gcc->id); - for (d = ci->boxes; d; d = d->next) - { - cb = d->data; - if ((cb->name) && (box_name)) + Config_Box *cb; + + cb = data; + if (!cb) + return 0; + cb->exe = NULL; + ecore_event_handler_del (exit_handler); + return 0; +} + +void +_mail_box_added (const char *ci_name, const char *box_name) +{ + Evas_List *l, *b; + + for (l = mail_config->instances; l; l = l->next) + { + Instance *inst; + Config_Item *ci; + + inst = l->data; + ci = _mail_config_item_get (inst->gcc->id); + if ((ci->id) && (!strcmp (ci->id, ci_name))) + { + for (b = ci->boxes; b; b = b->next) + { + Config_Box *cb; + + cb = b->data; + if ((cb->name) && (!strcmp (cb->name, box_name))) + { + switch (cb->type) { - if (!strcmp(cb->name, box_name)) - { - found = 1; - break; - } + case MAIL_TYPE_IMAP: + _mail_imap_add_mailbox (cb); + break; + case MAIL_TYPE_POP: + _mail_pop_add_mailbox (cb); + break; + case MAIL_TYPE_MDIR: + _mail_mdir_add_mailbox (inst, cb); + break; + case MAIL_TYPE_MBOX: + _mail_mbox_add_mailbox (inst, cb); + break; } - } - if (found) - { - switch (cb->type) - { - case MAIL_TYPE_IMAP: - _mail_imap_del_mailbox(cb); - break; - case MAIL_TYPE_POP: - _mail_pop_del_mailbox(cb); - break; - case MAIL_TYPE_MDIR: - _mail_mdir_del_mailbox(cb); - break; - case MAIL_TYPE_MBOX: - _mail_mbox_del_mailbox(cb); - break; - } - ci->boxes = evas_list_remove(ci->boxes, cb); - e_config_save_queue(); break; - } - break; - } - } + } + } + break; + } + } } -void -_mail_config_updated(const char *id) +void +_mail_box_deleted (const char *ci_name, const char *box_name) { - Evas_List *l; - Config_Item *ci; - - if (!mail_config) return; + Evas_List *d, *i; + Config_Box *cb; + int found = 0; - ci = _mail_config_item_get(id); - for (l = mail_config->instances; l; l = l->next) - { - Instance *inst; - - inst = l->data; - if (!inst->gcc->id) continue; - if (!strcmp(inst->gcc->id, ci->id)) - { - if (inst->check_timer) - { - ecore_timer_del(inst->check_timer); - inst->check_timer = ecore_timer_add((ci->check_time * 60.0), _mail_cb_check, inst); - } - - if (ci->show_label) - edje_object_signal_emit(inst->mail_obj, "label_active", ""); - else - edje_object_signal_emit(inst->mail_obj, "label_passive", ""); - break; - } - } + for (i = mail_config->instances; i; i = i->next) + { + Instance *inst; + + inst = i->data; + if (!inst->gcc->id) + continue; + if (!strcmp (inst->gcc->id, ci_name)) + { + Config_Item *ci; + + ci = _mail_config_item_get (inst->gcc->id); + for (d = ci->boxes; d; d = d->next) + { + cb = d->data; + if ((cb->name) && (box_name)) + { + if (!strcmp (cb->name, box_name)) + { + found = 1; + break; + } + } + } + if (found) + { + switch (cb->type) + { + case MAIL_TYPE_IMAP: + _mail_imap_del_mailbox (cb); + break; + case MAIL_TYPE_POP: + _mail_pop_del_mailbox (cb); + break; + case MAIL_TYPE_MDIR: + _mail_mdir_del_mailbox (cb); + break; + case MAIL_TYPE_MBOX: + _mail_mbox_del_mailbox (cb); + break; + } + ci->boxes = evas_list_remove (ci->boxes, cb); + e_config_save_queue (); + break; + } + break; + } + } } -static void -_mail_menu_cb_exec(void *data, E_Menu *m, E_Menu_Item *mi) +void +_mail_config_updated (const char *id) { - Config_Box *cb; - - cb = data; - if (!cb) return; - - exit_handler = ecore_event_handler_add(ECORE_EXE_EVENT_DEL, _mail_cb_exe_exit, cb); - cb->exe = ecore_exe_run(cb->exec, cb); + Evas_List *l; + Config_Item *ci; + + if (!mail_config) + return; + + ci = _mail_config_item_get (id); + for (l = mail_config->instances; l; l = l->next) + { + Instance *inst; + + inst = l->data; + if (!inst->gcc->id) + continue; + if (!strcmp (inst->gcc->id, ci->id)) + { + if (inst->check_timer) + { + ecore_timer_del (inst->check_timer); + inst->check_timer = + ecore_timer_add ((ci->check_time * 60.0), _mail_cb_check, + inst); + } + + if (ci->show_label) + edje_object_signal_emit (inst->mail_obj, "label_active", ""); + else + edje_object_signal_emit (inst->mail_obj, "label_passive", ""); + break; + } + } +} + +static void +_mail_menu_cb_exec (void *data, E_Menu * m, E_Menu_Item * mi) +{ + Config_Box *cb; + + cb = data; + if (!cb) + return; + + exit_handler = + ecore_event_handler_add (ECORE_EXE_EVENT_DEL, _mail_cb_exe_exit, cb); + cb->exe = ecore_exe_run (cb->exec, cb); } diff --git a/imap.c b/imap.c index 5700dc3..f6a7076 100644 --- a/imap.c +++ b/imap.c @@ -2,304 +2,330 @@ #include "e_mod_main.h" #include "imap.h" -static ImapServer *_mail_imap_server_get(Ecore_Con_Server *server); -static ImapClient *_mail_imap_client_get(void *data); -static int _mail_imap_server_add(void *data, int type, void *event); -static int _mail_imap_server_del(void *data, int type, void *event); -static int _mail_imap_server_data(void *data, int type, void *event); -static void _mail_imap_server_logout(ImapServer *is); +static ImapServer *_mail_imap_server_get (Ecore_Con_Server * server); +static ImapClient *_mail_imap_client_get (void *data); +static int _mail_imap_server_add (void *data, int type, void *event); +static int _mail_imap_server_del (void *data, int type, void *event); +static int _mail_imap_server_data (void *data, int type, void *event); +static void _mail_imap_server_logout (ImapServer * is); static Evas_List *iservers; void -_mail_imap_check_mail(void *data) +_mail_imap_check_mail (void *data) { - Ecore_Con_Type type = ECORE_CON_REMOTE_SYSTEM; - Evas_List *l, *j; - ImapClient *ic; + Ecore_Con_Type type = ECORE_CON_REMOTE_SYSTEM; + Evas_List *l, *j; + ImapClient *ic; - for (l = iservers; l; l = l->next) - { - ImapServer *is; - - is = l->data; - is->data = data; - if (!is->server) - { - if (!is->add_handler) - is->add_handler = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, _mail_imap_server_add, NULL); - if (!is->del_handler) - is->del_handler = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL, _mail_imap_server_del, NULL); - if (!is->data_handler) - is->data_handler = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA, _mail_imap_server_data, NULL); + for (l = iservers; l; l = l->next) + { + ImapServer *is; - for (j = is->clients; j; j = j->next) - { - ic = j->data; - if (!ic->server->server) - { - if (ecore_con_ssl_available_get() && (ic->config->ssl)) - type |= ECORE_CON_USE_SSL; - ic->server->state = IMAP_STATE_DISCONNECTED; - ic->server->server = ecore_con_server_connect(type, ic->config->host, ic->config->port, NULL); - ic->server->cmd = 0; - } - } - } - is->current = evas_list_nth(is->clients, 0); - ic = is->current; - } + is = l->data; + is->data = data; + if (!is->server) + { + if (!is->add_handler) + is->add_handler = + ecore_event_handler_add (ECORE_CON_EVENT_SERVER_ADD, + _mail_imap_server_add, NULL); + if (!is->del_handler) + is->del_handler = + ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DEL, + _mail_imap_server_del, NULL); + if (!is->data_handler) + is->data_handler = + ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DATA, + _mail_imap_server_data, NULL); + + for (j = is->clients; j; j = j->next) + { + ic = j->data; + if (!ic->server->server) + { + if (ecore_con_ssl_available_get () && (ic->config->ssl)) + type |= ECORE_CON_USE_SSL; + ic->server->state = IMAP_STATE_DISCONNECTED; + ic->server->server = + ecore_con_server_connect (type, ic->config->host, + ic->config->port, NULL); + ic->server->cmd = 0; + } + } + } + is->current = evas_list_nth (is->clients, 0); + ic = is->current; + } } void -_mail_imap_add_mailbox(void *data) +_mail_imap_add_mailbox (void *data) { - ImapClient *ic; - Config_Box *cb; + ImapClient *ic; + Config_Box *cb; - cb = data; - if (!cb) return; - ic = _mail_imap_client_get(cb); - ic->server->clients = evas_list_append(ic->server->clients, ic); -} - -void -_mail_imap_del_mailbox(void *data) -{ - ImapClient *ic; - Config_Box *cb; - - cb = data; - if (!cb) return; - ic = _mail_imap_client_get(cb); - ic->server->clients = evas_list_remove(ic->server->clients, ic); + cb = data; + if (!cb) + return; + ic = _mail_imap_client_get (cb); + ic->server->clients = evas_list_append (ic->server->clients, ic); } void -_mail_imap_shutdown() +_mail_imap_del_mailbox (void *data) { - if (!iservers) return; - while (iservers) - { - ImapServer *is; - - is = iservers->data; - if (is->add_handler) - ecore_event_handler_del(is->add_handler); - if (is->del_handler) - ecore_event_handler_del(is->del_handler); - if (is->data_handler) - ecore_event_handler_del(is->data_handler); - iservers = evas_list_remove_list(iservers, iservers); - free(is); - is = NULL; - } + ImapClient *ic; + Config_Box *cb; + + cb = data; + if (!cb) + return; + ic = _mail_imap_client_get (cb); + ic->server->clients = evas_list_remove (ic->server->clients, ic); +} + +void +_mail_imap_shutdown () +{ + if (!iservers) + return; + while (iservers) + { + ImapServer *is; + + is = iservers->data; + if (is->add_handler) + ecore_event_handler_del (is->add_handler); + if (is->del_handler) + ecore_event_handler_del (is->del_handler); + if (is->data_handler) + ecore_event_handler_del (is->data_handler); + iservers = evas_list_remove_list (iservers, iservers); + free (is); + is = NULL; + } } /* PRIVATES */ static ImapServer * -_mail_imap_server_get(Ecore_Con_Server *server) +_mail_imap_server_get (Ecore_Con_Server * server) { - Evas_List *l; - - for (l = iservers; l; l = l->next) - { - ImapServer *is; - - is = l->data; - if (is->server == server) - return is; - } - return NULL; + Evas_List *l; + + for (l = iservers; l; l = l->next) + { + ImapServer *is; + + is = l->data; + if (is->server == server) + return is; + } + return NULL; } static ImapClient * -_mail_imap_client_get(void *data) +_mail_imap_client_get (void *data) { - ImapServer *is; - ImapClient *ic; - Config_Box *cb; - Evas_List *l, *j; - int found = 0; + ImapServer *is; + ImapClient *ic; + Config_Box *cb; + Evas_List *l, *j; + int found = 0; - cb = data; - if (!cb) return NULL; - - if ((!iservers) || (evas_list_count(iservers) <= 0)) - { - is = E_NEW(ImapServer, 1); - is->server = NULL; - is->cmd = 0; - is->state = IMAP_STATE_DISCONNECTED; - iservers = evas_list_append(iservers, is); - } - - for (l = iservers; l; l = l->next) - { - is = l->data; - if (!is->clients) continue; - for (j = is->clients; j; j = j->next) - { - ic = j->data; - if (!ic->config) continue; - if ((!strcmp(ic->config->host, cb->host)) && - (!strcmp(ic->config->user, cb->user)) && - (!strcmp(ic->config->pass, cb->pass))) - { - found = 1; - break; - } - } - if (found) break; - } - if (!found) - { - ic = E_NEW(ImapClient, 1); - ic->config = cb; - ic->server = is; - ic->config->num_new = 0; - ic->config->num_total = 0; - } - return ic; -} + cb = data; + if (!cb) + return NULL; -static int -_mail_imap_server_add(void *data, int type, void *event) -{ - Ecore_Con_Event_Server_Add *ev = event; - ImapServer *is; - - is = _mail_imap_server_get(ev->server); - if (!is) return 1; + if ((!iservers) || (evas_list_count (iservers) <= 0)) + { + is = E_NEW (ImapServer, 1); + is->server = NULL; + is->cmd = 0; + is->state = IMAP_STATE_DISCONNECTED; + iservers = evas_list_append (iservers, is); + } - is->state = IMAP_STATE_CONNECTED; - is->cmd = 0; - return 0; -} - -static int -_mail_imap_server_del(void *data, int type, void *event) -{ - Ecore_Con_Event_Server_Del *ev = event; - ImapServer *is; - - is = _mail_imap_server_get(ev->server); - if (!is) return 1; - - if (is->state == IMAP_STATE_DISCONNECTED) - printf("Imap Server Disconnected\n"); - else - is->state = IMAP_STATE_DISCONNECTED; - - ecore_con_server_del(is->server); - is->server = NULL; - - _mail_set_text(is->data); - return 0; -} - -static int -_mail_imap_server_data(void *data, int type, void *event) -{ - Ecore_Con_Event_Server_Data *ev = event; - ImapServer *is; - ImapClient *ic; - int len, num = 0, total = 0; - char in[1024], out[1024], *spc; - size_t slen; - - is = _mail_imap_server_get(ev->server); - if (!is) return 1; - if (is->state == IMAP_STATE_DISCONNECTED) return 1; - - len = sizeof(in) - 1; - len = (len > ev->size) ? (ev->size) : (len); - - memcpy(in, ev->data, len); - in[len] = 0; - - if ((spc = strchr(in, ' '))) - { - slen = strlen(spc); - if ((slen > 5) && (!strncmp(spc + 1, "NO ", 3))) - { - _mail_imap_server_logout(is); - printf("Imap Failure: %s\n", spc + 4); - return 0; - } - else if ((slen > 6) && (!strncmp(spc + 1, "BAD ", 4))) - { - _mail_imap_server_logout(is); - printf("Imap Bad Command: %s\n", spc + 5); - return 0; - } - } - - ic = is->current; - is->state++; - - switch (is->state) - { - case IMAP_STATE_SERVER_READY: - len = snprintf(out, sizeof(out), "A%03i LOGIN %s %s\r\n", ++is->cmd, ic->config->user, ic->config->pass); - ecore_con_server_send(ev->server, out, len); + for (l = iservers; l; l = l->next) + { + is = l->data; + if (!is->clients) + continue; + for (j = is->clients; j; j = j->next) + { + ic = j->data; + if (!ic->config) + continue; + if ((!strcmp (ic->config->host, cb->host)) && + (!strcmp (ic->config->user, cb->user)) && + (!strcmp (ic->config->pass, cb->pass))) + { + found = 1; + break; + } + } + if (found) break; - case IMAP_STATE_LOGGED_IN: - len = snprintf(out, sizeof(out), "A%03i STATUS %s (MESSAGES UNSEEN)\r\n", ++is->cmd, ic->config->new_path); - ecore_con_server_send(ev->server, out, len); - break; - case IMAP_STATE_STATUS_OK: - if (sscanf(in, "* STATUS %*s (MESSAGES %i UNSEEN %i)", &total, &num) == 2) - { - ic->config->num_new = num; - ic->config->num_total = total; - _mail_set_text(is->data); - - if ((num > 0) && (ic->config->use_exec) && (ic->config->exec)) - _mail_start_exe(ic->config); - - is->clients = is->clients->next; - if (is->clients) - { - is->current = is->clients->data; - if (is->current) - { - ic = is->current; - is->state = IMAP_STATE_SERVER_READY; - } - else - { - _mail_imap_server_logout(is); - ic = NULL; - } - } - else - { - _mail_imap_server_logout(is); + } + if (!found) + { + ic = E_NEW (ImapClient, 1); + ic->config = cb; + ic->server = is; + ic->config->num_new = 0; + ic->config->num_total = 0; + } + return ic; +} + +static int +_mail_imap_server_add (void *data, int type, void *event) +{ + Ecore_Con_Event_Server_Add *ev = event; + ImapServer *is; + + is = _mail_imap_server_get (ev->server); + if (!is) + return 1; + + is->state = IMAP_STATE_CONNECTED; + is->cmd = 0; + return 0; +} + +static int +_mail_imap_server_del (void *data, int type, void *event) +{ + Ecore_Con_Event_Server_Del *ev = event; + ImapServer *is; + + is = _mail_imap_server_get (ev->server); + if (!is) + return 1; + + if (is->state == IMAP_STATE_DISCONNECTED) + printf ("Imap Server Disconnected\n"); + else + is->state = IMAP_STATE_DISCONNECTED; + + ecore_con_server_del (is->server); + is->server = NULL; + + _mail_set_text (is->data); + return 0; +} + +static int +_mail_imap_server_data (void *data, int type, void *event) +{ + Ecore_Con_Event_Server_Data *ev = event; + ImapServer *is; + ImapClient *ic; + int len, num = 0, total = 0; + char in[1024], out[1024], *spc; + size_t slen; + + is = _mail_imap_server_get (ev->server); + if (!is) + return 1; + if (is->state == IMAP_STATE_DISCONNECTED) + return 1; + + len = sizeof (in) - 1; + len = (len > ev->size) ? (ev->size) : (len); + + memcpy (in, ev->data, len); + in[len] = 0; + + if ((spc = strchr (in, ' '))) + { + slen = strlen (spc); + if ((slen > 5) && (!strncmp (spc + 1, "NO ", 3))) + { + _mail_imap_server_logout (is); + printf ("Imap Failure: %s\n", spc + 4); + return 0; + } + else if ((slen > 6) && (!strncmp (spc + 1, "BAD ", 4))) + { + _mail_imap_server_logout (is); + printf ("Imap Bad Command: %s\n", spc + 5); + return 0; + } + } + + ic = is->current; + is->state++; + + switch (is->state) + { + case IMAP_STATE_SERVER_READY: + len = + snprintf (out, sizeof (out), "A%03i LOGIN %s %s\r\n", ++is->cmd, + ic->config->user, ic->config->pass); + ecore_con_server_send (ev->server, out, len); + break; + case IMAP_STATE_LOGGED_IN: + len = + snprintf (out, sizeof (out), "A%03i STATUS %s (MESSAGES UNSEEN)\r\n", + ++is->cmd, ic->config->new_path); + ecore_con_server_send (ev->server, out, len); + break; + case IMAP_STATE_STATUS_OK: + if (sscanf (in, "* STATUS %*s (MESSAGES %i UNSEEN %i)", &total, &num) == + 2) + { + ic->config->num_new = num; + ic->config->num_total = total; + _mail_set_text (is->data); + + if ((num > 0) && (ic->config->use_exec) && (ic->config->exec)) + _mail_start_exe (ic->config); + + is->clients = is->clients->next; + if (is->clients) + { + is->current = is->clients->data; + if (is->current) + { + ic = is->current; + is->state = IMAP_STATE_SERVER_READY; + } + else + { + _mail_imap_server_logout (is); ic = NULL; - } - } - if (!ic) break; - default: + } + } + else + { + _mail_imap_server_logout (is); + ic = NULL; + } + } + if (!ic) break; - } - return 0; + default: + break; + } + return 0; } -static void -_mail_imap_server_logout(ImapServer *is) +static void +_mail_imap_server_logout (ImapServer * is) { - int len; - char out[1024]; - - if (!is) return; - - if (is->state >= IMAP_STATE_LOGGED_IN) - { - len = snprintf(out, sizeof(out), "A%03i LOGOUT", ++is->cmd); - ecore_con_server_send(is->server, out, len); - } - ecore_con_server_del(is->server); - is->server = NULL; - is->state = IMAP_STATE_DISCONNECTED; + int len; + char out[1024]; + + if (!is) + return; + + if (is->state >= IMAP_STATE_LOGGED_IN) + { + len = snprintf (out, sizeof (out), "A%03i LOGOUT", ++is->cmd); + ecore_con_server_send (is->server, out, len); + } + ecore_con_server_del (is->server); + is->server = NULL; + is->state = IMAP_STATE_DISCONNECTED; } diff --git a/mbox.c b/mbox.c index 34b1d89..a4f96a7 100644 --- a/mbox.c +++ b/mbox.c @@ -4,107 +4,120 @@ static Evas_List *mboxes; -static void _mail_mbox_check_mail(void *data, Ecore_File_Monitor *monitor, Ecore_File_Event event, const char *path); +static void _mail_mbox_check_mail (void *data, Ecore_File_Monitor * monitor, + Ecore_File_Event event, const char *path); -void -_mail_mbox_add_mailbox(void *data, void *data2) +void +_mail_mbox_add_mailbox (void *data, void *data2) { - MboxClient *mb; - Config_Box *cb; - - cb = data2; - if (!cb) return; - - mb = E_NEW(MboxClient, 1); - mb->config = cb; - mb->data = data; - mb->config->num_new = 0; - mb->config->num_total = 0; - mb->monitor = ecore_file_monitor_add(cb->new_path, _mail_mbox_check_mail, mb); - - mboxes = evas_list_append(mboxes, mb); + MboxClient *mb; + Config_Box *cb; + + cb = data2; + if (!cb) + return; + + mb = E_NEW (MboxClient, 1); + mb->config = cb; + mb->data = data; + mb->config->num_new = 0; + mb->config->num_total = 0; + mb->monitor = + ecore_file_monitor_add (cb->new_path, _mail_mbox_check_mail, mb); + + mboxes = evas_list_append (mboxes, mb); } void -_mail_mbox_del_mailbox(void *data) +_mail_mbox_del_mailbox (void *data) { - Config_Box *cb; - Evas_List *l; - - cb = data; - if (!cb) return; - for (l = mboxes; l; l = l->next) - { - MboxClient *mb; - - mb = l->data; - if (!mb) continue; - if (mb->config != cb) continue; - if (mb->monitor) - ecore_file_monitor_del(mb->monitor); - mboxes = evas_list_remove(mboxes, mb); - free(mb); - mb = NULL; - break; - } + Config_Box *cb; + Evas_List *l; + + cb = data; + if (!cb) + return; + for (l = mboxes; l; l = l->next) + { + MboxClient *mb; + + mb = l->data; + if (!mb) + continue; + if (mb->config != cb) + continue; + if (mb->monitor) + ecore_file_monitor_del (mb->monitor); + mboxes = evas_list_remove (mboxes, mb); + free (mb); + mb = NULL; + break; + } } void -_mail_mbox_shutdown() +_mail_mbox_shutdown () { - if (!mboxes) return; - while (mboxes) - { - MboxClient *mb; - - mb = mboxes->data; - if (mb->monitor) - ecore_file_monitor_del(mb->monitor); - mboxes = evas_list_remove_list(mboxes, mboxes); - free(mb); - mb = NULL; - } + if (!mboxes) + return; + while (mboxes) + { + MboxClient *mb; + + mb = mboxes->data; + if (mb->monitor) + ecore_file_monitor_del (mb->monitor); + mboxes = evas_list_remove_list (mboxes, mboxes); + free (mb); + mb = NULL; + } } /* PRIVATES */ -static void -_mail_mbox_check_mail(void *data, Ecore_File_Monitor *monitor, Ecore_File_Event event, const char *path) +static void +_mail_mbox_check_mail (void *data, Ecore_File_Monitor * monitor, + Ecore_File_Event event, const char *path) { - MboxClient *mb; - Config_Box *cb; - FILE *f; - char buf[1024]; - int header; - - mb = data; - if (!mb) return; - - cb = mb->config; - if (!cb) return; - if (!cb->new_path) return; - - if (!(f = fopen(cb->new_path, "r"))) - return; + MboxClient *mb; + Config_Box *cb; + FILE *f; + char buf[1024]; + int header; - mb->config->num_new = 0; - mb->config->num_total = 0; - - while (fgets(buf, sizeof(buf), f)) - { - if (buf[0] == '\n') - header = 0; - else if (!strncmp(buf, "From ", 5)) - { - header = 1; - mb->config->num_total++; - mb->config->num_new++; - } - else if ((header) && (!strncmp(buf, "Status: ", 7)) && (strchr(buf, 'R'))) - mb->config->num_new--; - } - fclose(f); + mb = data; + if (!mb) + return; - _mail_set_text(mb->data); - if ((mb->config->num_new > 0) && (mb->config->use_exec) && (mb->config->exec)) - _mail_start_exe(mb->config); + cb = mb->config; + if (!cb) + return; + if (!cb->new_path) + return; + + if (!(f = fopen (cb->new_path, "r"))) + return; + + mb->config->num_new = 0; + mb->config->num_total = 0; + + while (fgets (buf, sizeof (buf), f)) + { + if (buf[0] == '\n') + header = 0; + else if (!strncmp (buf, "From ", 5)) + { + header = 1; + mb->config->num_total++; + mb->config->num_new++; + } + else if ((header) && (!strncmp (buf, "Status: ", 7)) + && (strchr (buf, 'R'))) + mb->config->num_new--; + } + fclose (f); + + _mail_set_text (mb->data); + if ((mb->config->num_new > 0) && (mb->config->use_exec) + && (mb->config->exec)) + _mail_start_exe (mb->config); } diff --git a/mdir.c b/mdir.c index 68db300..30f935e 100644 --- a/mdir.c +++ b/mdir.c @@ -4,98 +4,109 @@ static Evas_List *mdirs; -static void _mail_mdir_check_mail(void *data, Ecore_File_Monitor *monitor, Ecore_File_Event event, const char *path); -static int _mail_mdir_get_files(const char *path); +static void _mail_mdir_check_mail (void *data, Ecore_File_Monitor * monitor, + Ecore_File_Event event, const char *path); +static int _mail_mdir_get_files (const char *path); void -_mail_mdir_add_mailbox(void *data, void *data2) +_mail_mdir_add_mailbox (void *data, void *data2) { - MdirClient *mc; - Config_Box *cb; - - cb = data2; - if (!cb) return; - - mc = E_NEW(MdirClient, 1); - mc->config = cb; - mc->data = data; - mc->config->num_new = 0; - mc->config->num_total = 0; - mc->monitor = ecore_file_monitor_add(cb->new_path, _mail_mdir_check_mail, mc); + MdirClient *mc; + Config_Box *cb; - mdirs = evas_list_append(mdirs, mc); + cb = data2; + if (!cb) + return; + + mc = E_NEW (MdirClient, 1); + mc->config = cb; + mc->data = data; + mc->config->num_new = 0; + mc->config->num_total = 0; + mc->monitor = + ecore_file_monitor_add (cb->new_path, _mail_mdir_check_mail, mc); + + mdirs = evas_list_append (mdirs, mc); } void -_mail_mdir_del_mailbox(void *data) +_mail_mdir_del_mailbox (void *data) { - Config_Box *cb; - Evas_List *l; - - cb = data; - if (!cb) return; - for (l = mdirs; l; l = l->next) - { - MdirClient *mc; - - mc = l->data; - if (!mc) continue; - if (mc->config != cb) continue; - mdirs = evas_list_remove(mdirs, mc); - free(mc); - mc = NULL; - break; - } + Config_Box *cb; + Evas_List *l; + + cb = data; + if (!cb) + return; + for (l = mdirs; l; l = l->next) + { + MdirClient *mc; + + mc = l->data; + if (!mc) + continue; + if (mc->config != cb) + continue; + mdirs = evas_list_remove (mdirs, mc); + free (mc); + mc = NULL; + break; + } } void -_mail_mdir_shutdown() +_mail_mdir_shutdown () { - if (!mdirs) return; - while (mdirs) - { - MdirClient *mc; - - mc = mdirs->data; - if (mc->monitor) - ecore_file_monitor_del(mc->monitor); - mdirs = evas_list_remove_list(mdirs, mdirs); - free(mc); - mc = NULL; - } + if (!mdirs) + return; + while (mdirs) + { + MdirClient *mc; + + mc = mdirs->data; + if (mc->monitor) + ecore_file_monitor_del (mc->monitor); + mdirs = evas_list_remove_list (mdirs, mdirs); + free (mc); + mc = NULL; + } } /* PRIVATES */ -static void -_mail_mdir_check_mail(void *data, Ecore_File_Monitor *monitor, Ecore_File_Event event, const char *path) +static void +_mail_mdir_check_mail (void *data, Ecore_File_Monitor * monitor, + Ecore_File_Event event, const char *path) { - MdirClient *mc; - - mc = data; - if (!mc) return; + MdirClient *mc; - mc->config->num_total = _mail_mdir_get_files(mc->config->cur_path); - mc->config->num_new = _mail_mdir_get_files(mc->config->new_path); + mc = data; + if (!mc) + return; - _mail_set_text(mc->data); - if ((mc->config->num_new > 0) && (mc->config->use_exec) && (mc->config->exec)) - _mail_start_exe(mc->config); + mc->config->num_total = _mail_mdir_get_files (mc->config->cur_path); + mc->config->num_new = _mail_mdir_get_files (mc->config->new_path); + + _mail_set_text (mc->data); + if ((mc->config->num_new > 0) && (mc->config->use_exec) + && (mc->config->exec)) + _mail_start_exe (mc->config); } -static int -_mail_mdir_get_files(const char *path) +static int +_mail_mdir_get_files (const char *path) { - Ecore_List *l; - char *item; - int i = 0; - - l = ecore_file_ls(path); - ecore_list_goto_first(l); - while ((item = (char *)ecore_list_next(l)) != NULL) - { - if ((!strcmp(item, ".")) || (!strcmp(item, ".."))) continue; - i++; - } - ecore_list_destroy(l); - return i; + Ecore_List *l; + char *item; + int i = 0; + + l = ecore_file_ls (path); + ecore_list_goto_first (l); + while ((item = (char *) ecore_list_next (l)) != NULL) + { + if ((!strcmp (item, ".")) || (!strcmp (item, ".."))) + continue; + i++; + } + ecore_list_destroy (l); + return i; } diff --git a/pop.c b/pop.c index f679957..384acdd 100644 --- a/pop.c +++ b/pop.c @@ -2,293 +2,330 @@ #include "e_mod_main.h" #include "pop.h" -static int _mail_pop_server_add(void *data, int type, void *event); -static int _mail_pop_server_del(void *data, int type, void *event); -static int _mail_pop_server_data(void *data, int type, void *event); -static PopClient *_mail_pop_client_get(void *data); -static PopClient *_mail_pop_client_get_from_server(void *data); -static void _mail_pop_client_quit(void *data); +static int _mail_pop_server_add (void *data, int type, void *event); +static int _mail_pop_server_del (void *data, int type, void *event); +static int _mail_pop_server_data (void *data, int type, void *event); +static PopClient *_mail_pop_client_get (void *data); +static PopClient *_mail_pop_client_get_from_server (void *data); +static void _mail_pop_client_quit (void *data); static Evas_List *pclients; void -_mail_pop_check_mail(void *data) +_mail_pop_check_mail (void *data) { - Ecore_Con_Type type = ECORE_CON_REMOTE_SYSTEM; - Evas_List *l; - Instance *inst; - - inst = data; - if (!inst) return; - - for (l = pclients; l; l = l->next) - { - PopClient *pc; + Ecore_Con_Type type = ECORE_CON_REMOTE_SYSTEM; + Evas_List *l; + Instance *inst; - pc = l->data; - if (!pc) continue; - pc->data = inst; - if (!pc->server) - { - if (!pc->add_handler) - pc->add_handler = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, _mail_pop_server_add, NULL); - if (!pc->del_handler) - pc->del_handler = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL, _mail_pop_server_del, NULL); - if (!pc->data_handler) - pc->data_handler = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA, _mail_pop_server_data, NULL); - - if ((ecore_con_ssl_available_get()) && (pc->config->ssl)) - type |= ECORE_CON_USE_SSL; - pc->server = ecore_con_server_connect(type, pc->config->host, pc->config->port, pc); - pc->state = POP_STATE_DISCONNECTED; - } - } -} + inst = data; + if (!inst) + return; -void -_mail_pop_add_mailbox(void *data) -{ - PopClient *pc; - Config_Box *cb; - - cb = data; - if (!cb) return; - pc = _mail_pop_client_get(cb); - pc->config->num_new = 0; - pc->config->num_total = 0; - pclients = evas_list_append(pclients, pc); + for (l = pclients; l; l = l->next) + { + PopClient *pc; + + pc = l->data; + if (!pc) + continue; + pc->data = inst; + if (!pc->server) + { + if (!pc->add_handler) + pc->add_handler = + ecore_event_handler_add (ECORE_CON_EVENT_SERVER_ADD, + _mail_pop_server_add, NULL); + if (!pc->del_handler) + pc->del_handler = + ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DEL, + _mail_pop_server_del, NULL); + if (!pc->data_handler) + pc->data_handler = + ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DATA, + _mail_pop_server_data, NULL); + + if ((ecore_con_ssl_available_get ()) && (pc->config->ssl)) + type |= ECORE_CON_USE_SSL; + pc->server = + ecore_con_server_connect (type, pc->config->host, + pc->config->port, pc); + pc->state = POP_STATE_DISCONNECTED; + } + } } void -_mail_pop_del_mailbox(void *data) +_mail_pop_add_mailbox (void *data) { - PopClient *pc; - Config_Box *cb; - - cb = data; - if (!cb) return; - pc = _mail_pop_client_get(cb); - if (pc->server) - _mail_pop_client_quit(pc); - if (pc->add_handler) - ecore_event_handler_del(pc->add_handler); - if (pc->del_handler) - ecore_event_handler_del(pc->del_handler); - if (pc->data_handler) - ecore_event_handler_del(pc->data_handler); - pclients = evas_list_remove(pclients, pc); + PopClient *pc; + Config_Box *cb; + + cb = data; + if (!cb) + return; + pc = _mail_pop_client_get (cb); + pc->config->num_new = 0; + pc->config->num_total = 0; + pclients = evas_list_append (pclients, pc); } void -_mail_pop_shutdown() +_mail_pop_del_mailbox (void *data) { - if (!pclients) return; + PopClient *pc; + Config_Box *cb; - while (pclients) - { - PopClient *pc; - - pc = pclients->data; - if (!pc) continue; - if (pc->server) - _mail_pop_client_quit(pc); - if (pc->add_handler) - ecore_event_handler_del(pc->add_handler); - if (pc->del_handler) - ecore_event_handler_del(pc->del_handler); - if (pc->data_handler) - ecore_event_handler_del(pc->data_handler); - pclients = evas_list_remove_list(pclients, pclients); - free(pc); - pc = NULL; - } + cb = data; + if (!cb) + return; + pc = _mail_pop_client_get (cb); + if (pc->server) + _mail_pop_client_quit (pc); + if (pc->add_handler) + ecore_event_handler_del (pc->add_handler); + if (pc->del_handler) + ecore_event_handler_del (pc->del_handler); + if (pc->data_handler) + ecore_event_handler_del (pc->data_handler); + pclients = evas_list_remove (pclients, pc); +} + +void +_mail_pop_shutdown () +{ + if (!pclients) + return; + + while (pclients) + { + PopClient *pc; + + pc = pclients->data; + if (!pc) + continue; + if (pc->server) + _mail_pop_client_quit (pc); + if (pc->add_handler) + ecore_event_handler_del (pc->add_handler); + if (pc->del_handler) + ecore_event_handler_del (pc->del_handler); + if (pc->data_handler) + ecore_event_handler_del (pc->data_handler); + pclients = evas_list_remove_list (pclients, pclients); + free (pc); + pc = NULL; + } } /* PRIVATES */ -static int -_mail_pop_server_add(void *data, int type, void *event) +static int +_mail_pop_server_add (void *data, int type, void *event) { - Ecore_Con_Event_Server_Add *ev = event; - PopClient *pc; - - pc = _mail_pop_client_get_from_server(ev->server); - if (!pc) return 1; - - pc->state = POP_STATE_CONNECTED; - return 0; + Ecore_Con_Event_Server_Add *ev = event; + PopClient *pc; + + pc = _mail_pop_client_get_from_server (ev->server); + if (!pc) + return 1; + + pc->state = POP_STATE_CONNECTED; + return 0; } -static int -_mail_pop_server_del(void *data, int type, void *event) +static int +_mail_pop_server_del (void *data, int type, void *event) { - Ecore_Con_Event_Server_Del *ev = event; - PopClient *pc; - - pc = _mail_pop_client_get_from_server(ev->server); - if (!pc) return 1; + Ecore_Con_Event_Server_Del *ev = event; + PopClient *pc; - if (pc->state == POP_STATE_DISCONNECTED) - printf("Pop Server Disconnected\n"); - - ecore_con_server_del(ev->server); - pc->server = NULL; - pc->state = POP_STATE_DISCONNECTED; - - return 0; + pc = _mail_pop_client_get_from_server (ev->server); + if (!pc) + return 1; + + if (pc->state == POP_STATE_DISCONNECTED) + printf ("Pop Server Disconnected\n"); + + ecore_con_server_del (ev->server); + pc->server = NULL; + pc->state = POP_STATE_DISCONNECTED; + + return 0; } -static int -_mail_pop_server_data(void *data, int type, void *event) +static int +_mail_pop_server_data (void *data, int type, void *event) { - Ecore_Con_Event_Server_Data *ev = event; - PopClient *pc; - char in[2048], out[2048]; - int len, num = 0, total = 0; - - pc = _mail_pop_client_get_from_server(ev->server); - if (!pc) return 1; - if (pc->state == POP_STATE_DISCONNECTED) return 1; - - len = sizeof(in) -1; - len = (((len) > (ev->size)) ? ev->size : len); - memcpy(in, ev->data, len); - in[len] = 0; - - if (!strncmp(in, "-ERR", 4)) - { - printf("ERROR: %s\n", in); - _mail_pop_client_quit(pc); - return 0; - } - else if (strncmp(in, "+OK", 3)) - { - printf("Unexpected reply: %s\n", in); - _mail_pop_client_quit(pc); - return 0; - } + Ecore_Con_Event_Server_Data *ev = event; + PopClient *pc; + char in[2048], out[2048]; + int len, num = 0, total = 0; - pc->state++; - switch (pc->state) - { - case POP_STATE_SERVER_READY: - len = snprintf(out, sizeof(out), "USER %s\r\n", pc->config->user); - ecore_con_server_send(ev->server, out, len); - break; - case POP_STATE_USER_OK: - len = snprintf(out, sizeof(out), "PASS %s\r\n", pc->config->pass); - ecore_con_server_send(ev->server, out, len); - break; - case POP_STATE_PASS_OK: - len = snprintf(out, sizeof(out), "STAT\r\n"); - ecore_con_server_send(ev->server, out, len); - break; - case POP_STATE_STATUS_OK: - if (sscanf(in, "+OK %i %i", &num, &total) == 2) - { - pc->config->num_new = num; - pc->config->num_total = num; - } - _mail_pop_client_quit(pc); - if ((num > 0) && (pc->config->use_exec) && (pc->config->exec)) - _mail_start_exe(pc->config); - break; - default: - break; - } - return 0; + pc = _mail_pop_client_get_from_server (ev->server); + if (!pc) + return 1; + if (pc->state == POP_STATE_DISCONNECTED) + return 1; + + len = sizeof (in) - 1; + len = (((len) > (ev->size)) ? ev->size : len); + memcpy (in, ev->data, len); + in[len] = 0; + + if (!strncmp (in, "-ERR", 4)) + { + printf ("ERROR: %s\n", in); + _mail_pop_client_quit (pc); + return 0; + } + else if (strncmp (in, "+OK", 3)) + { + printf ("Unexpected reply: %s\n", in); + _mail_pop_client_quit (pc); + return 0; + } + + pc->state++; + switch (pc->state) + { + case POP_STATE_SERVER_READY: + len = snprintf (out, sizeof (out), "USER %s\r\n", pc->config->user); + ecore_con_server_send (ev->server, out, len); + break; + case POP_STATE_USER_OK: + len = snprintf (out, sizeof (out), "PASS %s\r\n", pc->config->pass); + ecore_con_server_send (ev->server, out, len); + break; + case POP_STATE_PASS_OK: + len = snprintf (out, sizeof (out), "STAT\r\n"); + ecore_con_server_send (ev->server, out, len); + break; + case POP_STATE_STATUS_OK: + if (sscanf (in, "+OK %i %i", &num, &total) == 2) + { + pc->config->num_new = num; + pc->config->num_total = num; + } + _mail_pop_client_quit (pc); + if ((num > 0) && (pc->config->use_exec) && (pc->config->exec)) + _mail_start_exe (pc->config); + break; + default: + break; + } + return 0; } static PopClient * -_mail_pop_client_get(void *data) +_mail_pop_client_get (void *data) { - PopClient *pc; - Evas_List *l; - Config_Box *cb; - int found = 0; - - cb = data; - if (!cb) return NULL; - - if ((!pclients) || (evas_list_count(pclients) <= 0)) - { - pc = E_NEW(PopClient, 1); - pc->server = NULL; - pc->state = POP_STATE_DISCONNECTED; - pc->config = cb; - if (!pc->add_handler) - pc->add_handler = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, _mail_pop_server_add, NULL); - if (!pc->del_handler) - pc->del_handler = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL, _mail_pop_server_del, NULL); - if (!pc->data_handler) - pc->data_handler = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA, _mail_pop_server_data, NULL); - } + PopClient *pc; + Evas_List *l; + Config_Box *cb; + int found = 0; - for (l = pclients; l; l = l->next) - { - pc = l->data; - if (!pc) continue; - if (!pc->config) continue; - if ((!strcmp(pc->config->host, cb->host)) && - (!strcmp(pc->config->user, cb->user)) && - (!strcmp(pc->config->pass, cb->pass))) - { - found = 1; - break; - } - } - if (!found) - { - pc = E_NEW(PopClient, 1); - pc->server = NULL; - pc->state = POP_STATE_DISCONNECTED; - pc->config = cb; - if (!pc->add_handler) - pc->add_handler = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, _mail_pop_server_add, NULL); - if (!pc->del_handler) - pc->del_handler = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL, _mail_pop_server_del, NULL); - if (!pc->data_handler) - pc->data_handler = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA, _mail_pop_server_data, NULL); - } - return pc; + cb = data; + if (!cb) + return NULL; + + if ((!pclients) || (evas_list_count (pclients) <= 0)) + { + pc = E_NEW (PopClient, 1); + pc->server = NULL; + pc->state = POP_STATE_DISCONNECTED; + pc->config = cb; + if (!pc->add_handler) + pc->add_handler = + ecore_event_handler_add (ECORE_CON_EVENT_SERVER_ADD, + _mail_pop_server_add, NULL); + if (!pc->del_handler) + pc->del_handler = + ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DEL, + _mail_pop_server_del, NULL); + if (!pc->data_handler) + pc->data_handler = + ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DATA, + _mail_pop_server_data, NULL); + } + + for (l = pclients; l; l = l->next) + { + pc = l->data; + if (!pc) + continue; + if (!pc->config) + continue; + if ((!strcmp (pc->config->host, cb->host)) && + (!strcmp (pc->config->user, cb->user)) && + (!strcmp (pc->config->pass, cb->pass))) + { + found = 1; + break; + } + } + if (!found) + { + pc = E_NEW (PopClient, 1); + pc->server = NULL; + pc->state = POP_STATE_DISCONNECTED; + pc->config = cb; + if (!pc->add_handler) + pc->add_handler = + ecore_event_handler_add (ECORE_CON_EVENT_SERVER_ADD, + _mail_pop_server_add, NULL); + if (!pc->del_handler) + pc->del_handler = + ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DEL, + _mail_pop_server_del, NULL); + if (!pc->data_handler) + pc->data_handler = + ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DATA, + _mail_pop_server_data, NULL); + } + return pc; } static PopClient * -_mail_pop_client_get_from_server(void *data) +_mail_pop_client_get_from_server (void *data) { - Ecore_Con_Server *server = data; - Evas_List *l; - - if (!pclients) return NULL; - for (l = pclients; l; l = l->next) - { - PopClient *pc; - - pc = l->data; - if (!pc) continue; - if (!pc->server) continue; - if (pc->server == server) - return pc; - } - return NULL; + Ecore_Con_Server *server = data; + Evas_List *l; + + if (!pclients) + return NULL; + for (l = pclients; l; l = l->next) + { + PopClient *pc; + + pc = l->data; + if (!pc) + continue; + if (!pc->server) + continue; + if (pc->server == server) + return pc; + } + return NULL; } -static void -_mail_pop_client_quit(void *data) +static void +_mail_pop_client_quit (void *data) { - PopClient *pc; - int len; - char out[1024]; - - pc = data; - if (!pc) return; - if (pc->state >= POP_STATE_CONNECTED) - { - len = snprintf(out, sizeof(out), "QUIT\r\n"); - ecore_con_server_send(pc->server, out, len); - } - ecore_con_server_del(pc->server); - pc->server = NULL; - pc->state = POP_STATE_DISCONNECTED; + PopClient *pc; + int len; + char out[1024]; - _mail_set_text(pc->data); + pc = data; + if (!pc) + return; + if (pc->state >= POP_STATE_CONNECTED) + { + len = snprintf (out, sizeof (out), "QUIT\r\n"); + ecore_con_server_send (pc->server, out, len); + } + ecore_con_server_del (pc->server); + pc->server = NULL; + pc->state = POP_STATE_DISCONNECTED; + + _mail_set_text (pc->data); }