/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
+ * vim: ts=4 sw=4 noet ai cindent syntax=c
*
* Conky, a system monitor, based on torsmo
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
- * vim: ts=4 sw=4 noet ai cindent syntax=c
- *
*/
#include "config.h"
mail->last_update = current_update_time;
}
- if (stat(mail->box, &st)) {
+ if (stat(mail->mbox, &st)) {
static int rep = 0;
if (!rep) {
- ERR("can't stat %s: %s", mail->box, strerror(errno));
+ NORM_ERR("can't stat %s: %s", mail->mbox, strerror(errno));
rep = 1;
}
return;
mail->forwarded_mail_count = mail->unforwarded_mail_count = 0;
mail->replied_mail_count = mail->unreplied_mail_count = 0;
mail->draft_mail_count = mail->trashed_mail_count = 0;
- dirname = (char *) malloc(sizeof(char) * (strlen(mail->box) + 5));
+ dirname = (char *) malloc(sizeof(char) * (strlen(mail->mbox) + 5));
if (!dirname) {
- ERR("malloc");
+ NORM_ERR("malloc");
return;
}
- strcpy(dirname, mail->box);
+ strcpy(dirname, mail->mbox);
strcat(dirname, "/");
/* checking the cur subdirectory */
strcat(dirname, "cur");
dir = opendir(dirname);
if (!dir) {
- ERR("cannot open directory");
+ NORM_ERR("cannot open directory");
free(dirname);
return;
}
mail->mail_count++;
mailflags = (char *) malloc(sizeof(char) * strlen(strrchr(dirent->d_name, ',')));
if (!mailflags) {
- ERR("malloc");
+ NORM_ERR("malloc");
free(dirname);
return;
}
dir = opendir(dirname);
if (!dir) {
- ERR("cannot open directory");
+ NORM_ERR("cannot open directory");
free(dirname);
return;
}
mail->replied_mail_count = mail->unreplied_mail_count = -1;
mail->draft_mail_count = mail->trashed_mail_count = -1;
- fp = open_file(mail->box, &rep);
+ fp = open_file(mail->mbox, &rep);
if (!fp) {
return;
}
if (sscanf(arg, "%128s %128s %128s", mail->host, mail->user, mail->pass)
!= 3) {
if (type == POP3_TYPE) {
- ERR("Scanning POP3 args failed");
+ NORM_ERR("Scanning POP3 args failed");
} else if (type == IMAP_TYPE) {
- ERR("Scanning IMAP args failed");
+ NORM_ERR("Scanning IMAP args failed");
}
return 0;
}
int imap_command(int sockfd, const char *command, char *response, const char *verify)
{
- struct timeval timeout;
+ struct timeval fetchtimeout;
fd_set fdset;
int res, numbytes = 0;
if (send(sockfd, command, strlen(command), 0) == -1) {
perror("send");
return -1;
}
- timeout.tv_sec = 60; // 60 second timeout i guess
- timeout.tv_usec = 0;
+ fetchtimeout.tv_sec = 60; // 60 second timeout i guess
+ fetchtimeout.tv_usec = 0;
FD_ZERO(&fdset);
FD_SET(sockfd, &fdset);
- res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
+ res = select(sockfd + 1, &fdset, NULL, NULL, &fetchtimeout);
if (res > 0) {
if ((numbytes = recv(sockfd, response, MAXDATASIZE - 1, 0)) == -1) {
perror("recv");
reply += 2;
*strchr(reply, ')') = '\0';
if (reply == NULL) {
- ERR("Error parsing IMAP response: %s", recvbuf);
+ NORM_ERR("Error parsing IMAP response: %s", recvbuf);
return -1;
} else {
timed_thread_lock(mail->p_timed_thread);
#ifdef HAVE_GETHOSTBYNAME_R
if (gethostbyname_r(mail->host, &he, hostbuff, sizeof(hostbuff), &he_res, &he_errno)) { // get the host info
- ERR("IMAP gethostbyname_r: %s", hstrerror(h_errno));
+ NORM_ERR("IMAP gethostbyname_r: %s", hstrerror(h_errno));
exit(EXIT_FAILURE);
}
#else /* HAVE_GETHOSTBYNAME_R */
}
#endif /* HAVE_GETHOSTBYNAME_R */
while (fail < mail->retries) {
- struct timeval timeout;
+ struct timeval fetchtimeout;
int res;
fd_set fdset;
if (fail > 0) {
- ERR("Trying IMAP connection again for %s@%s (try %u/%u)",
+ NORM_ERR("Trying IMAP connection again for %s@%s (try %u/%u)",
mail->user, mail->host, fail + 1, mail->retries);
}
do {
break;
}
- timeout.tv_sec = 60; // 60 second timeout i guess
- timeout.tv_usec = 0;
+ fetchtimeout.tv_sec = 60; // 60 second timeout i guess
+ fetchtimeout.tv_usec = 0;
FD_ZERO(&fdset);
FD_SET(sockfd, &fdset);
- res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
+ res = select(sockfd + 1, &fdset, NULL, NULL, &fetchtimeout);
if (res > 0) {
if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
perror("recv");
break;
}
} else {
- ERR("IMAP connection failed: timeout");
+ NORM_ERR("IMAP connection failed: timeout");
fail++;
break;
}
recvbuf[numbytes] = '\0';
DBGP2("imap_thread() received: %s", recvbuf);
if (strstr(recvbuf, "* OK") != recvbuf) {
- ERR("IMAP connection failed, probably not an IMAP server");
+ NORM_ERR("IMAP connection failed, probably not an IMAP server");
fail++;
break;
}
+ strncpy(sendbuf, "abc CAPABILITY\r\n", MAXDATASIZE);
+ if (imap_command(sockfd, sendbuf, recvbuf, "abc OK")) {
+ fail++;
+ break;
+ }
+ if (strstr(recvbuf, " IDLE ") != NULL) {
+ has_idle = 1;
+ }
+
strncpy(sendbuf, "a1 login ", MAXDATASIZE);
strncat(sendbuf, mail->user, MAXDATASIZE - strlen(sendbuf) - 1);
strncat(sendbuf, " ", MAXDATASIZE - strlen(sendbuf) - 1);
fail++;
break;
}
- if (strstr(recvbuf, " IDLE ") != NULL) {
- has_idle = 1;
- }
strncpy(sendbuf, "a2 STATUS ", MAXDATASIZE);
strncat(sendbuf, mail->folder, MAXDATASIZE - strlen(sendbuf) - 1);
* RFC 2177 says we have to re-idle every 29 minutes.
* We'll do it every 20 minutes to be safe.
*/
- timeout.tv_sec = 1200;
- timeout.tv_usec = 0;
+ fetchtimeout.tv_sec = 1200;
+ fetchtimeout.tv_usec = 0;
DBGP2("idling...");
FD_ZERO(&fdset);
FD_SET(sockfd, &fdset);
* something other than 0, or we had a timeout
*/
buf = recvbuf;
- if (recent > 0 || (buf && strstr(buf, " FETCH ")) || timeout.tv_sec == 0 || force_check) {
+ if (recent > 0 || (buf && strstr(buf, " FETCH ")) || fetchtimeout.tv_sec == 0 || force_check) {
// re-check messages and unseen
if (imap_command(sockfd, "DONE\r\n", recvbuf, "a5 OK")) {
fail++;
fail++;
break;
}
- timeout.tv_sec = 60; // 60 second timeout i guess
- timeout.tv_usec = 0;
+ fetchtimeout.tv_sec = 60; // 60 second timeout i guess
+ fetchtimeout.tv_usec = 0;
FD_ZERO(&fdset);
FD_SET(sockfd, &fdset);
- res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
+ res = select(sockfd + 1, &fdset, NULL, NULL, &fetchtimeout);
if (res > 0) {
if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
perror("recv a3");
recvbuf[numbytes] = '\0';
DBGP2("imap_thread() received: %s", recvbuf);
if (strstr(recvbuf, "a3 OK") == NULL) {
- ERR("IMAP logout failed: %s", recvbuf);
+ NORM_ERR("IMAP logout failed: %s", recvbuf);
fail++;
break;
}
int pop3_command(int sockfd, const char *command, char *response, const char *verify)
{
- struct timeval timeout;
+ struct timeval fetchtimeout;
fd_set fdset;
int res, numbytes = 0;
if (send(sockfd, command, strlen(command), 0) == -1) {
perror("send");
return -1;
}
- timeout.tv_sec = 60; // 60 second timeout i guess
- timeout.tv_usec = 0;
+ fetchtimeout.tv_sec = 60; // 60 second timeout i guess
+ fetchtimeout.tv_usec = 0;
FD_ZERO(&fdset);
FD_SET(sockfd, &fdset);
- res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
+ res = select(sockfd + 1, &fdset, NULL, NULL, &fetchtimeout);
if (res > 0) {
if ((numbytes = recv(sockfd, response, MAXDATASIZE - 1, 0)) == -1) {
perror("recv");
#ifdef HAVE_GETHOSTBYNAME_R
if (gethostbyname_r(mail->host, &he, hostbuff, sizeof(hostbuff), &he_res, &he_errno)) { // get the host info
- ERR("POP3 gethostbyname_r: %s", hstrerror(h_errno));
+ NORM_ERR("POP3 gethostbyname_r: %s", hstrerror(h_errno));
exit(EXIT_FAILURE);
}
#else /* HAVE_GETHOSTBYNAME_R */
}
#endif /* HAVE_GETHOSTBYNAME_R */
while (fail < mail->retries) {
- struct timeval timeout;
+ struct timeval fetchtimeout;
int res;
fd_set fdset;
if (fail > 0) {
- ERR("Trying POP3 connection again for %s@%s (try %u/%u)",
+ NORM_ERR("Trying POP3 connection again for %s@%s (try %u/%u)",
mail->user, mail->host, fail + 1, mail->retries);
}
do {
break;
}
- timeout.tv_sec = 60; // 60 second timeout i guess
- timeout.tv_usec = 0;
+ fetchtimeout.tv_sec = 60; // 60 second timeout i guess
+ fetchtimeout.tv_usec = 0;
FD_ZERO(&fdset);
FD_SET(sockfd, &fdset);
- res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
+ res = select(sockfd + 1, &fdset, NULL, NULL, &fetchtimeout);
if (res > 0) {
if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
perror("recv");
break;
}
} else {
- ERR("POP3 connection failed: timeout\n");
+ NORM_ERR("POP3 connection failed: timeout\n");
fail++;
break;
}
DBGP2("pop3_thread received: %s", recvbuf);
recvbuf[numbytes] = '\0';
if (strstr(recvbuf, "+OK ") != recvbuf) {
- ERR("POP3 connection failed, probably not a POP3 server");
+ NORM_ERR("POP3 connection failed, probably not a POP3 server");
fail++;
break;
}
strncat(sendbuf, mail->pass, MAXDATASIZE - strlen(sendbuf) - 1);
strncat(sendbuf, "\r\n", MAXDATASIZE - strlen(sendbuf) - 1);
if (pop3_command(sockfd, sendbuf, recvbuf, "+OK ")) {
- ERR("POP3 server login failed: %s", recvbuf);
+ NORM_ERR("POP3 server login failed: %s", recvbuf);
fail++;
break;
}
// now we get the data
reply = recvbuf + 4;
if (reply == NULL) {
- ERR("Error parsing POP3 response: %s", recvbuf);
+ NORM_ERR("Error parsing POP3 response: %s", recvbuf);
fail++;
break;
} else {
strncpy(sendbuf, "QUIT\r\n", MAXDATASIZE);
if (pop3_command(sockfd, sendbuf, recvbuf, "+OK")) {
- ERR("POP3 logout failed: %s", recvbuf);
+ NORM_ERR("POP3 logout failed: %s", recvbuf);
fail++;
break;
}