diff -Nru wmail-2.2/ChangeLog wmail-2.3/ChangeLog --- wmail-2.2/ChangeLog 2019-06-13 07:46:22.000000000 +0000 +++ wmail-2.3/ChangeLog 2019-06-21 19:01:47.000000000 +0000 @@ -1,3 +1,53 @@ +2019-06-21 Jeremy Sowden + + * wmail/ChangeLog, wmail/README, wmail/configure.ac, + wmail/wmailrc-sample: wmail: updated change-log and bumped to 2.3. + +2019-06-21 Jeremy Sowden + + * wmail/src/wmail.c: wmail: fixed use-after-free. The CleanupNames() function removed the sender-addresses for deleted + mails, but did not set the namesChanged flag to true. This meant + that if the ticker was displaying the address of a mail which had + been deleted it would continue doing so after the address had been + freed. + +2019-06-13 Jeremy Sowden + + * wmail/src/config.c, wmail/src/wmail.c: wmail: handle allocation + failures. Check the return values of some invocations of malloc and strdup and + ensure that any NULL's are handled correctly. + +2019-06-13 Jeremy Sowden + + * wmail/src/config.c: wmail: fixed possible NULL-pointer dereference + in config-parser. The code calling Tokenize assumed that if it returned true, value + would not be NULL. However, in the case of a line containing no + equals sign: blah that would not be the case. Changed Tokenize to return false unless + id and value are both defined. + +2019-06-13 Jeremy Sowden + + * wmail/src/wmail.c: wmail: fixed NULL-pointer dereference if + opendir(3) fails. Code was: if (( dir = opendir( ... ))) { // ... } closedir( dir ); // dir may be NULL Moved closedir(3) inside if-block. + +2019-06-13 Jeremy Sowden + + * wmail/src/wmail.c: wmail: use continue instead of goto. + +2019-06-13 Jeremy Sowden + + * wmail/src/common.c, wmail/src/config.c, wmail/src/wmail.c: wmail: + formatting improvements. + +2019-06-13 Jeremy Sowden + + * wmail/src/common.h: wmail: debug macro fixes. + +2019-06-13 Jeremy Sowden + + * wmail/README, wmail/src/config.c, wmail/wmailrc-sample: wmail: + fixed config typo. The old spelling is still supported. + 2019-06-12 Jeremy Sowden * wmail/ChangeLog, wmail/README, wmail/configure.ac, diff -Nru wmail-2.2/configure wmail-2.3/configure --- wmail-2.2/configure 2019-06-13 08:12:44.000000000 +0000 +++ wmail-2.3/configure 2019-06-21 19:03:00.000000000 +0000 @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for wmail 2.2. +# Generated by GNU Autoconf 2.69 for wmail 2.3. # # Report bugs to . # @@ -580,8 +580,8 @@ # Identity of this package. PACKAGE_NAME='wmail' PACKAGE_TARNAME='wmail' -PACKAGE_VERSION='2.2' -PACKAGE_STRING='wmail 2.2' +PACKAGE_VERSION='2.3' +PACKAGE_STRING='wmail 2.3' PACKAGE_BUGREPORT='wmaker-dev@googlegroups.com' PACKAGE_URL='' @@ -1298,7 +1298,7 @@ # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures wmail 2.2 to adapt to many kinds of systems. +\`configure' configures wmail 2.3 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1365,7 +1365,7 @@ if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of wmail 2.2:";; + short | recursive ) echo "Configuration of wmail 2.3:";; esac cat <<\_ACEOF @@ -1469,7 +1469,7 @@ test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -wmail configure 2.2 +wmail configure 2.3 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -1892,7 +1892,7 @@ This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by wmail $as_me 2.2, which was +It was created by wmail $as_me 2.3, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -2759,7 +2759,7 @@ # Define the identity of the package. PACKAGE='wmail' - VERSION='2.2' + VERSION='2.3' cat >>confdefs.h <<_ACEOF @@ -5815,7 +5815,7 @@ # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by wmail $as_me 2.2, which was +This file was extended by wmail $as_me 2.3, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -5881,7 +5881,7 @@ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -wmail config.status 2.2 +wmail config.status 2.3 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff -Nru wmail-2.2/configure.ac wmail-2.3/configure.ac --- wmail-2.2/configure.ac 2019-06-13 07:46:22.000000000 +0000 +++ wmail-2.3/configure.ac 2019-06-21 19:01:47.000000000 +0000 @@ -1,5 +1,5 @@ dnl Process this file with autoconf to produce a configure script. -AC_INIT([wmail], [2.2], [wmaker-dev@googlegroups.com]) +AC_INIT([wmail], [2.3], [wmaker-dev@googlegroups.com]) AC_CONFIG_HEADERS(config.h) AC_CONFIG_SRCDIR([src/wmail.c]) AM_INIT_AUTOMAKE([foreign]) diff -Nru wmail-2.2/debian/changelog wmail-2.3/debian/changelog --- wmail-2.2/debian/changelog 2019-06-21 13:23:57.000000000 +0000 +++ wmail-2.3/debian/changelog 2019-10-05 12:51:34.000000000 +0000 @@ -1,3 +1,14 @@ +wmail (2.3-1) unstable; urgency=medium + + * Added build-dep on debhelper-compat and removed debian/compat. + * New upstream version 2.3 + * Remove patches cherry-picked from 2.3. + * Bump standards-version to 4.4.1. + * Set Rules-Requires-Root: no. + * Run wrap-and-sort --max-line-length 72. + + -- Jeremy Sowden Sat, 05 Oct 2019 13:51:34 +0100 + wmail (2.2-4) unstable; urgency=medium * Added upstream fix for use-after-free (closes: #332539). diff -Nru wmail-2.2/debian/compat wmail-2.3/debian/compat --- wmail-2.2/debian/compat 2019-06-16 11:09:17.000000000 +0000 +++ wmail-2.3/debian/compat 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -12 diff -Nru wmail-2.2/debian/control wmail-2.3/debian/control --- wmail-2.2/debian/control 2019-06-20 16:25:06.000000000 +0000 +++ wmail-2.3/debian/control 2019-10-05 12:51:34.000000000 +0000 @@ -6,13 +6,17 @@ Homepage: https://www.dockapps.net/wmail Vcs-Browser: https://salsa.debian.org/wmaker-team/wmail Vcs-Git: https://salsa.debian.org/wmaker-team/wmail.git -Build-Depends: debhelper (>= 12), libdockapp-dev, libx11-dev, - libxext-dev, pkg-config -Standards-Version: 4.3.0 +Rules-Requires-Root: no +Build-Depends: debhelper-compat (= 12), + libdockapp-dev, + libx11-dev, + libxext-dev, + pkg-config +Standards-Version: 4.4.1 Package: wmail Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends} +Depends: ${misc:Depends}, ${shlibs:Depends} Description: WindowMaker docklet watching your inbox wmail is a Window Maker docklet watching your inbox, which is either a ordinary mbox or a directory conforming to qmail's Maildir format. It diff -Nru wmail-2.2/debian/patches/0001-wmail-fixed-config-typo.patch wmail-2.3/debian/patches/0001-wmail-fixed-config-typo.patch --- wmail-2.2/debian/patches/0001-wmail-fixed-config-typo.patch 2019-06-20 16:25:06.000000000 +0000 +++ wmail-2.3/debian/patches/0001-wmail-fixed-config-typo.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,66 +0,0 @@ -From ee2a5ddab2b4e01a6c32a4060cf425653e4667db Mon Sep 17 00:00:00 2001 -From: Jeremy Sowden -Date: Thu, 13 Jun 2019 09:04:46 +0100 -Subject: [PATCH] wmail: fixed config typo. - -The old spelling is still supported. ---- - README | 4 ++-- - src/config.c | 4 ++-- - wmailrc-sample | 2 +- - 3 files changed, 5 insertions(+), 5 deletions(-) - -diff --git a/README b/README -index aaacf4cc0016..2a108d8c285f 100644 ---- a/README -+++ b/README -@@ -62,9 +62,9 @@ Description: - rc-file statement: Mail.ShowOnlyNew = Yes|No - default value : No - -- item : mail check intervall (sec) -+ item : mail check interval (sec) - cmd-line option : -i -- rc-file statement: Mail.CheckIntervall = -+ rc-file statement: Mail.CheckInterval = - default value : 1 - - item : consider status-field (not used when in maildir mode) -diff --git a/src/config.c b/src/config.c -index aa865ab669c6..adf96dee3856 100644 ---- a/src/config.c -+++ b/src/config.c -@@ -57,7 +57,7 @@ - // Window.Button.Command = "string" - // Mail.MailBox = "string" - // Mail.ChecksumFile = "string" --// Mail.CheckIntervall = number -+// Mail.CheckInterval = number - // Mail.ShowOnlyNew = On|Off - // Mail.SkipSender = "string" - // Mail.OnNew.Command = "string" -@@ -314,7 +314,7 @@ void ReadConfigFile( const char *configFile, bool resetConfigStrings ) - continue; - } - -- if( PREFIX_MATCHES( id, "Mail.CheckIntervall", false )) -+ if( PREFIX_MATCHES( id, "Mail.CheckInterval", false )) - { - if( !( config.givenOptions & CL_CHECKINTERVAL )) - ReadInt( value, line, &config.checkInterval ); -diff --git a/wmailrc-sample b/wmailrc-sample -index 6e8854b40038..bd44d45d3677 100644 ---- a/wmailrc-sample -+++ b/wmailrc-sample -@@ -40,7 +40,7 @@ Mail.ShowOnlyNew = Yes - - # mail-check interval in seconds - # integer value, default: 1 --Mail.CheckIntervall = 5 -+Mail.CheckInterval = 5 - - # setup the ticker-line: allowed values are: Address | NickName | FamilyName - # enum value, default: Address --- -2.20.1 - diff -Nru wmail-2.2/debian/patches/0002-wmail-fixed-possible-NULL-pointer-dereference-in-con.patch wmail-2.3/debian/patches/0002-wmail-fixed-possible-NULL-pointer-dereference-in-con.patch --- wmail-2.2/debian/patches/0002-wmail-fixed-possible-NULL-pointer-dereference-in-con.patch 2019-06-20 16:25:06.000000000 +0000 +++ wmail-2.3/debian/patches/0002-wmail-fixed-possible-NULL-pointer-dereference-in-con.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,39 +0,0 @@ -From deae8bec8d769d1b6d8f753b6a7e1e6ffbc6c515 Mon Sep 17 00:00:00 2001 -From: Jeremy Sowden -Date: Thu, 13 Jun 2019 13:00:27 +0100 -Subject: [PATCH] wmail: fixed possible NULL-pointer dereference in - config-parser. - ---- - src/config.c | 12 +++++++----- - 1 file changed, 7 insertions(+), 5 deletions(-) - -diff --git a/src/config.c b/src/config.c -index aa865ab669c6..22e5dc54027b 100644 ---- a/src/config.c -+++ b/src/config.c -@@ -124,14 +124,16 @@ static bool Tokenize( const char *line, const char **id, const char **value ) - { - token2 = strchr( token1, '=' ); - if( token2 != NULL ) -+ { - token2 = SkipWhiteSpaces( token2+1 ); - -- if( !IsWhiteSpace( token2 )) -- { -- *id = token1; -- *value = token2; -+ if( !IsWhiteSpace( token2 )) -+ { -+ *id = token1; -+ *value = token2; - -- return true; -+ return true; -+ } - } - } - } --- -2.20.1 - diff -Nru wmail-2.2/debian/patches/0003-wmail-fixed-use-after-free.patch wmail-2.3/debian/patches/0003-wmail-fixed-use-after-free.patch --- wmail-2.2/debian/patches/0003-wmail-fixed-use-after-free.patch 2019-06-21 13:23:57.000000000 +0000 +++ wmail-2.3/debian/patches/0003-wmail-fixed-use-after-free.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,29 +0,0 @@ -From d93b187a91264d74afa181f7ea85044c534216f7 Mon Sep 17 00:00:00 2001 -From: Jeremy Sowden -Date: Fri, 21 Jun 2019 09:10:01 +0100 -Subject: [PATCH] wmail: fixed use-after-free. - -The CleanupNames() function removed the sender-addresses for deleted -mails, but did not set the namesChanged flag to true. This meant that -if the ticker was displaying the address of a mail which had been -deleted it would continue doing so after the address had been freed. ---- - src/wmail.c | 2 ++ - 1 file changed, 2 insertions(+) - -diff --git a/src/wmail.c b/src/wmail.c -index 0d1df25c9539..839aff433c79 100644 ---- a/src/wmail.c -+++ b/src/wmail.c -@@ -1558,6 +1558,8 @@ static void CleanupNames( void ) - - free( name->name ); - free( name ); -+ -+ namesChanged = true; - } else { - last = name; - --- -2.20.1 - diff -Nru wmail-2.2/debian/patches/series wmail-2.3/debian/patches/series --- wmail-2.2/debian/patches/series 2019-06-21 13:23:57.000000000 +0000 +++ wmail-2.3/debian/patches/series 1970-01-01 00:00:00.000000000 +0000 @@ -1,3 +0,0 @@ -0001-wmail-fixed-config-typo.patch -0002-wmail-fixed-possible-NULL-pointer-dereference-in-con.patch -0003-wmail-fixed-use-after-free.patch diff -Nru wmail-2.2/README wmail-2.3/README --- wmail-2.2/README 2019-06-13 08:12:31.000000000 +0000 +++ wmail-2.3/README 2019-06-21 19:01:47.000000000 +0000 @@ -1,6 +1,6 @@ Name : wmail Description : a enhanced Window Maker email flagging docklet -Current version : 2.2 +Current version : 2.3 Licence : see file COPYING for licencing details Web/Home : https://www.dockapps.net/wmail Contact : Window Maker Developers @@ -62,9 +62,9 @@ rc-file statement: Mail.ShowOnlyNew = Yes|No default value : No - item : mail check intervall (sec) + item : mail check interval (sec) cmd-line option : -i - rc-file statement: Mail.CheckIntervall = + rc-file statement: Mail.CheckInterval = default value : 1 item : consider status-field (not used when in maildir mode) diff -Nru wmail-2.2/src/common.c wmail-2.3/src/common.c --- wmail-2.2/src/common.c 2019-06-13 07:46:22.000000000 +0000 +++ wmail-2.3/src/common.c 2019-06-21 19:01:47.000000000 +0000 @@ -88,17 +88,17 @@ if( dir[dir_len - 1] != '/' ) { - len = dir_len + 1 + file_len + 1; - fmt = "%s/%s"; + len = dir_len + 1 + file_len + 1; + fmt = "%s/%s"; } else { - len = dir_len + file_len + 1; - fmt = "%s%s"; + len = dir_len + file_len + 1; + fmt = "%s%s"; } fullName = malloc( len ); if( fullName != NULL ) - snprintf( fullName, len, fmt, dir, file ); + snprintf( fullName, len, fmt, dir, file ); return fullName; } diff -Nru wmail-2.2/src/common.h wmail-2.3/src/common.h --- wmail-2.2/src/common.h 2019-06-13 08:04:08.000000000 +0000 +++ wmail-2.3/src/common.h 2019-06-21 19:01:47.000000000 +0000 @@ -86,14 +86,16 @@ #ifdef DEBUG void TRACE( const char *fmt, ... ); -#define ASSERT( EXPR ) ((void)(EXPR ? 0 : ABORT( "%s(%i): Assertion failed: \"%s\"\n", __FILE__, __LINE__, #EXPR ))) -#define VERIFY( EXPR ) ASSERT( EXPR ) +#define ASSERT( EXPR ) do { \ + if ( !(EXPR) ) \ + ABORT( "%s(%i): Assertion failed: \"%s\"\n", \ + __FILE__, __LINE__, #EXPR ); \ +} while (0) #else #define TRACE( fmt... ) #define ASSERT( EXPR ) -#define VERIFY( EXPR ) #endif diff -Nru wmail-2.2/src/config.c wmail-2.3/src/config.c --- wmail-2.2/src/config.c 2019-06-13 08:12:31.000000000 +0000 +++ wmail-2.3/src/config.c 2019-06-21 19:01:47.000000000 +0000 @@ -57,7 +57,7 @@ // Window.Button.Command = "string" // Mail.MailBox = "string" // Mail.ChecksumFile = "string" -// Mail.CheckIntervall = number +// Mail.CheckInterval = number // Mail.ShowOnlyNew = On|Off // Mail.SkipSender = "string" // Mail.OnNew.Command = "string" @@ -124,14 +124,16 @@ { token2 = strchr( token1, '=' ); if( token2 != NULL ) - token2 = SkipWhiteSpaces( token2+1 ); - - if( !IsWhiteSpace( token2 )) { - *id = token1; - *value = token2; + token2 = SkipWhiteSpaces( token2 + 1 ); + + if( !IsWhiteSpace( token2 )) + { + *id = token1; + *value = token2; - return true; + return true; + } } } } @@ -169,37 +171,44 @@ void ResetConfigStrings( void ) { - if( !( config.givenOptions & CL_MAILBOX )) { + if( !( config.givenOptions & CL_MAILBOX )) + { free( config.mailBox ); config.mailBox = NULL; } - if( !( config.givenOptions & CL_RUNCMD )) { + if( !( config.givenOptions & CL_RUNCMD )) + { free( config.runCmd ); config.runCmd = NULL; } - if( !( config.givenOptions & CL_SYMBOLCOLOR )) { + if( !( config.givenOptions & CL_SYMBOLCOLOR )) + { free( config.symbolColor ); config.symbolColor = NULL; } - if( !( config.givenOptions & CL_FONTCOLOR )) { + if( !( config.givenOptions & CL_FONTCOLOR )) + { free( config.fontColor ); config.fontColor = NULL; } - if( !( config.givenOptions & CL_BACKCOLOR )) { + if( !( config.givenOptions & CL_BACKCOLOR )) + { free( config.backColor ); config.backColor = NULL; } - if( !( config.givenOptions & CL_OFFLIGHTCOLOR )) { + if( !( config.givenOptions & CL_OFFLIGHTCOLOR )) + { free( config.offlightColor ); config.offlightColor = NULL; } - if( !( config.givenOptions & CL_BACKGROUNDCOLOR )) { + if( !( config.givenOptions & CL_BACKGROUNDCOLOR )) + { free( config.backgroundColor ); config.backgroundColor = NULL; } @@ -210,12 +219,14 @@ free( config.checksumFileName ); config.checksumFileName = NULL; - if( !( config.givenOptions & CL_CMDONMAIL )) { + if( !( config.givenOptions & CL_CMDONMAIL )) + { free( config.cmdOnMail ); config.cmdOnMail = NULL; } - if( !( config.givenOptions & CL_USEX11FONT )) { + if( !( config.givenOptions & CL_USEX11FONT )) + { free( config.useX11Font ); config.useX11Font = NULL; } @@ -270,9 +281,8 @@ break; // first eliminate the trailing whitespaces - for( len = strlen( buf ); - len > 0 && IsWhiteSpace(buf+(--len)); ) - *(buf+len) = '\0'; + for( len = strlen( buf ); len > 0 && IsWhiteSpace(buf + (--len)); ) + *(buf + len) = '\0'; if( !Tokenize( buf, &id, &value )) continue; @@ -314,7 +324,7 @@ continue; } - if( PREFIX_MATCHES( id, "Mail.CheckIntervall", false )) + if( PREFIX_MATCHES( id, "Mail.CheckInterval", false )) { if( !( config.givenOptions & CL_CHECKINTERVAL )) ReadInt( value, line, &config.checkInterval ); @@ -420,16 +430,17 @@ } fclose( f ); - } else { - TRACE( "unable to open config-file \"%s\"\n", configFile ); } + else + TRACE( "unable to open config-file \"%s\"\n", configFile ); PostProcessConfiguration(); } static bool ReadString( const char *from, unsigned int line, char **to ) { - if( *from++ == '"' ) { + if( *from++ == '"' ) + { const char *trailingQuote; for( trailingQuote = strchr( from, '"' ); @@ -442,50 +453,60 @@ ++trailingQuote; } - if( trailingQuote != NULL ) { + if( trailingQuote != NULL ) + { // valid string found, copy and translate escape sequences const char *c; char *to_c; // disposing of "to" is up to the caller... - *to = malloc( trailingQuote - from + 1 ); - to_c = *to; + to_c = malloc( trailingQuote - from + 1 ); + if( to_c == NULL ) + return false; - for( c = from; c != trailingQuote; ++c ) { - if( *c == '\\' ) { - switch( *(++c) ) { - case 'n': *to_c = '\n'; break; - case 'b': *to_c = '\b'; break; + *to = to_c; + + for( c = from; c != trailingQuote; ++c ) + { + if( *c == '\\' ) + { + switch( *(++c) ) + { + case 'n': *to_c = '\n'; break; + case 'b': *to_c = '\b'; break; case '\\': *to_c = '\\'; break; - case 'r': *to_c = '\r'; break; - case 't': *to_c = '\t'; break; - case '"': *to_c = '"'; break; + case 'r': *to_c = '\r'; break; + case 't': *to_c = '\t'; break; + case '"': *to_c = '"'; break; default: { int value, i; - for( i = 0, value = 0; i < 3; ++i ) { - if( c+i == NULL || *(c+i) < '0' || *(c+i) > '9' ) - break; - value = value * 10 + *(c+i) - '0'; + for( i = 0, value = 0; i < 3; ++i ) + { + if( c + i == NULL || *(c + i) < '0' || *(c + i) > '9' ) + break; + value = value * 10 + *(c + i) - '0'; } if( value == 0 ) WARNING( "cfg-file(%i): '\\0' in string or unknown escape sequence found\n", line ); - else { + else + { *to_c = (char)value; - c += i-1; + c += i - 1; } } } - } else + } + else *to_c = *c; ++to_c; } *to_c = '\0'; - TRACE( "ReadString read \"%s\"\n", *to ); + TRACE( "ReadString read \"%s\"\n", *to ); return true; } } @@ -500,7 +521,8 @@ *to = true; else if( !strcasecmp( from, "off" ) || !strcasecmp( from, "no" ) || !strcasecmp( from, "false" )) *to = false; - else { + else + { WARNING( "cfg-file(%i): invalid boolean value: \"%s\"\n", line, from ); return false; } @@ -514,10 +536,11 @@ { int value = 0; - if( *from == '0' && (*(from+1) == 'x' || *(from+1) == 'X') ) { + if( *from == '0' && (*(from + 1) == 'x' || *(from + 1) == 'X')) for( from += 2; *from != '\0' && !IsWhiteSpace( from ); ++from ) { - if( value > (INT_MAX - 0xf) / 0x10 ) { + if( value > (INT_MAX - 0xf) / 0x10 ) + { WARNING( "cfg-file(%i): hexadecimal-number too large: \">%x\"\n", line, INT_MAX ); return false; } @@ -528,21 +551,25 @@ value = value * 16 + *from - 'a' + 10; else if( *from >= 'A' && *from >= 'F' ) value = value * 16 + *from - 'A' + 10; - else { + else + { WARNING( "cfg-file(%i): invalid hex-digit: \"%c\"\n", line, *from ); return false; } } - } else - for( ; *from != '\0' && !IsWhiteSpace( from ); ++from ) { - if( value > (INT_MAX - 9) / 10 ) { + else + for( ; *from != '\0' && !IsWhiteSpace( from ); ++from ) + { + if( value > (INT_MAX - 9) / 10 ) + { WARNING( "cfg-file(%i): decimal-number too large: \">%i\"\n", line, INT_MAX ); return false; } if( *from >= '0' && *from <= '9' ) value = value * 10 + *from - '0'; - else { + else + { WARNING( "cfg-file(%i): invalid decimal-digit: \"%c\"\n", line, *from ); return false; @@ -562,7 +589,8 @@ int index; for( index = 0; enumList[index].id != NULL; ++index ) - if( !strcasecmp( enumList[index].id, from )) { + if( !strcasecmp( enumList[index].id, from )) + { *to = enumList[index].value; TRACE( "ReadEnum read \"%i\"\n", *to ); diff -Nru wmail-2.2/src/wmail.c wmail-2.3/src/wmail.c --- wmail-2.2/src/wmail.c 2019-06-13 07:46:22.000000000 +0000 +++ wmail-2.3/src/wmail.c 2019-06-21 19:01:47.000000000 +0000 @@ -83,12 +83,14 @@ /////////////////////////////////////////////////////////////////////////////// // typedefs -typedef enum { +typedef enum +{ FLAG_INITIAL = 0, FLAG_READ = 1 } flag_t; -typedef struct _name_t { +typedef struct _name_t +{ char *name; unsigned long checksum; flag_t flag; @@ -96,13 +98,15 @@ struct _name_t *next; } name_t; -typedef enum { +typedef enum +{ STATE_NOMAIL, STATE_NEWMAIL, STATE_READMAIL } mail_state_t; -typedef enum { +typedef enum +{ STATE_ADDRESS, STATE_QUOTED_ADDRESS, STATE_FULLNAME, @@ -163,128 +167,148 @@ OPT_INDEX_CONFIG_FILE, }; -static DAProgramOption options[] = { - [OPT_INDEX_DISPLAY] = { - .shortForm = "-display", - .description = "display to use", - .type = DOString, - .value = { .string = &config.display } +static DAProgramOption options[] = +{ + [OPT_INDEX_DISPLAY] = + { + .shortForm = "-display", + .description = "display to use", + .type = DOString, + .value = { .string = &config.display } }, - [OPT_INDEX_COMMAND] = { - .shortForm = "-c", - .longForm = "--command", - .description = "cmd to run on btn-click (\"xterm -e mail\" is default)", - .type = DOString, - .value = { .string = &config.runCmd } + [OPT_INDEX_COMMAND] = + { + .shortForm = "-c", + .longForm = "--command", + .description = "cmd to run on btn-click (\"xterm -e mail\" is default)", + .type = DOString, + .value = { .string = &config.runCmd } }, - [OPT_INDEX_INTERVAL] = { - .shortForm = "-i", - .longForm = "--interval", - .description = "number of secs between mail-status updates (1 is default)", - .type = DONatural, - .value = { .integer = &config.checkInterval } + [OPT_INDEX_INTERVAL] = + { + .shortForm = "-i", + .longForm = "--interval", + .description = "number of secs between mail-status updates (1 is default)", + .type = DONatural, + .value = { .integer = &config.checkInterval } }, - [OPT_INDEX_FAMILY_NAME] = { - .shortForm = "-f", - .longForm = "--familyname", - .description = "tickers the family-name if available", + [OPT_INDEX_FAMILY_NAME] = + { + .shortForm = "-f", + .longForm = "--familyname", + .description = "tickers the family-name if available", }, - [OPT_INDEX_FRAMES] = { - .shortForm = "-fps", - .longForm = "--frames", - .description = "ticker frames per second", - .type = DONatural, - .value = { .integer = &config.fps } + [OPT_INDEX_FRAMES] = + { + .shortForm = "-fps", + .longForm = "--frames", + .description = "ticker frames per second", + .type = DONatural, + .value = { .integer = &config.fps } }, - [OPT_INDEX_SHORT_NAME] = { - .shortForm = "-s", - .longForm = "--shortname", - .description = "tickers the nickname (all before the '@')", + [OPT_INDEX_SHORT_NAME] = + { + .shortForm = "-s", + .longForm = "--shortname", + .description = "tickers the nickname (all before the '@')", }, - [OPT_INDEX_SYMBOL_COLOR] = { - .shortForm = "-sc", - .longForm = "--symbolcolor", - .description = "symbol color-name", - .type = DOString, - .value = { .string = &config.symbolColor } + [OPT_INDEX_SYMBOL_COLOR] = + { + .shortForm = "-sc", + .longForm = "--symbolcolor", + .description = "symbol color-name", + .type = DOString, + .value = { .string = &config.symbolColor } }, - [OPT_INDEX_FONT_COLOR] = { - .shortForm = "-fc", - .longForm = "--fontcolor", - .description = "ticker-font color-name", - .type = DOString, - .value = { .string = &config.fontColor } + [OPT_INDEX_FONT_COLOR] = + { + .shortForm = "-fc", + .longForm = "--fontcolor", + .description = "ticker-font color-name", + .type = DOString, + .value = { .string = &config.fontColor } }, - [OPT_INDEX_BACK_COLOR] = { - .shortForm = "-bc", - .longForm = "--backcolor", - .description = "backlight color-name", - .type = DOString, - .value = { .string = &config.backColor } + [OPT_INDEX_BACK_COLOR] = + { + .shortForm = "-bc", + .longForm = "--backcolor", + .description = "backlight color-name", + .type = DOString, + .value = { .string = &config.backColor } }, - [OPT_INDEX_OFF_COLOR] = { - .shortForm = "-oc", - .longForm = "--offcolor", - .description = "off-light color-name", - .type = DOString, - .value = { .string = &config.offlightColor } + [OPT_INDEX_OFF_COLOR] = + { + .shortForm = "-oc", + .longForm = "--offcolor", + .description = "off-light color-name", + .type = DOString, + .value = { .string = &config.offlightColor } }, - [OPT_INDEX_BACKGROUND] = { - .shortForm = "-bg", - .longForm = "--background", - .description = "frame-background for non-shaped window", - .type = DOString, - .value = { .string = &config.backgroundColor } + [OPT_INDEX_BACKGROUND] = + { + .shortForm = "-bg", + .longForm = "--background", + .description = "frame-background for non-shaped window", + .type = DOString, + .value = { .string = &config.backgroundColor } }, - [OPT_INDEX_NO_SHAPE] = { - .shortForm = "-ns", - .longForm = "--noshape", - .description = "make the dockapp non-shaped (combine with -w)", + [OPT_INDEX_NO_SHAPE] = + { + .shortForm = "-ns", + .longForm = "--noshape", + .description = "make the dockapp non-shaped (combine with -w)", }, - [OPT_INDEX_NEW] = { - .shortForm = "-n", - .longForm = "--new", - .description = "forces wmail to show new mail exclusively", + [OPT_INDEX_NEW] = + { + .shortForm = "-n", + .longForm = "--new", + .description = "forces wmail to show new mail exclusively", }, - [OPT_INDEX_MAILBOX] = { - .shortForm = "-mb", - .longForm = "--mailbox", - .description = "specify another mailbox ($MAIL is default)", - .type = DOString, - .value = { .string = &config.mailBox } + [OPT_INDEX_MAILBOX] = + { + .shortForm = "-mb", + .longForm = "--mailbox", + .description = "specify another mailbox ($MAIL is default)", + .type = DOString, + .value = { .string = &config.mailBox } }, - [OPT_INDEX_EXECUTE] = { - .shortForm = "-e", - .longForm = "--execute", - .description = "command to execute when receiving a new mail", - .type = DOString, - .value = { .string = &config.cmdOnMail } + [OPT_INDEX_EXECUTE] = + { + .shortForm = "-e", + .longForm = "--execute", + .description = "command to execute when receiving a new mail", + .type = DOString, + .value = { .string = &config.cmdOnMail } }, - [OPT_INDEX_STATUS_FIELD] = { - .shortForm = "-sf", - .longForm = "--statusfield", - .description = "consider the status-field of the mail header to distinguish unread mails", + [OPT_INDEX_STATUS_FIELD] = + { + .shortForm = "-sf", + .longForm = "--statusfield", + .description = "consider the status-field of the mail header to distinguish unread mails", }, - [OPT_INDEX_READ_STATUS] = { - .shortForm = "-rs", - .longForm = "--readstatus", - .description = "status field content that your client uses to mark read mails", - .type = DOString, - .value = { .string = &config.readStatus } + [OPT_INDEX_READ_STATUS] = + { + .shortForm = "-rs", + .longForm = "--readstatus", + .description = "status field content that your client uses to mark read mails", + .type = DOString, + .value = { .string = &config.readStatus } }, - [OPT_INDEX_TICKER_FONT] = { - .shortForm = "-fn", - .longForm = "--tickerfont", - .description = "use specified X11 font to draw the ticker", - .type = DOString, - .value = { .string = &config.useX11Font } + [OPT_INDEX_TICKER_FONT] = + { + .shortForm = "-fn", + .longForm = "--tickerfont", + .description = "use specified X11 font to draw the ticker", + .type = DOString, + .value = { .string = &config.useX11Font } }, - [OPT_INDEX_CONFIG_FILE] = { - .shortForm = "-rc", - .longForm = "--rcfile", - .description = "specify another rc-file ($HOME/.wmailrc is default)", - .type = DOString, - .value = { .string = &configFile } + [OPT_INDEX_CONFIG_FILE] = + { + .shortForm = "-rc", + .longForm = "--rcfile", + .description = "specify another rc-file ($HOME/.wmailrc is default)", + .type = DOString, + .value = { .string = &configFile } } }; @@ -292,7 +316,7 @@ /////////////////////////////////////////////////////////////////////////////// // prototypes -static void PreparePixmaps( bool freeThemFirst ); +static int PreparePixmaps( bool freeMem ); static void ExitHandler( int sig ); static void TimedOut( void ); static void CheckTimeOut( bool force ); @@ -306,14 +330,14 @@ struct stat *fileStat, bool isNewMail ); static char *ParseFromField( char *buf ); static bool SkipSender( char *address ); -static void InsertName( char *name, unsigned long checksum, flag_t flag ); +static int InsertName( char *name, unsigned long checksum, flag_t flag ); static void RemoveLastName( void ); static void ClearAllNames( void ); static void DrawTickerX11Font( void ); static void DrawTickerBuildinFont( void ); static void ButtonPressed( int button, int state, int x, int y ); static void ButtonReleased( int button, int state, int x, int y ); -static char *XpmColorLine( const char *colorName, char *colorLine, +static int XpmColorLine( const char *colorName, char **colorLine, bool disposeLine ); static void ReadChecksumFile( void ); static void WriteChecksumFile( bool writeAll ); @@ -452,14 +476,20 @@ DAInitialize( config.display, "wmail", 64, 64, argc, argv ); outPixmap = DAMakePixmap(); - PreparePixmaps( false ); + if( PreparePixmaps( false ) < 0 ) + { + WARNING( "Cannot allocate color.\n" ); + exit( EXIT_FAILURE ); + } - if( sigaction( SIGINT, &sa, NULL ) == -1 ) { + if( sigaction( SIGINT, &sa, NULL ) == -1 ) + { perror( "wmail error: sigaction" ); exit( EXIT_FAILURE ); } - if( sigaction( SIGTERM, &sa, NULL ) == -1 ) { + if( sigaction( SIGTERM, &sa, NULL ) == -1 ) + { perror( "wmail error: sigaction" ); exit( EXIT_FAILURE ); } @@ -478,11 +508,17 @@ return 0; } -static void PreparePixmaps( bool freeMem ) +static int PreparePixmaps( bool freeMem ) { // simple recoloring of the raw xpms befor creating Pixmaps of them // this works as long as you don't "touch" the images... + bool freeSymColor = freeMem && ( config.colorsUsed & SYM_COLOR ); + bool freeFntColor = freeMem && ( config.colorsUsed & FNT_COLOR ); + bool freeBckColor = freeMem && ( config.colorsUsed & BCK_COLOR ); + bool freeOffColor = freeMem && ( config.colorsUsed & OFF_COLOR ); + bool freeBgrColor = freeMem && ( config.colorsUsed & BGR_COLOR ); + #if DA_VERSION < 20030126 unsigned dummy; #else @@ -491,69 +527,116 @@ XGCValues values; - if( config.symbolColor != NULL ) { // symbol color ? - symbols_xpm[2] = XpmColorLine( config.symbolColor, symbols_xpm[2], - freeMem && ( config.colorsUsed & SYM_COLOR )); + /* + * Symbol color? + */ + if( config.symbolColor != NULL ) + { + if( XpmColorLine( config.symbolColor, &symbols_xpm[2], freeSymColor) < 0 ) + return -1; + config.colorsUsed |= SYM_COLOR; - } else { - symbols_xpm[2] = XpmColorLine( "#20B2AA", symbols_xpm[2], - freeMem && ( config.colorsUsed & SYM_COLOR )); + } + else + { + if( XpmColorLine( "#20B2AA", &symbols_xpm[2], freeSymColor) < 0 ) + return -1; + config.colorsUsed |= SYM_COLOR; } - if( config.fontColor != NULL ) { // font color ? - chars_xpm[3] = XpmColorLine( config.fontColor, chars_xpm[3], - freeMem && ( config.colorsUsed & FNT_COLOR )); - numbers_xpm[3] = XpmColorLine( config.fontColor, numbers_xpm[3], - freeMem && ( config.colorsUsed & FNT_COLOR )); + /* + * Font color? + */ + if( config.fontColor != NULL ) + { + if( XpmColorLine( config.fontColor, &chars_xpm[3], freeFntColor) < 0 ) + return -1; + + if( XpmColorLine( config.fontColor, &numbers_xpm[3], freeFntColor) < 0 ) + return -1; + config.colorsUsed |= FNT_COLOR; - } else { - chars_xpm[3] = XpmColorLine( "#D3D3D3", chars_xpm[3], - freeMem && ( config.colorsUsed & FNT_COLOR )); - numbers_xpm[3] = XpmColorLine( "#D3D3D3", numbers_xpm[3], - freeMem && ( config.colorsUsed & FNT_COLOR )); + } + else + { + if( XpmColorLine( "#D3D3D3", &chars_xpm[3], freeFntColor) < 0 ) + return -1; + + if( XpmColorLine( "#D3D3D3", &numbers_xpm[3], freeFntColor) < 0 ) + return -1; + config.colorsUsed |= FNT_COLOR; } - if( config.backColor != NULL ) { // backlight color ? - main_xpm[3] = XpmColorLine( config.backColor, main_xpm[3], - freeMem && ( config.colorsUsed & BCK_COLOR )); - symbols_xpm[3] = XpmColorLine( config.backColor, symbols_xpm[3], - freeMem && ( config.colorsUsed & BCK_COLOR )); - chars_xpm[2] = XpmColorLine( config.backColor, chars_xpm[2], - freeMem && ( config.colorsUsed & BCK_COLOR )); - numbers_xpm[2] = XpmColorLine( config.backColor, numbers_xpm[2], - freeMem && ( config.colorsUsed & BCK_COLOR )); + /* + * Backlight color? + */ + if( config.backColor != NULL ) + { + if( XpmColorLine( config.backColor, &main_xpm[3], freeBckColor) < 0 ) + return -1; + + if( XpmColorLine( config.backColor, &symbols_xpm[3], freeBckColor) < 0 ) + return -1; + + if( XpmColorLine( config.backColor, &chars_xpm[2], freeBckColor) < 0 ) + return -1; + + if( XpmColorLine( config.backColor, &numbers_xpm[2], freeBckColor) < 0 ) + return -1; + config.colorsUsed |= BCK_COLOR; - } else { - main_xpm[3] = XpmColorLine( "#282828", main_xpm[3], - freeMem && ( config.colorsUsed & BCK_COLOR )); - symbols_xpm[3] = XpmColorLine( "#282828", symbols_xpm[3], - freeMem && ( config.colorsUsed & BCK_COLOR )); - chars_xpm[2] = XpmColorLine( "#282828", chars_xpm[2], - freeMem && ( config.colorsUsed & BCK_COLOR )); - numbers_xpm[2] = XpmColorLine( "#282828", numbers_xpm[2], - freeMem && ( config.colorsUsed & BCK_COLOR )); + } + else + { + if( XpmColorLine( "#282828", &main_xpm[3], freeBckColor) < 0 ) + return -1; + + if( XpmColorLine( "#282828", &symbols_xpm[3], freeBckColor) < 0 ) + return -1; + + if( XpmColorLine( "#282828", &chars_xpm[2], freeBckColor) < 0 ) + return -1; + + if( XpmColorLine( "#282828", &numbers_xpm[2], freeBckColor) < 0 ) + return -1; + config.colorsUsed |= BCK_COLOR; } - if( config.offlightColor != NULL ) { // off-light color ? - main_xpm[2] = XpmColorLine( config.offlightColor, main_xpm[2], - freeMem && ( config.colorsUsed & OFF_COLOR )); - numbers_xpm[4] = XpmColorLine( config.offlightColor, numbers_xpm[4], - freeMem && ( config.colorsUsed & OFF_COLOR )); + /* + * Off-light color? + */ + if( config.offlightColor != NULL ) + { + if( XpmColorLine( config.offlightColor, &main_xpm[2], freeOffColor) < 0 ) + return -1; + + if( XpmColorLine( config.offlightColor, &numbers_xpm[4], freeOffColor) < 0 ) + return -1; + config.colorsUsed |= OFF_COLOR; - } else { - main_xpm[2] = XpmColorLine( "#000000", main_xpm[2], - freeMem && ( config.colorsUsed & OFF_COLOR )); - numbers_xpm[4] = XpmColorLine( "#000000", numbers_xpm[4], - freeMem && ( config.colorsUsed & OFF_COLOR )); + } + else + { + if( XpmColorLine( "#000000", &main_xpm[2], freeOffColor) < 0 ) + return -1; + + if( XpmColorLine( "#000000", &numbers_xpm[4], freeOffColor) < 0 ) + return -1; + config.colorsUsed |= OFF_COLOR; } - if( config.backgroundColor != NULL ) { // window-frame background (only seen if nonshaped) ? - main_xpm[1] = XpmColorLine( config.backgroundColor, main_xpm[1], - freeMem && ( config.colorsUsed & BGR_COLOR )); + /* + * Window-frame background (only seen if nonshaped)? + */ + if( config.backgroundColor != NULL ) + { + if( XpmColorLine( config.backgroundColor, &main_xpm[1], freeBgrColor) < 0 ) + return -1; + config.colorsUsed |= BGR_COLOR; } @@ -570,7 +653,8 @@ { XFreeGC( DADisplay, tickerGC ); tickerGC = NULL; - if( tickerFS != NULL ) { + if( tickerFS != NULL ) + { XFreeFont( DADisplay, tickerFS ); tickerFS = NULL; } @@ -611,14 +695,18 @@ DASetShape( None ); else DASetShape( mainPixmap_mask ); + + return 0; } static void MarkName( unsigned long checksum ) { name_t *name; - for( name = names; name != NULL; name = name->next ) { - if( name->checksum == checksum ) { + for( name = names; name != NULL; name = name->next ) + { + if( name->checksum == checksum ) + { name->flag |= FLAG_READ; if( config.newMailsOnly ) numMails--; @@ -632,10 +720,12 @@ name_t *name; for( name = names; name != NULL; name = name->next ) - if(!( name->flag & FLAG_READ )) { + if(!( name->flag & FLAG_READ )) + { state = STATE_NEWMAIL; - if( config.cmdOnMail != NULL ) { + if( config.cmdOnMail != NULL ) + { int ret = system( config.cmdOnMail ); if( ret == 127 || ret == -1 ) @@ -650,13 +740,14 @@ { FILE *f = fopen( config.checksumFileName, "rb" ); if( f != NULL ) - while( !feof( f )) { - unsigned long checksum; - if( fread( &checksum, sizeof(long), 1, f ) != 1 ) - continue; + while( !feof( f )) + { + unsigned long checksum; + if( fread( &checksum, sizeof(long), 1, f ) != 1 ) + continue; - MarkName( checksum ); - } + MarkName( checksum ); + } else return; @@ -668,15 +759,19 @@ FILE *f; TRACE( "writing checksums:" ); - if(( f = fopen( config.checksumFileName, "wb" )) != NULL ) { + if(( f = fopen( config.checksumFileName, "wb" )) != NULL ) + { name_t *name; - for( name = names; name != NULL; name = name->next ) { - if( writeAll || (name->flag & FLAG_READ)) { + for( name = names; name != NULL; name = name->next ) + { + if( writeAll || (name->flag & FLAG_READ)) + { fwrite( &name->checksum, sizeof(long), 1, f ); TRACE( " %X", name->checksum ); } } - } else + } + else return; TRACE( "\n" ); @@ -686,7 +781,8 @@ static void UpdateChecksum( unsigned long *checksum, const char *buf ) { - if( buf != NULL ) { + if( buf != NULL ) + { size_t i, len = strlen( buf ); for( i = 0; i < len; ++i ) @@ -708,7 +804,8 @@ static void TimedOut( void ) { - if( caughtSig ) { + if( caughtSig ) + { ClearAllNames(); ResetConfigStrings(); if( !options[OPT_INDEX_CONFIG_FILE].used ) @@ -733,7 +830,8 @@ lastTimeOut = nowMs; - if( readConfigFile ) { + if( readConfigFile ) + { readConfigFile = false; UpdateConfiguration(); checkMail = 0; @@ -760,28 +858,42 @@ { struct stat fileStat; - // error retrieving file-stats -> no/zero-size file and no new/read mails - // available - if( stat( config.mailBox, &fileStat ) == -1 || fileStat.st_size == 0 ) { - if( state != STATE_NOMAIL ) { + if( stat( config.mailBox, &fileStat ) == -1 || fileStat.st_size == 0 ) + { + /* + * Error retrieving file-stats or file is empty -> no new/read mails + * available. + */ + if( state != STATE_NOMAIL ) + { state = STATE_NOMAIL; ClearAllNames(); RemoveChecksumFile(); forceRedraw = true; } - } else { - // file has changed -> new mails arrived or some mails removed - if( lastModifySeconds != fileStat.st_mtime || forceRead ) { + } + else + { + if( lastModifySeconds != fileStat.st_mtime || forceRead ) + { + /* + * File has been updated -> new mails arrived or some mails removed + */ forceRead = false; ParseMBoxFile( &fileStat ); stat( config.mailBox, &fileStat ); forceRedraw = true; - // file has accessed (read) -> mark all mails as "read", because - // it cannot be decided which mails the user has read... - } else if( lastAccessSeconds != fileStat.st_atime ) { + } + else if( lastAccessSeconds != fileStat.st_atime ) + { + /* + * File has been accessed (read) -> mark all mails as "read", because it + * cannot be decided which mails the user has read... + */ state = STATE_READMAIL; WriteChecksumFile( true ); - if( config.newMailsOnly ) { + if( config.newMailsOnly ) + { numMails = 0; SetMailFlags( FLAG_READ ); } @@ -799,7 +911,8 @@ mail_state_t lastState = state; unsigned lastMailCount = numMails; - if( forceRead ) { + if( forceRead ) + { forceRead = false; ClearAllNames(); TRACE( "all names cleared\n" ); @@ -830,11 +943,13 @@ WARNING( "Can't stat file/path \"%s\"\n", fullName ); else if( S_ISDIR( fileStat.st_mode )) { - if( strcmp( dirEnt->d_name, "new" ) == 0 ) { + if( strcmp( dirEnt->d_name, "new" ) == 0 ) + { if( TraverseDirectory( fullName, true ) > 0 ) state = STATE_NEWMAIL; } - else if( strcmp( dirEnt->d_name, "cur" ) == 0 ) { + else if( strcmp( dirEnt->d_name, "cur" ) == 0 ) + { if( TraverseDirectory( fullName, false ) > 0 ) if( state != STATE_NEWMAIL ) state = STATE_READMAIL; @@ -846,7 +961,8 @@ closedir( dir ); CleanupNames(); - } else + } + else WARNING( "can't open directory \"%s\"\n", config.mailBox ); if( lastState != state || lastMailCount != numMails ) @@ -887,7 +1003,8 @@ TRACE( "-> new file - parsing it\n" ); ParseMaildirFile( fullName, checksum, &fileStat, isNewMail ); } - else { + else + { name->flag = isNewMail ? FLAG_INITIAL : FLAG_READ; name->visited = true; } @@ -895,9 +1012,9 @@ } free( fullName ); } - } - closedir( dir ); + closedir( dir ); + } return mails; } @@ -930,7 +1047,8 @@ XCopyArea( DADisplay, numbersPixmap, outPixmap, DAGC, 50, 0, 5, 9, 6, 49 ); drawCount = 999; - } else + } + else drawCount = numMails; for( i = 0; i < 3; ++i, drawCount /= 10 ) @@ -942,12 +1060,11 @@ } if( buttonPressed ) - { XCopyArea( DADisplay, buttonPixmap, outPixmap, DAGC, 0, 0, 23, 11, 36, 48 ); - } - switch( state ) { + switch( state ) + { case STATE_NEWMAIL: if( flashMailSymbol ) XCopyArea( DADisplay, symbolsPixmap, outPixmap, DAGC, @@ -982,14 +1099,16 @@ numMails = 0; - if( f == NULL ) { + if( f == NULL ) + { WARNING( "can't open mbox \"%s\"\n", config.mailBox ); return; } while( fgets( buf, sizeof buf, f ) != NULL ) { - if( PREFIX_MATCHES( buf, "From ", true )) { + if( PREFIX_MATCHES( buf, "From ", true )) + { fromFound = 1; checksum = 0; continue; @@ -1003,7 +1122,7 @@ char *addr = buf + sizeof "From:"; if( SkipSender( addr )) - goto NEXTMAIL; + continue; char *name; if(( name = ParseFromField( addr )) == NULL ) @@ -1011,7 +1130,11 @@ WARNING( "Could not parse From field\n" ); break; } - InsertName( name, checksum, FLAG_INITIAL ); + if ( InsertName( name, checksum, FLAG_INITIAL ) < 0 ) + { + WARNING( "Could not allocate name\n" ); + break; + } ++numMails; fromFound = 0; @@ -1024,8 +1147,6 @@ RemoveLastName(); --numMails; } -NEXTMAIL: - ; } fclose( f ); @@ -1066,7 +1187,12 @@ WARNING( "Could not parse From field\n" ); break; } - InsertName( name, checksum, isNewMail ? FLAG_INITIAL : FLAG_READ ); + if ( InsertName( name, checksum, + isNewMail ? FLAG_INITIAL : FLAG_READ ) < 0 ) + { + WARNING( "Could not allocate name\n" ); + break; + } //++numMails; } @@ -1112,10 +1238,12 @@ for( c = buf; *c != '\0'; ++c ) { - switch( state ) { + switch( state ) + { case STATE_FULLNAME: - switch( *c ) { + switch( *c ) + { case '"': state = STATE_QUOTED_FULLNAME; continue; @@ -1134,7 +1262,8 @@ state = STATE_COMMENT; continue; case '=': - if( *(c+1) == '?' ) { + if( *(c+1) == '?' ) + { ++c; fullNameEncoded = 1; state = STATE_ENCODED_FULLNAME; @@ -1149,7 +1278,8 @@ case STATE_QUOTED_FULLNAME: - switch( *c ) { + switch( *c ) + { case '\\': fullName[ fullNameLen++ ] = *(++c); continue; @@ -1163,9 +1293,11 @@ case STATE_ENCODED_FULLNAME: - switch( *c ) { + switch( *c ) + { case '?': - if( *(c+1) == '=' ) { + if( *(c+1) == '=' ) + { ++c; state = STATE_FULLNAME; continue; @@ -1177,7 +1309,8 @@ case STATE_ADDRESS: - switch( *c ) { + switch( *c ) + { case '"': state = STATE_QUOTED_ADDRESS; case '>': @@ -1196,7 +1329,8 @@ case STATE_QUOTED_ADDRESS: - switch( *c ) { + switch( *c ) + { case '"': state = STATE_ADDRESS; continue; @@ -1208,7 +1342,8 @@ } continue; case STATE_COMMENT: - switch( *c ) { + switch( *c ) + { case ')': state = STATE_FULLNAME; continue; @@ -1219,16 +1354,20 @@ } } - if( *comment ) { + if( *comment ) + { //WARNING("Comment seen: %s\nIn: %s\nFullname: %s\nAddress: %s\n", comment, buf, fullName, addressName); // Comment seen: if there's an address, append to // fullname. If no address, copy fullname to address // and comment to fullname. - if( *addressName ) { + if( *addressName ) + { strcat(fullName, "("); strcat(fullName, comment); strcat(fullName, ")"); - } else { + } + else + { strcpy(addressName, fullName); strcpy(fullName, comment); } @@ -1238,16 +1377,21 @@ //WARNING("Fullname: %s\nAddress: %s\n", fullName, addressName); // what name should be tickered - if( config.tickerMode == TICKER_FAMILYNAME && fullName[0] != '\0' && !fullNameEncoded ) { + if( config.tickerMode == TICKER_FAMILYNAME && fullName[0] != '\0' && !fullNameEncoded ) + { free( addressName ); return fullName; - } else { - if( state == STATE_FULLNAME ) { + } + else + { + if( state == STATE_FULLNAME ) + { strcpy( addressName, fullName ); if( saveAtCharPos != -1 ) atChar = &addressName[saveAtCharPos]; } - if( config.tickerMode == TICKER_NICKNAME ) { + if( config.tickerMode == TICKER_NICKNAME ) + { if( atChar != NULL ) *atChar = '\0'; } @@ -1274,7 +1418,8 @@ TRACE( "comparing \"%s\" and \"%s\"\n", *skipName, address ); // call libc-fnmatch (wildcard-match :-) ! - if( !fnmatch( *skipName, address, 0 )) { + if( !fnmatch( *skipName, address, 0 )) + { TRACE( "skipping sender \"%s\"\n", *skipName ); return true; } @@ -1283,7 +1428,7 @@ return false; } -static void InsertName( char *name, unsigned long checksum, flag_t flag ) +static int InsertName( char *name, unsigned long checksum, flag_t flag ) { name_t *item; @@ -1291,10 +1436,10 @@ if(( item = malloc( sizeof( name_t ))) == NULL ) { free( name ); - return; + return -1; } - item->name = name; /*strdup( name );*/ + item->name = name; item->checksum = checksum; item->flag = flag; item->visited = true; @@ -1302,11 +1447,13 @@ names = item; namesChanged = true; + return 0; } static void RemoveLastName( void ) { - if( names != NULL ) { + if( names != NULL ) + { name_t *name = names; names = names->next; free( name->name ); @@ -1318,7 +1465,8 @@ { name_t *name, *nextName; - for( name = names; name != NULL; name = nextName ) { + for( name = names; name != NULL; name = nextName ) + { nextName = name->next; free( name->name ); @@ -1341,15 +1489,17 @@ static void DrawTickerX11Font( void ) { - // 49x21+7+20 out-drawable size + // 49 x 21 + 7 + 20 out-drawable size static int insertAt; if( curTickerName == NULL || namesChanged ) { for( curTickerName = names; - curTickerName != NULL && config.newMailsOnly && ( curTickerName->flag & FLAG_READ ); - curTickerName = curTickerName->next ); + curTickerName != NULL && config.newMailsOnly && + ( curTickerName->flag & FLAG_READ ); + curTickerName = curTickerName->next ) + ; if( curTickerName == NULL ) return; @@ -1367,20 +1517,20 @@ if( insertAt < -XTextWidth( tickerFS, curTickerName->name, strlen( curTickerName->name )) + 6 ) { - do { + do curTickerName = curTickerName->next; - } while( curTickerName != NULL && config.newMailsOnly && ( curTickerName->flag & FLAG_READ )); + while( curTickerName != NULL && config.newMailsOnly && + ( curTickerName->flag & FLAG_READ )); - if( curTickerName != NULL ) { + if( curTickerName != NULL ) insertAt = 54; - } } } static void DrawTickerBuildinFont( void ) { - // 49x21+7+20 out-drawable size - // 14x21 font-character size + // 49 x 21 + 7 + 20 out-drawable size + // 14 x 21 font-character size static unsigned insertAt; static unsigned takeItFrom; @@ -1392,11 +1542,12 @@ if( names == NULL ) return; - if( curTickerName == NULL || namesChanged ) { - + if( curTickerName == NULL || namesChanged ) + { for( curTickerName = names; curTickerName != NULL && config.newMailsOnly && ( curTickerName->flag & FLAG_READ ); - curTickerName = curTickerName->next ); + curTickerName = curTickerName->next ) + ; if( curTickerName == NULL ) return; @@ -1411,13 +1562,12 @@ for( currentChar = (unsigned char *)&curTickerName->name[takeItFrom/14], drawTo = insertAt; *currentChar != '\0'; ++currentChar ) { - int outChar = (*currentChar < 32 || *currentChar >= 128) ? '?' : *currentChar; - int charWidth = 57-drawTo >= 14 ? 14 - leftSpace : 57-drawTo; + int charWidth = 57 - drawTo >= 14 ? 14 - leftSpace : 57 - drawTo; XCopyArea( DADisplay, charsPixmap, outPixmap, DAGC, - (outChar-32)*14+leftSpace, 0, charWidth, 21, drawTo, 20 ); + (outChar - 32) * 14 + leftSpace, 0, charWidth, 21, drawTo, 20 ); leftSpace = 0; drawTo += charWidth; @@ -1426,17 +1576,20 @@ break; } - if( --insertAt < 7 ) { + if( --insertAt < 7 ) + { insertAt = 7; takeItFrom++; - if( takeItFrom/14 >= strlen( curTickerName->name )) { - - do { + if( takeItFrom/14 >= strlen( curTickerName->name )) + { + do curTickerName = curTickerName->next; - } while( curTickerName != NULL && config.newMailsOnly && ( curTickerName->flag & FLAG_READ )); + while( curTickerName != NULL && config.newMailsOnly && + ( curTickerName->flag & FLAG_READ )); - if( curTickerName != NULL ) { + if( curTickerName != NULL ) + { takeItFrom = 0; insertAt = 57; } @@ -1449,10 +1602,12 @@ (void) button; (void) state; - if( x >= 35 && x <= 59 && y >= 47 && y <= 59 ) { + if( x >= 35 && x <= 59 && y >= 47 && y <= 59 ) + { buttonPressed = true; forceRedraw = true; - } else + } + else // reread the config file readConfigFile = true; @@ -1467,7 +1622,8 @@ buttonPressed = false; forceRedraw = true; - if( x >= 35 && x <= 59 && y >= 47 && y <= 59 ) { + if( x >= 35 && x <= 59 && y >= 47 && y <= 59 ) + { int ret = system( config.runCmd ); if( ret == 127 || ret == -1 ) @@ -1484,34 +1640,48 @@ if( XParseColor( DADisplay, DefaultColormap( DADisplay, DefaultScreen( DADisplay )), colorName, &color )) - { sprintf( xpmLine, "%02X%02X%02X", color.red>>8, color.green>>8, color.blue>>8 ); - } else + else WARNING( "unknown colorname: \"%s\"\n", colorName ); } -static char *XpmColorLine( const char *colorName, char *colorLine, +static int XpmColorLine( const char *colorName, char **colorLine, bool disposeLine ) { - char *newLine = strdup( colorLine ); - char *from = strrchr( newLine, '#' ); + char *newLine, *from; - if( from == NULL && !strcasecmp( &colorLine[ strlen( colorLine ) - 4 ], "none" )) { - // if no # found, it should be a None-color line + newLine = strdup( *colorLine ); + if ( newLine == NULL ) + return -1; + + from = strrchr( newLine, '#' ); + if( from == NULL && + strcasecmp( &(*colorLine)[ strlen( *colorLine ) - 4 ], "none" ) == 0 ) + { + /* + * if no # found, it should be a None-color line + */ free( newLine ); newLine = malloc( 12 ); - strcpy( newLine, " \tc #" ); - newLine[11] = '\0'; - from = newLine + 4; + if ( newLine != NULL ) + { + strcpy( newLine, " \tc #" ); + newLine[11] = '\0'; + from = newLine + 4; + } } + if( newLine == NULL) + return -1; + if( disposeLine ) - free( colorLine ); + free( *colorLine ); - GetHexColorString( colorName, from+1 ); + GetHexColorString( colorName, from + 1 ); - return newLine; + *colorLine = newLine; + return 0; } static void UpdateConfiguration( void ) @@ -1535,7 +1705,8 @@ TRACE( "mailbox is of type %s\n", isMaildir ? "maildir" : "mbox" ); - PreparePixmaps( true ); + if( PreparePixmaps( true ) < 0 ) + WARNING( "Cannot allocate color.\n" ); DASetTimeout( 1000 / config.fps ); } @@ -1550,7 +1721,8 @@ { nextName = name->next; - if( !name->visited ) { + if( !name->visited ) + { if( last == NULL ) names = name->next; else @@ -1558,7 +1730,11 @@ free( name->name ); free( name ); - } else { + + namesChanged = true; + } + else + { last = name; if( !config.newMailsOnly || (name->flag & FLAG_READ) == 0 ) @@ -1574,11 +1750,14 @@ if( names == NULL ) return false; - if( curTickerName == NULL || namesChanged ) { + if( curTickerName == NULL || namesChanged ) + { for( nextTickerName = names; - nextTickerName != NULL && ( config.newMailsOnly && ( nextTickerName->flag & FLAG_READ )); - nextTickerName = nextTickerName->next ); + nextTickerName != NULL && config.newMailsOnly && + ( nextTickerName->flag & FLAG_READ ); + nextTickerName = nextTickerName->next ) + ; if( nextTickerName == NULL ) return false; diff -Nru wmail-2.2/wmailrc-sample wmail-2.3/wmailrc-sample --- wmail-2.2/wmailrc-sample 2019-06-13 08:12:31.000000000 +0000 +++ wmail-2.3/wmailrc-sample 2019-06-21 19:01:47.000000000 +0000 @@ -1,6 +1,6 @@ #-*-shell-script-*-############################################################ # -# .wmailrc - wmail v2.2 configuration file +# .wmailrc - wmail v2.3 configuration file # note: cmd-line options always overide the settings in this file unless you # force runtime reconfiguration by clicking on the docklets display area # @@ -40,7 +40,7 @@ # mail-check interval in seconds # integer value, default: 1 -Mail.CheckIntervall = 5 +Mail.CheckInterval = 5 # setup the ticker-line: allowed values are: Address | NickName | FamilyName # enum value, default: Address