#include "ncrypt/ncrypt.h"
#include "opcodes.h"
#include "options.h"
+#include "pager.h"
#include "pattern.h"
#include "protos.h"
#include "sort.h"
break;
#endif /* USE_POP */
+ case OP_SHOW_MESSAGES:
+ {
+ char tempfile[PATH_MAX];
+ mutt_mktemp(tempfile, sizeof(tempfile));
+
+ FILE *fp = mutt_file_fopen(tempfile, "a+");
+ if (!fp)
+ {
+ mutt_perror("fopen");
+ break;
+ }
+
+ log_queue_save(fp);
+ mutt_file_fclose(&fp);
+
+ mutt_do_pager("messages", tempfile, MUTT_PAGER_LOGS, NULL);
+ break;
+ }
+
case OP_HELP:
mutt_help(MENU_MAIN);
};
const struct Binding OpMain[] = { /* map: index */
+ { "show-messages", OP_SHOW_MESSAGES, "M" },
{ "create-alias", OP_CREATE_ALIAS, "a" },
{ "bounce-message", OP_BOUNCE_MESSAGE, "b" },
{ "break-thread", OP_MAIN_BREAK_THREAD, "#" },
log_queue_empty();
}
+/**
+ * log_queue_save - Save the contents of the queue to a temporary file
+ * @param fp Open file handle
+ * @retval num Number of lines written to the file
+ *
+ * The queue is written to a temporary file. The format is:
+ * * `[HH:MM:SS]<LEVEL> FORMATTED-MESSAGE`
+ *
+ * @note The caller should free the returned string and delete the file.
+ */
+int log_queue_save(FILE *fp)
+{
+ if (!fp)
+ return 0;
+
+ char buf[32];
+ int count = 0;
+ struct LogLine *ll = NULL;
+ STAILQ_FOREACH(ll, &LogQueue, entries)
+ {
+ strftime(buf, sizeof(buf), "%H:%M:%S", localtime(&ll->time));
+ fprintf(fp, "[%s]<%c> %s", buf, LevelAbbr[ll->level + 3], ll->message);
+ if (ll->level <= 0)
+ fputs("\n", fp);
+ count++;
+ }
+
+ return count;
+}
+
/**
* log_disp_queue - Save a log line to an internal queue
* @param stamp Unix time
int log_queue_add(struct LogLine *ll);
void log_queue_empty(void);
void log_queue_flush(log_dispatcher_t disp);
+int log_queue_save(FILE *fp);
void log_queue_set_max_size(int size);
void log_file_close(bool verbose);
MT_COLOR_SB_INDICATOR,
MT_COLOR_SB_SPOOLFILE,
#endif
+ MT_COLOR_MESSAGE_LOG,
/* please no non-MT_COLOR_INDEX objects after this point */
MT_COLOR_INDEX,
MT_COLOR_INDEX_AUTHOR,
}
log_disp_file(stamp, file, line, function, level, "%s", buf);
+ if (stamp == 0)
+ log_disp_queue(stamp, file, line, function, level, "%s", buf);
/* Don't display debugging message on screen */
if (level > LL_MESSAGE)
#define OPS_CORE(_fmt) \
_fmt(OP_NULL, N_("null operation")) \
+ _fmt(OP_SHOW_MESSAGES, N_("show messages")) \
_fmt(OP_END_COND, N_("end of conditional execution (noop)")) \
_fmt(OP_ATTACH_VIEW_MAILCAP, N_("force viewing of attachment using mailcap")) \
_fmt(OP_ATTACH_VIEW_TEXT, N_("view attachment as text")) \
}
else
m = n;
- if (!(flags & MUTT_SHOWCOLOR))
+ if (flags & MUTT_PAGER_LOGS)
+ {
+ def_color = ColorDefs[(line_info[n].syntax)[0].color];
+ }
+ else if (!(flags & MUTT_SHOWCOLOR))
def_color = ColorDefs[MT_COLOR_NORMAL];
else if (line_info[m].type == MT_COLOR_HEADER)
def_color = (line_info[m].syntax)[0].color;
if (nl > 0)
buf[nl] = '\n';
}
+
+ if (line_info[n].type == MT_COLOR_MESSAGE_LOG)
+ {
+ line_info[n].chunks = 1;
+ line_info[n].syntax = mutt_mem_calloc(1, sizeof(struct Syntax));
+
+ (line_info[n].syntax)[i].color = MT_COLOR_ERROR;
+ (line_info[n].syntax)[i].first = 5;
+ (line_info[n].syntax)[i].last = 10;
+ }
}
static int is_ansi(unsigned char *buf)
}
}
+ if (flags & MUTT_PAGER_LOGS)
+ {
+ /* determine the line class */
+ if (fill_buffer(f, last_pos, (*line_info)[n].offset, &buf, &fmt, &buflen, &buf_ready) < 0)
+ {
+ if (change_last)
+ (*last)--;
+ goto out;
+ }
+
+ (*line_info)[n].type = MT_COLOR_MESSAGE_LOG;
+ if (buf[11] == 'M')
+ (*line_info)[n].syntax[0].color = MT_COLOR_MESSAGE;
+ else if (buf[11] == 'E')
+ (*line_info)[n].syntax[0].color = MT_COLOR_ERROR;
+ else
+ (*line_info)[n].syntax[0].color = MT_COLOR_NORMAL;
+ }
+
/* only do color highlighting if we are viewing a message */
if (flags & (MUTT_SHOWCOLOR | MUTT_TYPES))
{
#define MUTT_PAGER_MESSAGE (MUTT_SHOWCOLOR | MUTT_PAGER_MARKER)
#define MUTT_PAGER_ATTACHMENT (1 << 8)
#define MUTT_PAGER_NOWRAP (1 << 9) /**< format for term width, ignore $wrap */
+#define MUTT_PAGER_LOGS (1 << 10) /**< Logview mode */
-#define MUTT_DISPLAYFLAGS (MUTT_SHOW | MUTT_PAGER_NSKIP | MUTT_PAGER_MARKER)
+#define MUTT_DISPLAYFLAGS (MUTT_SHOW | MUTT_PAGER_NSKIP | MUTT_PAGER_MARKER | MUTT_PAGER_LOGS)
/**
* struct Pager - An email being displayed