Projects STRLCPY neomutt Commits 0600d109
🤬
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■ ■
    core/mailbox.c
    skipped 75 lines
    76 76   m->emails = mutt_mem_calloc(m->email_max, sizeof(struct Email *));
    77 77   m->v2r = mutt_mem_calloc(m->email_max, sizeof(int));
    78 78   m->gen = mailbox_gen();
     79 +#ifdef USE_DEVEL_NEW_MAIL
     80 + m->last_notified.tv_sec = 0;
     81 + m->last_notified.tv_nsec = 0;
     82 +#endif
    79 83   
    80 84   return m;
    81 85  }
    skipped 236 lines
  • ■ ■ ■ ■ ■ ■
    core/mailbox.h
    skipped 91 lines
    92 92   int msg_new; ///< Number of new messages
    93 93   int msg_deleted; ///< Number of deleted messages
    94 94   int msg_tagged; ///< How many messages are tagged?
     95 +#ifdef USE_DEVEL_NEW_MAIL
     96 + int msg_unnotified; ///< Number of messages we have not notified about
     97 +#endif
    95 98   
    96 99   struct Email **emails; ///< Array of Emails
    97 100   int email_max; ///< Number of pointers in emails
    skipped 6 lines
    104 107   struct timespec mtime; ///< Time Mailbox was last changed
    105 108   struct timespec last_visited; ///< Time of last exit from this mailbox
    106 109   struct timespec stats_last_checked; ///< Mtime of mailbox the last time stats where checked.
     110 +#ifdef USE_DEVEL_NEW_MAIL
     111 + struct timespec last_notified; ///< Time when the user was last notified about new messages.
     112 +#endif
    107 113   
    108 114   const struct MxOps *mx_ops; ///< MXAPI callback functions
    109 115   
    skipped 72 lines
    182 188   NT_MAILBOX_NEW_MAIL, ///< New messages have been added
    183 189  };
    184 190   
    185  -ARRAY_HEAD(EmailArray, struct Email *);
    186  - 
    187 191  /**
    188 192   * struct EventMailbox - An Event that happened to a Mailbox
    189 193   */
    190 194  struct EventMailbox
    191 195  {
    192 196   struct Mailbox *mailbox; ///< The Mailbox this Event relates to
    193  - struct EmailArray emails; ///< List of emails associated with the event
    194 197  };
    195 198   
    196 199  void mailbox_changed (struct Mailbox *m, enum NotifyMailbox action);
    skipped 26 lines
  • ■ ■ ■ ■ ■ ■
    maildir/maildir.c
    skipped 45 lines
    46 46  #include <utime.h>
    47 47  #include "private.h"
    48 48  #include "mutt/lib.h"
     49 +#include "mutt/notify.h"
    49 50  #include "config/lib.h"
    50 51  #include "email/lib.h"
    51 52  #include "core/lib.h"
    52 53  #include "lib.h"
     54 +#include "newmail/lib.h"
    53 55  #include "progress/lib.h"
    54 56  #include "copy.h"
    55 57  #include "edata.h"
    skipped 38 lines
    94 96   struct Buffer *path = mutt_buffer_pool_get();
    95 97   struct Buffer *msgpath = mutt_buffer_pool_get();
    96 98   mutt_buffer_printf(path, "%s/%s", mailbox_path(m), dir_name);
     99 + 
     100 +#ifdef USE_DEVEL_NEW_MAIL
     101 + bool check_unnotified = check_new;
     102 +#endif
    97 103   
    98 104   /* when $mail_check_recent is set, if the new/ directory hasn't been modified since
    99 105   * the user last exited the m, then we know there is no recent mail. */
    skipped 36 lines
    136 142   {
    137 143   if (check_stats)
    138 144   m->msg_unread++;
     145 + 
     146 +#ifdef USE_DEVEL_NEW_MAIL
     147 + if (check_unnotified)
     148 + {
     149 + struct timespec created;
     150 + mutt_buffer_printf(msgpath, "%s/%s", mutt_buffer_string(path), de->d_name);
     151 + stat(mutt_buffer_string(msgpath), &st);
     152 + mutt_file_get_stat_timespec(&created, &st, MUTT_STAT_CTIME);
     153 + if (mutt_file_timespec_compare(&m->last_notified, &created) < 0)
     154 + {
     155 + mutt_debug(LL_DEBUG1, "Unnotified %s/%s\n", mutt_buffer_string(path), de->d_name);
     156 + m->msg_unnotified++;
     157 + }
     158 + }
     159 +#endif
     160 + 
    139 161   if (check_new)
    140 162   {
    141 163   if (c_mail_check_recent)
    skipped 1211 lines
    1353 1375   m->msg_unread = 0;
    1354 1376   m->msg_flagged = 0;
    1355 1377   m->msg_new = 0;
     1378 +#ifdef USE_DEVEL_NEW_MAIL
     1379 + m->msg_unnotified = 0;
     1380 +#endif
    1356 1381   }
    1357 1382   
    1358 1383   maildir_check_dir(m, "new", check_new, check_stats);
    skipped 2 lines
    1361 1386   check_new = !m->has_new && c_maildir_check_cur;
    1362 1387   if (check_new || check_stats)
    1363 1388   maildir_check_dir(m, "cur", check_new, check_stats);
     1389 + 
     1390 +#ifdef USE_DEVEL_NEW_MAIL
     1391 + if (check_stats && m->msg_unnotified > 0)
     1392 + {
     1393 + mutt_debug(LL_DEBUG1, "Unnotified = %d\n", m->msg_unnotified);
     1394 + struct EventMailbox ev_m = { m };
     1395 + notify_send(m->notify, NT_MAILBOX, NT_MAILBOX_NEW_MAIL, &ev_m);
     1396 + clock_gettime(CLOCK_REALTIME, &m->last_notified);
     1397 + mutt_debug(LL_DEBUG2, "resetting time\n");
     1398 + }
     1399 +#endif
    1364 1400   
    1365 1401   return m->msg_new ? MX_STATUS_NEW_MAIL : MX_STATUS_OK;
    1366 1402  }
    skipped 307 lines
  • ■ ■ ■ ■ ■ ■
    mx.c
    skipped 84 lines
    85 85  #include <xlocale.h>
    86 86  #endif
    87 87   
    88  -#ifdef USE_DEVEL_NEW_MAIL
    89  -static time_t LastNotified = 0; ///< Time of last new mail notification.
    90  -#endif
    91  - 
    92 88  static const struct Mapping MboxTypeMap[] = {
    93 89   // clang-format off
    94 90   { "mbox", MUTT_MBOX, },
    skipped 1028 lines
    1123 1119  }
    1124 1120   
    1125 1121  /**
    1126  - * find_new_emails - XXX
    1127  - */
    1128  -void find_new_emails(const struct Mailbox *mailbox, time_t last_notified,
    1129  - struct EmailArray *emails)
    1130  -{
    1131  - mutt_debug(LL_DEBUG1, "Mailbox: %s\n", mailbox_path(mailbox));
    1132  - mutt_debug(LL_DEBUG1, "MSG COUNT: %d\n", mailbox->msg_count);
    1133  - mutt_debug(LL_DEBUG1, "Unread: %d\n", mailbox->msg_unread);
    1134  - for (int i = 0; i < mailbox->msg_count; i++)
    1135  - {
    1136  - struct Email *email = mailbox->emails[i];
    1137  - mutt_debug(LL_DEBUG1, "msg(%d): %d\n", i, email);
    1138  - // if (last_notified < mailbox->emails[i]->received)
    1139  - // ARRAY_ADD(emails, mailbox->emails[i]);
    1140  - }
    1141  -}
    1142  - 
    1143  -/**
    1144 1122   * mx_mbox_check - Check for new mail - Wrapper for MxOps::mbox_check()
    1145 1123   * @param m Mailbox
    1146 1124   * @retval enum #MxStatus
    skipped 8 lines
    1155 1133   {
    1156 1134   mailbox_changed(m, NT_MAILBOX_INVALID);
    1157 1135   }
    1158  -#ifdef USE_DEVEL_NEW_MAIL
    1159  - if (rc == MX_STATUS_NEW_MAIL)
    1160  - {
    1161  - if (LastNotified > 0)
    1162  - {
    1163  - struct EventMailbox ev_m = { m, ARRAY_HEAD_INITIALIZER };
    1164  - find_new_emails(m, LastNotified, &ev_m.emails);
    1165  - if (!ARRAY_EMPTY(&ev_m.emails))
    1166  - notify_send(m->notify, NT_MAILBOX, NT_MAILBOX_NEW_MAIL, &ev_m);
    1167  - }
    1168  - LastNotified = mutt_date_epoch();
    1169  - }
    1170  -#endif
    1171 1136   
    1172 1137   return rc;
    1173 1138  }
    skipped 736 lines
  • ■ ■ ■ ■ ■
    newmail/lib.h
    skipped 24 lines
    25 25   
    26 26  #include <stdint.h>
    27 27  #include <stdio.h>
     28 +#include "mutt/lib.h"
    28 29  #include "format_flags.h"
    29 30   
    30 31  struct NotifyCallback;
    skipped 12 lines
  • ■ ■ ■ ■ ■ ■
    newmail/new_mail.c
    skipped 62 lines
    63 63  {
    64 64   struct EventMailbox *ev_m = (struct EventMailbox *) data;
    65 65   struct Mailbox *mailbox = ev_m->mailbox;
    66  - struct EmailArray *emails = &ev_m->emails;
    67 66   
    68 67   switch (op)
    69 68   {
    70  - case 'c':
    71  - snprintf(buf, buflen, "%ld", ARRAY_SIZE(emails));
     69 + case 'n':
     70 + snprintf(buf, buflen, "%d", mailbox->msg_unnotified);
     71 + break;
     72 + case 'N':
     73 + snprintf(buf, buflen, "%d", mailbox->msg_new);
    72 74   break;
    73 75   case 'f':
    74 76   snprintf(buf, buflen, "%s", NONULL(mailbox_path(mailbox)));
    75 77   break;
    76  - case 'n':
     78 + case 'F':
    77 79   snprintf(buf, buflen, "%s", NONULL(mailbox->name));
    78 80   break;
    79 81   case 'u':
    skipped 16 lines
    96 98   mutt_expando_format(expanded_cmd, 1024, 0, 1024, cmd, new_mail_format_str,
    97 99   (intptr_t) ev_m, MUTT_FORMAT_NO_FLAGS);
    98 100   execute(expanded_cmd);
    99  - ARRAY_FREE(&ev_m->emails);
    100 101   return 0;
    101 102  }
    102 103   
    skipped 15 lines
  • ■ ■ ■ ■ ■ ■
    test/newmail/new_mail_format_str.c
    skipped 41 lines
    42 42   mailbox->name = mutt_str_dup("MailBox");
    43 43   mailbox->pathbuf = mutt_buffer_make(16);
    44 44   mailbox->msg_unread = 7;
     45 + mailbox->msg_unnotified = 2;
     46 + mailbox->msg_new = 3;
    45 47   mutt_buffer_strcpy(&mailbox->pathbuf, "/path");
    46 48   
    47  - struct EventMailbox ev_m = { mailbox, ARRAY_HEAD_INITIALIZER };
    48  - ARRAY_ADD(&ev_m.emails, email_new());
    49  - ARRAY_ADD(&ev_m.emails, email_new());
     49 + struct EventMailbox ev_m = { mailbox };
    50 50   
    51 51   intptr_t data = (intptr_t) &ev_m;
    52 52   
    53  - new_mail_format_str((char *) buf, 64, col, cols, 'n', NULL, NULL, NULL, NULL, data, 0);
     53 + new_mail_format_str((char *) buf, 64, col, cols, 'F', NULL, NULL, NULL, NULL, data, 0);
    54 54   TEST_CHECK(mutt_str_equal(buf, "MailBox"));
    55 55   TEST_MSG("Check failed: %s != MailBox", buf);
    56 56   
    skipped 5 lines
    62 62   TEST_CHECK(mutt_str_equal(buf, "7"));
    63 63   TEST_MSG("Check failed: %s != 7", buf);
    64 64   
    65  - new_mail_format_str((char *) buf, 64, col, cols, 'c', NULL, NULL, NULL, NULL, data, 0);
     65 + new_mail_format_str((char *) buf, 64, col, cols, 'n', NULL, NULL, NULL, NULL, data, 0);
    66 66   TEST_CHECK(mutt_str_equal(buf, "2"));
    67 67   TEST_MSG("Check failed: %s != 2", buf);
    68 68   
    69  - struct Email **email;
    70  - ARRAY_FOREACH(email, &ev_m.emails)
    71  - {
    72  - email_free(email);
    73  - }
    74  - ARRAY_FREE(&ev_m.emails);
     69 + new_mail_format_str((char *) buf, 64, col, cols, 'N', NULL, NULL, NULL, NULL, data, 0);
     70 + TEST_CHECK(mutt_str_equal(buf, "3"));
     71 + TEST_MSG("Check failed: %s != 3", buf);
     72 + 
    75 73   mailbox_free(&mailbox);
    76 74  }
    77 75   
  • ■ ■ ■ ■
    test/newmail/new_mail_observer.c
    skipped 47 lines
    48 48   notify_observer_add(notify, NT_MAILBOX, dummy_new_mail_observer, NULL);
    49 49   struct Mailbox *mailbox = mailbox_new();
    50 50   mailbox->name = mutt_str_dup("Mailbox");
    51  - struct EventMailbox event = { mailbox, ARRAY_HEAD_INITIALIZER };
     51 + struct EventMailbox event = { mailbox };
    52 52   
    53 53   notify_send(notify, NT_MAILBOX, NT_MAILBOX_NEW_MAIL, NULL);
    54 54   TEST_CHECK(message == NULL);
    skipped 11 lines
Please wait...
Page is in error, reload to recover