Commit 2ca6f6be 2ca6f6be2f00463dbb8f6e8f4af83387e00b9d14 by Alain Magloire

* mail/headers.c: Catch the overflow in the calculation by

	reseting the number of lines to default screen lines.
	* mail/mail.c (main): Add a "summary" call also for the
	initial commands on startup(in interactive).
	* mail.h: Proto for mail_summary() and mail_version().
	* table.c: Add mail_summary() and mail_version() in the cmd table.
	* util.c (util_getcols): First try an ioctl(TIOCGWINSZ,..) call
	not all shells set the COLUMNS environ.
	(util_getlines): Likewised. Also take to account the prompt
	in the lines number.
	* z.c (mail_z): Change the behaviour of "z." to show a screenfull
	when the lastpage is reach.  This is very practical when starting
	mail, since "z." is the initial command to show the header summary.
	* mail/version.c: New file, show mail version, mail_version().
	* mail/summary.c: New file, display a short summary of the mailbox.
	mail_summary().
	* mail/Makefile.am: add summary.c and version.c

	* mailbox2/include/mailutils/mbox.h: Proto for Unix-Mbox.
1 parent a26b5ba5
2001-07-03 Alain Magloire
* mail/headers.c: Catch the overflow in the calculation by
reseting the number of lines to default screen lines.
* mail/mail.c (main): Add a "summary" call also for the
initial commands on startup(in interactive).
* mail.h: Proto for mail_summary() and mail_version().
* table.c: Add mail_summary() and mail_version() in the cmd table.
* util.c (util_getcols): First try an ioctl(TIOCGWINSZ,..) call
not all shells set the COLUMNS environ.
(util_getlines): Likewised. Also take to account the prompt
in the lines number.
* z.c (mail_z): Change the behaviour of "z." to show a screenfull
when the lastpage is reach. This is very practical when starting
mail, since "z." is the initial command to show the header summary.
* mail/version.c: New file, show mail version, mail_version().
* mail/summary.c: New file, display a short summary of the mailbox.
mail_summary().
* mail/Makefile.am: add summary.c and version.c
* mailbox2/include/mailutils/mbox.h: Proto for Unix-Mbox.
2001-07-03 Jakob 'sparky' Kaivo <jkaivo@elijah.nodomainname.net>
* README-alpha: note that INSTALL is generated
......@@ -21,7 +43,7 @@
* mailbox/attribute.c: added attribute_set_modified() function.
Fixed attribute_unset.* functions to raise MU_ATTRIBUTE_MODIFIED bit.
* include/mailutils/attribute.h: Proto for attribute_set_modified().
2001-07-02 Alain Magloire
* mailbox2/tcp.c: make it thread-safe.
......
......@@ -12,5 +12,5 @@ mail_SOURCES = alias.c alt.c cd.c copy.c delete.c dp.c echo.c \
edit.c eq.c exit.c file.c folders.c followup.c from.c headers.c help.c \
hold.c if.c inc.c list.c mail.c mail.h mailline.c mbox.c next.c pipe.c \
previous.c print.c quit.c reply.c retain.c save.c send.c set.c shell.c \
size.c source.c table.c top.c touch.c unalias.c undelete.c unset.c util.c \
var.c visual.c write.c z.c
size.c source.c summary.c table.c top.c touch.c unalias.c undelete.c \
unset.c util.c var.c version.c visual.c write.c z.c
......
......@@ -34,6 +34,8 @@ mail_headers (int argc, char **argv)
int num = util_expand_msglist (argc, argv, &list);
lines = (lines / num) - 2;
if (lines < 0)
lines = util_screen_lines ();
if (lines < total)
{
......
......@@ -143,7 +143,7 @@ mail_cmdline(void *closure, int cont)
if (interactive)
prompt = pev->set && pev->value != NULL ? pev->value : "? ";
rc = readline (prompt);
if (ml_got_interrupt())
......@@ -157,7 +157,7 @@ mail_cmdline(void *closure, int cont)
util_error ("Use \"quit\" to quit.");
continue;
}
break;
}
return rc;
......@@ -252,7 +252,7 @@ main (int argc, char **argv)
util_do_command ("set noSign");
util_do_command ("set toplines=5");
util_do_command ("set autoinc");
/* GNU extensions to the environment, for sparky's sanity */
util_do_command ("set mode=read");
util_do_command ("set nobyname");
......@@ -336,7 +336,10 @@ main (int argc, char **argv)
/* initial commands */
if ((util_find_env("header"))->set)
{
util_do_command ("summary");
util_do_command ("z.");
}
prompt = util_find_env ("prompt");
mail_mainloop(mail_cmdline, (void*) prompt, 1);
......
......@@ -154,11 +154,13 @@ int mail_set __P((int argc, char **argv));
int mail_shell __P((int argc, char **argv));
int mail_size __P((int argc, char **argv));
int mail_source __P((int argc, char **argv));
int mail_summary __P((int argc, char **argv));
int mail_top __P((int argc, char **argv));
int mail_touch __P((int argc, char **argv));
int mail_unalias __P((int argc, char **argv));
int mail_undelete __P((int argc, char **argv));
int mail_unset __P((int argc, char **argv));
int mail_version __P((int argc, char **argv));
int mail_visual __P((int argc, char **argv));
int mail_warranty __P((int argc, char **argv));
int mail_write __P((int argc, char **argv));
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2001 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
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, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "mail.h"
/* Simple summary dysplaying a blurb on the name of the
mailbox and how many new:deleted:read messages.
The side effect is that is set the cursor/realcursor
to the newest or read message number. */
int
mail_summary (int argc, char **argv)
{
message_t msg;
attribute_t attr;
int msgno;
size_t count = 0;
int mseen = 0, mnew = 0, mdelete = 0;
int first_new = 0, first_unread = 0;
mailbox_messages_count (mbox, &count);
for (msgno = 1; msgno <= count; msgno++)
{
if ((mailbox_get_message (mbox, msgno, &msg) == 0)
&& (message_get_attribute (msg, &attr) == 0))
{
if (attribute_is_deleted (attr))
mdelete++;
if (attribute_is_seen (attr) && ! attribute_is_read (attr))
{
mseen++;
if (!first_unread)
first_unread = msgno;
}
if (attribute_is_recent (attr))
{
mnew++;
if (!first_new)
first_new = msgno;
}
}
}
/* Print the mailbox name. */
{
url_t url = NULL;
mailbox_get_url (mbox, &url);
printf("\"%s\": ", url_to_string (url));
}
printf("%d messages", count);
if (mnew > 0)
printf(" %d new", mnew);
if (mseen > 0)
printf(" %d unread", mseen);
if (mdelete > 0)
printf(" %d deleted", mdelete);
printf("\n");
/* Set the cursor. */
cursor = realcursor = (first_new == 0) ? ((first_unread == 0) ?
1 : first_unread) : first_new ;
}
......@@ -32,8 +32,8 @@ const struct mail_command_entry mail_command_table[] = {
{ "dt", "dt", 0, mail_dp, "dt [msglist]" },
{ "ec", "echo", 0, mail_echo, "ec[ho] string ..." },
{ "e", "edit", 0, mail_edit, "e[dit] [msglist]" },
{ "el", "else", EF_FLOW, mail_else, "el[se]" },
{ "en", "endif", EF_FLOW, mail_endif, "en[dif]" },
{ "el", "else", EF_FLOW, mail_else, "el[se]" },
{ "en", "endif", EF_FLOW, mail_endif, "en[dif]" },
{ "ex", "exit", 0, mail_exit, "ex[it]" },
{ "F", "Followup", EF_SEND, mail_followup,"F[ollowup] [msglist]" },
{ "fi", "file", 0, mail_file, "fi[le] [file]" },
......@@ -46,7 +46,7 @@ const struct mail_command_entry mail_command_table[] = {
{ "h", "headers", 0, mail_headers,"h[eaders] [msglist]" },
{ "hel", "help", 0, mail_help, "hel[p] [command...]" },
{ "ho", "hold", 0, mail_hold, "ho[ld] [msglist]" },
{ "i", "if", EF_FLOW, mail_if, "i[f] s|r|t" },
{ "i", "if", EF_FLOW, mail_if, "i[f] s|r|t" },
{ "ig", "ignore", 0, mail_discard,"ig[nore] [header-field...]" },
{ "inc", "incorporate", 0, mail_inc, "inc[orporate]" },
{ "l", "list", 0, mail_list, "l[ist]" },
......@@ -71,6 +71,7 @@ const struct mail_command_entry mail_command_table[] = {
{ "sh", "shell", 0, mail_shell, "sh[ell] [command]" },
{ "si", "size", 0, mail_size, "si[ze] [msglist]" },
{ "so", "source", 0, mail_source, "so[urce] file" },
{ "su", "summary", 0, mail_summary, "su[mmary]" },
{ "T", "Type", 0, mail_print, "T[ype] [msglist]" },
{ "to", "top", 0, mail_top, "to[p] [msglist]" },
{ "tou", "touch", 0, mail_touch, "tou[ch] [msglist]" },
......@@ -78,6 +79,7 @@ const struct mail_command_entry mail_command_table[] = {
{ "una", "unalias", 0, mail_unalias,"una[lias] [alias]..." },
{ "u", "undelete", 0, mail_undelete,"u[ndelete] [msglist]" },
{ "uns", "unset", 0, mail_unset, "uns[et] name..." },
{ "ve", "version", 0, mail_version, "ve[rsion]" },
{ "v", "visual", 0, mail_visual, "v[isual] [msglist]" },
{ "wa", "warranty", 0, mail_warranty,"wa[rranty]" },
{ "W", "Write", 0, mail_write, "W[rite] [msglist]" },
......
......@@ -18,6 +18,7 @@
#include "mail.h"
#include <mailutils/mutil.h>
#include <pwd.h>
#include <sys/ioctl.h>
typedef struct _node {
/* for the msglist expander */
......@@ -401,21 +402,41 @@ util_stripwhite (char *string)
}
/*
* get the number of columns on the screen
* Get the number of columns on the screen
* First try an ioctl() call not all shells set the COLUMNS environ.
*/
int
util_getcols (void)
{
return strtol (getenv("COLUMNS"), NULL, 10);
struct winsize ws;
ws.ws_col = ws.ws_row = 0;
if ((ioctl(1, TIOCGWINSZ, (char *) &ws) < 0)
|| ws.ws_row == 0)
ws.ws_col = strtol (getenv("COLUMNS"), NULL, 10);
/* FIXME: Should we exit()/abort() if col <= 0 ? */
return ws.ws_col;
}
/*
* get the number of lines on the screen
* Get the number of lines on the screen
* First try an ioctl() call not all shells set the LINES environ.
*/
int
util_getlines (void)
{
return strtol (getenv("LINES"), NULL, 10);
struct winsize ws;
ws.ws_col = ws.ws_row = 0;
if ((ioctl(1, TIOCGWINSZ, (char *) &ws) < 0)
|| ws.ws_row == 0)
ws.ws_row = strtol (getenv("LINES"), NULL, 10);
/* FIXME: Should we exit()/abort() if row <= 0 ? */
/* Reserve at least 2 line for the prompt. */
return ws.ws_row - 2;
}
int
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
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, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "mail.h"
/*
* ve[rsion]
*/
int
mail_version (int argc, char **argv)
{
fprintf (ofile, "%s\n", argp_program_version);
return 0;
}
......@@ -72,13 +72,13 @@ z_parse_args(int argc, char **argv, int *return_count, int *return_dir)
}
argc -= an;
if (argc > 1)
{
util_error("Too many arguments for the scrolling command");
return 1;
}
if (argp && *argp)
{
if (dir == D_NONE)
......@@ -95,10 +95,10 @@ z_parse_args(int argc, char **argv, int *return_count, int *return_dir)
}
}
*return_count = mul * count;
*return_dir = dir;
return 0;
}
......@@ -109,12 +109,12 @@ mail_z (int argc, char **argv)
unsigned int pagelines = util_screen_lines();
int count;
int dir;
if (z_parse_args(argc, argv, &count, &dir))
return 1;
nlines = pagelines;
count *= pagelines;
switch (dir)
{
......@@ -138,10 +138,10 @@ mail_z (int argc, char **argv)
}
cursor += count;
if (cursor + nlines > total)
nlines = total - cursor;
if (nlines <= 0)
{
fprintf(stdout, "On last screenful of messages\n");
......@@ -149,11 +149,35 @@ mail_z (int argc, char **argv)
}
case D_NONE:
{
/* z. is a GNU extension, so it will be more usefull
when we reach the last message to show a full screen
of the last message. This behaviour is use on startup
when displaying the summary and the headers, new messages
are last but we want to display a screenfull with the
real cursor set by symmary() to the new message. */
/* Find the start of the last screen page. */
int lastpage = total - pagelines + 1;
if (lastpage <= 0)
lastpage = 1;
if (cursor > lastpage)
{
realcursor = cursor;
cursor = lastpage;
for (i = 0; i < nlines; i++)
{
mail_from(0, NULL);
cursor++;
}
cursor = realcursor;
return 1;
}
}
break;
}
realcursor = cursor;
for (i = 0; i < nlines; i++)
{
mail_from(0, NULL);
......@@ -161,6 +185,6 @@ mail_z (int argc, char **argv)
}
cursor = realcursor;
return 1;
}
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Library Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef _MAILUTILS_MBOX_H
#define _MAILUTILS_MBOX_H
#include <mailutils/iterator.h>
#include <mailutils/stream.h>
#include <mailutils/message.h>
#include <mailutils/observer.h>
__MAILUTILS_BEGIN_DECLS
extern int mbox_create __P ((mbox_t));
extern int mbox_destroy __P ((mbox_t));
extern int mbox_uidvalidity __P ((mbox_t, unsigned long *));
extern int mbox_uidnext __P ((mbox_t, unsigned long));
extern int mbox_open __P ((mbox_t, const char *, int));
extern int mbox_close __P ((mbox_t));
extern int mbox_get_message __P ((mbox_t, unsigned int, message_t *));
extern int mbox_get_size __P ((mbox_t, unsigned long *));
extern int mbox_save_attributes __P ((mbox_t));
extern int mbox_expunge __P ((mbox_t));
extern int mbox_is_modified __P ((mbox_t));
extern int mbox_scan __P ((mbox_t, unsigned int, unsigned int *));
extern int mbox_get_count __P ((mbox_t, unsigned int *));
extern int mbox_get_oberver __P ((mbox_t, observer_t));
extern int mbox_append __P ((mbox_t, stream_t));
__MAILUTILS_END_DECLS
#endif /* _MAILUTILS_MBOX_H */