generate_text_internal(p, max_user_text, *root, cur);
}
-static inline struct mail_s *ensure_mail_thread(struct text_object *obj,
- void *thread(void *), const char *text)
-{
- if (obj->char_b && info.mail) {
- // this means we use info
- if (!info.mail->p_timed_thread) {
- info.mail->p_timed_thread =
- timed_thread_create(thread,
- (void *) info.mail, info.mail->interval * 1000000);
- if (!info.mail->p_timed_thread) {
- NORM_ERR("Error creating %s timed thread", text);
- }
- timed_thread_register(info.mail->p_timed_thread,
- &info.mail->p_timed_thread);
- if (timed_thread_run(info.mail->p_timed_thread)) {
- NORM_ERR("Error running %s timed thread", text);
- }
- }
- return info.mail;
- } else if (obj->data.mail) {
- // this means we use obj
- if (!obj->data.mail->p_timed_thread) {
- obj->data.mail->p_timed_thread =
- timed_thread_create(thread,
- (void *) obj->data.mail,
- obj->data.mail->interval * 1000000);
- if (!obj->data.mail->p_timed_thread) {
- NORM_ERR("Error creating %s timed thread", text);
- }
- timed_thread_register(obj->data.mail->p_timed_thread,
- &obj->data.mail->p_timed_thread);
- if (timed_thread_run(obj->data.mail->p_timed_thread)) {
- NORM_ERR("Error running %s timed thread", text);
- }
- }
- return obj->data.mail;
- } else if (!obj->a) {
- // something is wrong, warn once then stop
- NORM_ERR("There's a problem with your mail settings. "
- "Check that the global mail settings are properly defined"
- " (line %li).", obj->line);
- obj->a++;
- }
- return NULL;
-}
-
char *format_time(unsigned long timeval, const int width)
{
char buf[10];
print_texeci(obj, p, p_max_size);
}
OBJ(imap_unseen) {
- struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
-
- if (mail && mail->p_timed_thread) {
- timed_thread_lock(mail->p_timed_thread);
- snprintf(p, p_max_size, "%lu", mail->unseen);
- timed_thread_unlock(mail->p_timed_thread);
- }
+ print_imap_unseen(obj, p, p_max_size);
}
OBJ(imap_messages) {
- struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
-
- if (mail && mail->p_timed_thread) {
- timed_thread_lock(mail->p_timed_thread);
- snprintf(p, p_max_size, "%lu", mail->messages);
- timed_thread_unlock(mail->p_timed_thread);
- }
+ print_imap_messages(obj, p, p_max_size);
}
OBJ(pop3_unseen) {
- struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
-
- if (mail && mail->p_timed_thread) {
- timed_thread_lock(mail->p_timed_thread);
- snprintf(p, p_max_size, "%lu", mail->unseen);
- timed_thread_unlock(mail->p_timed_thread);
- }
+ print_pop3_unseen(obj, p, p_max_size);
}
OBJ(pop3_used) {
- struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
-
- if (mail && mail->p_timed_thread) {
- timed_thread_lock(mail->p_timed_thread);
- snprintf(p, p_max_size, "%.1f",
- mail->used / 1024.0 / 1024.0);
- timed_thread_unlock(mail->p_timed_thread);
- }
+ print_pop3_used(obj, p, p_max_size);
}
OBJ(fs_bar) {
print_fs_bar(obj, 0, p, p_max_size);
END OBJ(apm_battery_time, 0)
#endif /* __FreeBSD__ */
END OBJ(imap_unseen, 0)
- if (arg) {
- // proccss
- obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
- obj->char_b = 0;
- } else {
- obj->char_b = 1;
- }
+ parse_imap_mail_args(obj, arg);
END OBJ(imap_messages, 0)
- if (arg) {
- // proccss
- obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
- obj->char_b = 0;
- } else {
- obj->char_b = 1;
- }
+ parse_imap_mail_args(obj, arg);
END OBJ(pop3_unseen, 0)
- if (arg) {
- // proccss
- obj->data.mail = parse_mail_args(POP3_TYPE, arg);
- obj->char_b = 0;
- } else {
- obj->char_b = 1;
- }
+ parse_pop3_mail_args(obj, arg);
END OBJ(pop3_used, 0)
- if (arg) {
- // proccss
- obj->data.mail = parse_mail_args(POP3_TYPE, arg);
- obj->char_b = 0;
- } else {
- obj->char_b = 1;
- }
+ parse_pop3_mail_args(obj, arg);
#ifdef IBM
END OBJ_ARG(smapi, 0, "smapi needs an argument")
obj->data.s = strndup(arg, text_buffer_size);
free(data.local_mail.mbox);
break;
case OBJ_imap_unseen:
- if (!obj->char_b) {
- free(data.mail);
- }
- break;
case OBJ_imap_messages:
- if (!obj->char_b) {
- free(data.mail);
- }
- break;
case OBJ_pop3_unseen:
- if (!obj->char_b) {
- free(data.mail);
- }
- break;
case OBJ_pop3_used:
- if (!obj->char_b) {
- free(data.mail);
- }
+ free_mail_obj(obj);
break;
case OBJ_if_empty:
case OBJ_if_match:
#include "common.h"
#include "logging.h"
#include "mail.h"
+#include "text_object.h"
#include <errno.h>
#include <stdio.h>
return mail;
}
+void parse_imap_mail_args(struct text_object *obj, const char *arg)
+{
+ if (!arg) {
+ obj->char_b = 1;
+ return;
+ }
+ // proccss
+ obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
+ obj->char_b = 0;
+}
+
+void parse_pop3_mail_args(struct text_object *obj, const char *arg)
+{
+ if (!arg) {
+ obj->char_b = 1;
+ return;
+ }
+ // proccss
+ obj->data.mail = parse_mail_args(POP3_TYPE, arg);
+ obj->char_b = 0;
+}
+
+void free_mail_obj(struct text_object *obj)
+{
+ if (!obj->char_b) {
+ free(obj->data.mail);
+ }
+}
+
int imap_command(int sockfd, const char *command, char *response, const char *verify)
{
struct timeval fetchtimeout;
}
}
-void *imap_thread(void *arg)
+static inline struct mail_s *ensure_mail_thread(struct text_object *obj,
+ void *thread(void *), const char *text)
+{
+ if (obj->char_b && info.mail) {
+ // this means we use info
+ if (!info.mail->p_timed_thread) {
+ info.mail->p_timed_thread =
+ timed_thread_create(thread,
+ (void *) info.mail, info.mail->interval * 1000000);
+ if (!info.mail->p_timed_thread) {
+ NORM_ERR("Error creating %s timed thread", text);
+ }
+ timed_thread_register(info.mail->p_timed_thread,
+ &info.mail->p_timed_thread);
+ if (timed_thread_run(info.mail->p_timed_thread)) {
+ NORM_ERR("Error running %s timed thread", text);
+ }
+ }
+ return info.mail;
+ } else if (obj->data.mail) {
+ // this means we use obj
+ if (!obj->data.mail->p_timed_thread) {
+ obj->data.mail->p_timed_thread =
+ timed_thread_create(thread,
+ (void *) obj->data.mail,
+ obj->data.mail->interval * 1000000);
+ if (!obj->data.mail->p_timed_thread) {
+ NORM_ERR("Error creating %s timed thread", text);
+ }
+ timed_thread_register(obj->data.mail->p_timed_thread,
+ &obj->data.mail->p_timed_thread);
+ if (timed_thread_run(obj->data.mail->p_timed_thread)) {
+ NORM_ERR("Error running %s timed thread", text);
+ }
+ }
+ return obj->data.mail;
+ } else if (!obj->a) {
+ // something is wrong, warn once then stop
+ NORM_ERR("There's a problem with your mail settings. "
+ "Check that the global mail settings are properly defined"
+ " (line %li).", obj->line);
+ obj->a++;
+ }
+ return NULL;
+}
+
+static void *imap_thread(void *arg)
{
int sockfd, numbytes;
char recvbuf[MAXDATASIZE];
return 0;
}
+void print_imap_unseen(struct text_object *obj, char *p, int p_max_size)
+{
+ struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
+
+ if (mail && mail->p_timed_thread) {
+ timed_thread_lock(mail->p_timed_thread);
+ snprintf(p, p_max_size, "%lu", mail->unseen);
+ timed_thread_unlock(mail->p_timed_thread);
+ }
+}
+
+void print_imap_messages(struct text_object *obj, char *p, int p_max_size)
+{
+ struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
+
+ if (mail && mail->p_timed_thread) {
+ timed_thread_lock(mail->p_timed_thread);
+ snprintf(p, p_max_size, "%lu", mail->messages);
+ timed_thread_unlock(mail->p_timed_thread);
+ }
+}
+
int pop3_command(int sockfd, const char *command, char *response, const char *verify)
{
struct timeval fetchtimeout;
return 0;
}
-void *pop3_thread(void *arg)
+static void *pop3_thread(void *arg)
{
int sockfd, numbytes;
char recvbuf[MAXDATASIZE];
return 0;
}
+void print_pop3_unseen(struct text_object *obj, char *p, int p_max_size)
+{
+ struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
+
+ if (mail && mail->p_timed_thread) {
+ timed_thread_lock(mail->p_timed_thread);
+ snprintf(p, p_max_size, "%lu", mail->unseen);
+ timed_thread_unlock(mail->p_timed_thread);
+ }
+}
+
+void print_pop3_used(struct text_object *obj, char *p, int p_max_size)
+{
+ struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
+
+ if (mail && mail->p_timed_thread) {
+ timed_thread_lock(mail->p_timed_thread);
+ snprintf(p, p_max_size, "%.1f",
+ mail->used / 1024.0 / 1024.0);
+ timed_thread_unlock(mail->p_timed_thread);
+ }
+}
#include "timed_thread.h"
#include <time.h>
+/* forward declare to make gcc happy */
+struct text_object;
+
extern char *current_mail_spool;
struct mail_s { // for imap and pop3
#define POP3_TYPE 1
#define IMAP_TYPE 2
-struct mail_s *parse_mail_args(char type, const char *arg);
-void *imap_thread(void *arg);
-void *pop3_thread(void *arg);
+/* FIXME: this is here for the config leftovers only */
+struct mail_s *parse_mail_args(char, const char *);
+
+void parse_imap_mail_args(struct text_object *, const char *);
+void parse_pop3_mail_args(struct text_object *, const char *);
+void free_mail_obj(struct text_object *);
+void print_imap_unseen(struct text_object *, char *, int);
+void print_imap_messages(struct text_object *, char *, int);
+void print_pop3_unseen(struct text_object *, char *, int);
+void print_pop3_used(struct text_object *, char *, int);
#endif /* _MAIL_H */