make unit of all temperatures selectable
[monky] / src / mail.c
index a7f0fd1..8ce47a2 100644 (file)
@@ -1,5 +1,4 @@
-/*
- * Conky, a system monitor, based on torsmo
+/* Conky, a system monitor, based on torsmo
  *
  * Any original torsmo code is licensed under the BSD license
  *
@@ -8,7 +7,8 @@
  * Please see COPYING for details
  *
  * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
- * Copyright (c) 2005-2007 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS)
+ * Copyright (c) 2005-2008 Brenden Matthews, Philip Kovacs, et. al.
+ *     (see AUTHORS)
  * All rights reserved.
  *
  * This program is free software: you can redistribute it and/or modify
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>. 
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
- *  $Id$
- */
+ * $Id$ */
 
 #include <sys/stat.h>
 #include <sys/time.h>
 
 #include <dirent.h>
 #include <errno.h>
-#include <stdio.h>
-#include <string.h>
 
 #include "conky.h"
 
@@ -40,39 +37,39 @@ char *current_mail_spool;
 
 void update_mail_count(struct local_mail_s *mail)
 {
-       struct stat buf;
+       struct stat st;
 
-       if (mail == NULL)
+       if (mail == NULL) {
                return;
+       }
 
        /* TODO: use that fine file modification notify on Linux 2.4 */
 
        /* don't check mail so often (9.5s is minimum interval) */
-       if (current_update_time - mail->last_update < 9.5)
+       if (current_update_time - mail->last_update < 9.5) {
                return;
-       else
+       } else {
                mail->last_update = current_update_time;
+       }
 
-       if (stat(mail->box, &buf)) {
+       if (stat(mail->box, &st)) {
                static int rep;
+
                if (!rep) {
-                       ERR("can't stat %s: %s", mail->box,
-                           strerror(errno));
+                       ERR("can't stat %s: %s", mail->box, strerror(errno));
                        rep = 1;
                }
                return;
        }
 #if HAVE_DIRENT_H
        /* maildir format */
-       if (S_ISDIR(buf.st_mode)) {
+       if (S_ISDIR(st.st_mode)) {
                DIR *dir;
                char *dirname;
                struct dirent *dirent;
 
                mail->mail_count = mail->new_mail_count = 0;
-               dirname =
-                   (char *) malloc(sizeof(char) *
-                                   (strlen(mail->box) + 5));
+               dirname = (char *) malloc(sizeof(char) * (strlen(mail->box) + 5));
                if (!dirname) {
                        ERR("malloc");
                        return;
@@ -123,7 +120,7 @@ void update_mail_count(struct local_mail_s *mail)
        }
 #endif
        /* mbox format */
-       if (buf.st_mtime != mail->last_mtime) {
+       if (st.st_mtime != mail->last_mtime) {
                /* yippee, modification time has changed, let's read mail count! */
                static int rep;
                FILE *fp;
@@ -135,43 +132,46 @@ void update_mail_count(struct local_mail_s *mail)
                mail->new_mail_count = mail->mail_count = 0;
 
                fp = open_file(mail->box, &rep);
-               if (!fp)
+               if (!fp) {
                        return;
+               }
 
                /* NOTE: adds mail as new if there isn't Status-field at all */
 
                while (!feof(fp)) {
                        char buf[128];
-                       if (fgets(buf, 128, fp) == NULL)
+
+                       if (fgets(buf, 128, fp) == NULL) {
                                break;
+                       }
 
                        if (strncmp(buf, "From ", 5) == 0) {
                                /* ignore MAILER-DAEMON */
-                               if (strncmp(buf + 5, "MAILER-DAEMON ", 14)
-                                   != 0) {
+                               if (strncmp(buf + 5, "MAILER-DAEMON ", 14) != 0) {
                                        mail->mail_count++;
 
-                                       if (reading_status)
+                                       if (reading_status) {
                                                mail->new_mail_count++;
-                                       else
+                                       } else {
                                                reading_status = 1;
+                                       }
                                }
                        } else {
                                if (reading_status
-                                   && strncmp(buf, "X-Mozilla-Status:",
-                                              17) == 0) {
+                                               && strncmp(buf, "X-Mozilla-Status:", 17) == 0) {
                                        /* check that mail isn't already read */
-                                       if (strchr(buf + 21, '0'))
+                                       if (strchr(buf + 21, '0')) {
                                                mail->new_mail_count++;
+                                       }
 
                                        reading_status = 0;
                                        continue;
                                }
-                               if (reading_status
-                                   && strncmp(buf, "Status:", 7) == 0) {
+                               if (reading_status && strncmp(buf, "Status:", 7) == 0) {
                                        /* check that mail isn't already read */
-                                       if (strchr(buf + 7, 'R') == NULL)
+                                       if (strchr(buf + 7, 'R') == NULL) {
                                                mail->new_mail_count++;
+                                       }
 
                                        reading_status = 0;
                                        continue;
@@ -179,15 +179,17 @@ void update_mail_count(struct local_mail_s *mail)
                        }
 
                        /* skip until \n */
-                       while (strchr(buf, '\n') == NULL && !feof(fp))
+                       while (strchr(buf, '\n') == NULL && !feof(fp)) {
                                fgets(buf, 128, fp);
+                       }
                }
 
                fclose(fp);
 
-               if (reading_status)
+               if (reading_status) {
                        mail->new_mail_count++;
+               }
 
-               mail->last_mtime = buf.st_mtime;
+               mail->last_mtime = st.st_mtime;
        }
 }