<commit_before>/* ==================================================================
 * FILE     mail.c (Project: dwmstatus)
 * MACHINE  all
 * INFO     dwm statusline in C
 *          based on the suckless dwmstatus project under
 *          git://git.suckless.org/dwmstatus,
 *          and alsa stuff from https://github.com/Unia/dwmst
 *
 *          Attention: dwmstatus is likely to crash when suspending 
 *          computer while it is not in sleep() state. Therefore, 
 *          we have to run a custom systemd service (or bash script) 
 *          which kills it (if necessary) and re-runs it after 
 *          waking up.
 *
 * DATE     02.05.2014
 * OWNER    Bischofberger
 * ==================================================================
 */

/* TODO: better error handling
 */

#include <string.h>
#include <dirent.h>  /* check directory for new files */

#include "dwmstatus.h"

mailbox initmail(char *machine)
{
    mailbox tmp;

    if(!strcmp("laptop", machine)) {
        tmp.mail_fast = MAIL_LAP_FAST;
        tmp.mail_uzh  = MAIL_LAP_UZH;
        tmp.mail_zhaw = MAIL_LAP_ZHAW;
        return tmp;
    }
    else if(!strcmp("desktop", machine)) {
        tmp.mail_fast = MAIL_DESK_FAST;
        tmp.mail_uzh  = MAIL_DESK_UZH;
        tmp.mail_zhaw = MAIL_DESK_ZHAW;
        return tmp;
    }
    else {
        die("initmail: invalid argument\n");
    }
    return tmp;
}

char *get_nmail(char *directory)
{
    /* directory : Maildir path */
    int n = 0;
    DIR* dir = NULL;
    struct dirent* rf = NULL;

    dir = opendir(directory);  /* try to open directory */
    if (dir == NULL) {
        perror("");
    }
    while ((rf = readdir(dir)) != NULL) {  /*count number of files */
        if (strcmp(rf->d_name, ".") != 0 && strcmp(rf->d_name, "..") != 0) {
            n++;<commit_msg>better mail error handling<commit_after>/* ==================================================================
 * FILE     mail.c (Project: dwmstatus)
 * MACHINE  all
 * INFO     dwm statusline in C
 *          based on the suckless dwmstatus project under
 *          git://git.suckless.org/dwmstatus,
 *          and alsa stuff from https://github.com/Unia/dwmst
 *
 *          Attention: dwmstatus is likely to crash when suspending 
 *          computer while it is not in sleep() state. Therefore, 
 *          we have to run a custom systemd service (or bash script) 
 *          which kills it (if necessary) and re-runs it after 
 *          waking up.
 *
 * DATE     09.05.2014
 * OWNER    Bischofberger
 * ==================================================================
 */

/* TODO: better error handling
 */

#include <string.h>
#include <dirent.h>  /* check directory for new files */

#include "dwmstatus.h"

mailbox initmail(char *machine)
{
    mailbox tmp;

    if(!strcmp("laptop", machine)) {
        tmp.mail_fast = MAIL_LAP_FAST;
        tmp.mail_uzh  = MAIL_LAP_UZH;
        tmp.mail_zhaw = MAIL_LAP_ZHAW;
        return tmp;
    }
    else if(!strcmp("desktop", machine)) {
        tmp.mail_fast = MAIL_DESK_FAST;
        tmp.mail_uzh  = MAIL_DESK_UZH;
        tmp.mail_zhaw = MAIL_DESK_ZHAW;
        return tmp;
    }
    else {
        die("initmail: invalid argument\n");
    }
    return tmp;
}

char *get_nmail(char *directory)
{
    /* directory : Maildir path */
    int n = 0;
    DIR* dir = NULL;
    struct dirent* rf = NULL;

    dir = opendir(directory);  /* try to open directory */
    if (dir == NULL) {
        return smprintf("e");
    }
    while ((rf = readdir(dir)) != NULL) {  /*count number of files */
        if (strcmp(rf->d_name, ".") != 0 && strcmp(rf->d_name, "..") != 0) {
            n++;
{'fraction_non_alphanumeric': 0.18673218673218672, 'fraction_numerical': 0.006006006006006006, 'mean_word_length': 2.3583868010999085, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7673915', 'n_tokens_mistral': 1224, 'n_tokens_neox': 1165, 'n_words': 313}