#include "quote_fmt.h"
#include "quote_fmt_lex.h"
+#include "account.h"
+#include "file-utils.h"
/* decl */
/*
if (visible == NULL)
maxsize = 0;
}
-
- visible[stacksize - 1] = val;
+ if (visible != NULL)
+ visible[stacksize - 1] = val;
}
static void remove_visibility(void)
{
stacksize--;
if (stacksize < 0) {
- g_warning("Error: visibility stack underflow\n");
+ g_warning("Error: visibility stack underflow");
stacksize = 0;
}
}
gchar *quote_fmt_get_buffer(void)
{
if (current != &main_expr)
- g_warning("Error: parser still in sub-expr mode\n");
+ g_warning("Error: parser still in sub-expr mode");
if (error != 0)
return NULL;
void quote_fmterror(char *str)
{
- g_warning("Error: %s at line %d\n", str, line);
+ g_warning("Error: %s at line %d", str, line);
error = 1;
}
return g_ascii_isspace(ch) || ch == '.' || ch == '-';
}
+/*
+ * Search for glibc extended strftime timezone specs within haystack.
+ * If not found NULL is returned and the integer pointed by tzspeclen is
+ * not changed.
+ * If found a pointer to the start of the specification within haystack
+ * is returned and the integer pointed by tzspeclen is set to the lenght
+ * of specification.
+ */
+static const char* strtzspec(const char *haystack, int *tzspeclen)
+{
+ const char *p = NULL;
+ const char *q = NULL;
+ const char *r = NULL;
+
+ p = strstr(haystack, "%");
+ while (p != NULL) {
+ q = p + 1;
+ if (!*q) return NULL;
+ r = strchr("_-0^#", *q); /* skip flags */
+ if (r != NULL) {
+ ++q;
+ if (!*q) return NULL;
+ }
+ while (*q >= '0' && *q <= '9') ++q; /* skip width */
+ if (!*q) return NULL;
+ if (*q == 'z' || *q == 'Z') { /* numeric or name */
+ *tzspeclen = 1 + (q - p);
+ return p;
+ }
+ p = strstr(q, "%");
+ }
+ return NULL;
+}
+
static void quote_fmt_show_date(const MsgInfo *msginfo, const gchar *format)
{
char result[100];
*/
#define RLEFT (sizeof result) - (rptr - result)
-#define STR_SIZE(x) (sizeof (x) - 1)
zone[0] = 0;
* feed it to strftime(). don't forget that '%%z' mean literal '%z'.
*/
for (rptr = result, fptr = format; fptr && *fptr && rptr < &result[sizeof result - 1];) {
- int perc;
+ int perc, zlen;
const char *p;
char *tmp;
- if (NULL != (zptr = strstr(fptr, "%z"))) {
+ if (NULL != (zptr = strtzspec(fptr, &zlen))) {
/*
* count nr. of prepended percent chars
*/
/*
* feed to strftime()
*/
- tmp = g_strndup(fptr, zptr - fptr + (perc % 2 ? 0 : STR_SIZE("%z")));
+ tmp = g_strndup(fptr, zptr - fptr + (perc % 2 ? 0 : zlen));
if (tmp) {
rptr += strftime(rptr, RLEFT, tmp, <);
g_free(tmp);
*/
if (zone[0] && perc % 2)
rptr += g_snprintf(rptr, RLEFT, "%s", zone);
- fptr = zptr + STR_SIZE("%z");
+ fptr = zptr + zlen;
} else {
rptr += strftime(rptr, RLEFT, fptr, <);
fptr = NULL;
g_free(utf);
}
}
-#undef STR_SIZE
#undef RLEFT
}
}
if (fp == NULL)
- g_warning("Can't get text part\n");
+ g_warning("Can't get text part");
else {
+ account_sigsep_matchlist_create();
while (fgets(buf, sizeof(buf), fp) != NULL) {
strcrchomp(buf);
-
- if (!signature && strncmp(buf, "-- \n", 4) == 0)
+
+ if (!signature && account_sigsep_matchlist_nchar_found(buf, "%s\n"))
break;
if (quoted && quote_str)
INSERT(buf);
}
+ account_sigsep_matchlist_delete();
fclose(fp);
}
}
static void quote_fmt_insert_file(const gchar *filename)
{
FILE *file;
- char buffer[256];
+ char buffer[PATH_MAX];
if ((file = g_fopen(filename, "rb")) != NULL) {
while (fgets(buffer, sizeof(buffer), file)) {
static void quote_fmt_insert_program_output(const gchar *progname)
{
FILE *file;
- char buffer[256];
+ char buffer[PATH_MAX];
if ((file = popen(progname, "r")) != NULL) {
while (fgets(buffer, sizeof(buffer), file)) {
attachments = g_list_append(attachments, g_strdup(filename));
}
+static void quote_fmt_attach_file_program_output(const gchar *progname)
+{
+ FILE *file;
+ char buffer[PATH_MAX];
+
+ if ((file = popen(progname, "r")) != NULL) {
+ /* get first line only */
+ if (fgets(buffer, sizeof(buffer), file)) {
+ /* trim trailing CR/LF */
+ strretchomp(buffer);
+ attachments = g_list_append(attachments, g_strdup(buffer));
+ }
+ pclose(file);
+ }
+}
+
static gchar *quote_fmt_complete_address(const gchar *addr)
{
gint count;
%token SHOW_QUOTED_MESSAGE_NO_SIGNATURE SHOW_MESSAGE_NO_SIGNATURE
%token SHOW_EOL SHOW_QUESTION_MARK SHOW_EXCLAMATION_MARK SHOW_PIPE SHOW_OPARENT SHOW_CPARENT
%token SHOW_ACCOUNT_FULL_NAME SHOW_ACCOUNT_MAIL_ADDRESS SHOW_ACCOUNT_NAME SHOW_ACCOUNT_ORGANIZATION
-%token SHOW_ACCOUNT_DICT
+%token SHOW_ACCOUNT_DICT SHOW_ACCOUNT_SIG SHOW_ACCOUNT_SIGPATH
%token SHOW_DICT SHOW_TAGS
%token SHOW_ADDRESSBOOK_COMPLETION_FOR_CC
%token SHOW_ADDRESSBOOK_COMPLETION_FOR_FROM
%token QUERY_FULLNAME QUERY_SUBJECT QUERY_TO QUERY_NEWSGROUPS
%token QUERY_MESSAGEID QUERY_CC QUERY_REFERENCES
%token QUERY_ACCOUNT_FULL_NAME QUERY_ACCOUNT_ORGANIZATION QUERY_ACCOUNT_DICT
+%token QUERY_ACCOUNT_SIG QUERY_ACCOUNT_SIGPATH
%token QUERY_DICT
%token QUERY_CC_FOUND_IN_ADDRESSBOOK
%token QUERY_FROM_FOUND_IN_ADDRESSBOOK
%token QUERY_NOT_FULLNAME QUERY_NOT_SUBJECT QUERY_NOT_TO QUERY_NOT_NEWSGROUPS
%token QUERY_NOT_MESSAGEID QUERY_NOT_CC QUERY_NOT_REFERENCES
%token QUERY_NOT_ACCOUNT_FULL_NAME QUERY_NOT_ACCOUNT_ORGANIZATION QUERY_NOT_ACCOUNT_DICT
+%token QUERY_NOT_ACCOUNT_SIG QUERY_NOT_ACCOUNT_SIGPATH
%token QUERY_NOT_DICT
%token QUERY_NOT_CC_FOUND_IN_ADDRESSBOOK
%token QUERY_NOT_FROM_FOUND_IN_ADDRESSBOOK
%token QUERY_NOT_TO_FOUND_IN_ADDRESSBOOK
/* other tokens */
%token INSERT_FILE INSERT_PROGRAMOUTPUT INSERT_USERINPUT
-%token ATTACH_FILE
+%token ATTACH_FILE ATTACH_PROGRAMOUTPUT
%token OPARENT CPARENT
%token CHARACTER
%token SHOW_DATE_EXPR
%start quote_fmt
-%token <chr> CHARACTER
+%type <chr> CHARACTER
%type <chr> character
%type <str> string
if (account && account->organization)
INSERT(account->organization);
}
+ | SHOW_ACCOUNT_SIG
+ {
+ gchar *str = account_get_signature_str(account);
+ INSERT(str);
+ g_free(str);
+ }
+ | SHOW_ACCOUNT_SIGPATH
+ {
+ if (account && account->sig_path)
+ INSERT(account->sig_path);
+ }
| SHOW_ACCOUNT_DICT
{
#ifdef USE_ENCHANT
{
remove_visibility();
}
+ | QUERY_ACCOUNT_SIG
+ {
+ gchar *str = account_get_signature_str(account);
+ add_visibility(str != NULL && * str != '\0');
+ g_free(str);
+ }
+ OPARENT quote_fmt CPARENT
+ {
+ remove_visibility();
+ }
+ | QUERY_ACCOUNT_SIGPATH
+ {
+ add_visibility(account != NULL && account->sig_path != NULL
+ && *account->sig_path != '\0');
+ }
+ OPARENT quote_fmt CPARENT
+ {
+ remove_visibility();
+ }
| QUERY_ACCOUNT_DICT
{
#ifdef USE_ENCHANT
{
remove_visibility();
}
+ | QUERY_NOT_ACCOUNT_SIG
+ {
+ gchar *str = account_get_signature_str(account);
+ add_visibility(str == NULL || *str == '\0');
+ g_free(str);
+ }
+ OPARENT quote_fmt CPARENT
+ {
+ remove_visibility();
+ }
+ | QUERY_NOT_ACCOUNT_SIGPATH
+ {
+ add_visibility(account == NULL || account->sig_path == NULL
+ || *account->sig_path == '\0');
+ }
+ OPARENT quote_fmt CPARENT
+ {
+ remove_visibility();
+ }
| QUERY_NOT_ACCOUNT_DICT
{
#ifdef USE_ENCHANT
if (!dry_run) {
quote_fmt_attach_file(sub_expr.buffer);
}
+ }
+ | ATTACH_PROGRAMOUTPUT
+ {
+ current = &sub_expr;
+ clear_buffer();
+ }
+ OPARENT sub_expr CPARENT
+ {
+ current = &main_expr;
+ if (!dry_run) {
+ quote_fmt_attach_file_program_output(sub_expr.buffer);
+ }
};
+;