+
+ return is_spam;
+}
+
+static gboolean mail_filtering_hook(gpointer source, gpointer data)
+{
+ MailFilteringData *mail_filtering_data = (MailFilteringData *) source;
+ MsgInfo *msginfo = mail_filtering_data->msginfo;
+ gboolean is_spam = FALSE;
+ FILE *fp = NULL;
+ int pid = 0;
+ int status;
+
+ if (!config.enable)
+ return FALSE;
+
+ debug_print("Filtering message %d\n", msginfo->msgnum);
+
+ if ((fp = procmsg_open_message(msginfo)) == NULL) {
+ debug_print("failed to open message file\n");
+ return FALSE;
+ }
+
+ pid = fork();
+ if (pid == 0) {
+ _exit(msg_is_spam(fp) ? 1 : 0);
+ } else {
+ gint running = 0;
+
+ running |= CHILD_RUNNING;
+
+ g_timeout_add(1000, timeout_func, &running);
+ running |= TIMEOUT_RUNNING;
+
+ while(running & CHILD_RUNNING) {
+ waitpid(pid, &status, WNOHANG);
+ if (WIFEXITED(status)) {
+ running &= ~CHILD_RUNNING;
+ }
+
+ g_main_iteration(TRUE);
+ }
+
+ while (running & TIMEOUT_RUNNING)
+ g_main_iteration(TRUE);
+ }
+ is_spam = WEXITSTATUS(status) == 1 ? TRUE : FALSE;
+