fad68bbfec
* src/account.c * src/account.h * src/action.c * src/action.h * src/adbookbase.h * src/addr_compl.c * src/addr_compl.h * src/addrbook.c * src/addrcache.c * src/addrcache.h * src/addrcindex.c * src/addrcindex.h * src/addrclip.c * src/addrclip.h * src/addrdefs.h * src/addressadd.c * src/addressadd.h * src/addressbook.c * src/addressbook.h * src/addressbook_foldersel.c * src/addressbook_foldersel.h * src/addrgather.c * src/addrgather.h * src/addrharvest.c * src/addrharvest.h * src/addrindex.c * src/addrindex.h * src/addritem.c * src/addritem.h * src/addrquery.c * src/addrquery.h * src/addrselect.c * src/addrselect.h * src/alertpanel.c * src/alertpanel.h * src/browseldap.c * src/browseldap.h * src/codeconv.c * src/codeconv.h * src/compose.c * src/compose.h * src/customheader.c * src/customheader.h * src/displayheader.c * src/displayheader.h * src/editaddress.c * src/editaddress.h * src/editbook.c * src/editbook.h * src/editgroup.c * src/editgroup.h * src/editjpilot.c * src/editjpilot.h * src/editldap.c * src/editldap.h * src/editldap_basedn.c * src/editldap_basedn.h * src/editvcard.c * src/editvcard.h * src/exphtmldlg.c * src/exphtmldlg.h * src/expldifdlg.c * src/expldifdlg.h * src/export.c * src/export.h * src/exporthtml.c * src/exporthtml.h * src/exportldif.c * src/exportldif.h * src/filtering.c * src/filtering.h * src/folder.c * src/folder.h * src/folder_item_prefs.c * src/folder_item_prefs.h * src/foldersel.c * src/foldersel.h * src/folderutils.c * src/folderutils.h * src/folderview.c * src/folderview.h * src/grouplistdialog.c * src/grouplistdialog.h * src/headerview.c * src/html.c * src/html.h * src/image_viewer.c * src/image_viewer.h * src/imap.c * src/imap.h * src/imap_gtk.c * src/imap_gtk.h * src/import.c * src/import.h * src/importldif.c * src/importldif.h * src/importmutt.c * src/importmutt.h * src/importpine.c * src/importpine.h * src/inc.c * src/inc.h * src/jpilot.c * src/jpilot.h * src/ldapctrl.c * src/ldapctrl.h * src/ldaplocate.c * src/ldaplocate.h * src/ldapquery.c * src/ldapquery.h * src/ldapserver.c * src/ldapserver.h * src/ldaputil.c * src/ldaputil.h * src/ldif.c * src/ldif.h * src/main.c * src/main.h * src/mainwindow.c * src/mainwindow.h * src/manual.c * src/manual.h * src/mbox.c * src/message_search.c * src/message_search.h * src/messageview.c * src/messageview.h * src/mh.c * src/mh.h * src/mh_gtk.c * src/mh_gtk.h * src/mimeview.c * src/mimeview.h * src/msgcache.c * src/msgcache.h * src/mutt.c * src/mutt.h * src/news.c * src/news.h * src/news_gtk.c * src/news_gtk.h * src/partial_download.c * src/partial_download.h * src/pine.c * src/pine.h * src/pop.c * src/pop.h * src/prefs_account.c * src/prefs_account.h * src/prefs_actions.c * src/prefs_actions.h * src/prefs_common.c * src/prefs_common.h * src/prefs_compose_writing.c * src/prefs_compose_writing.h * src/prefs_customheader.c * src/prefs_customheader.h * src/prefs_display_header.c * src/prefs_display_header.h * src/prefs_filtering.c * src/prefs_filtering.h * src/prefs_filtering_action.c * src/prefs_filtering_action.h * src/prefs_folder_column.c * src/prefs_folder_column.h * src/prefs_folder_item.c * src/prefs_folder_item.h * src/prefs_fonts.c * src/prefs_fonts.h * src/prefs_gtk.c * src/prefs_gtk.h * src/prefs_image_viewer.c * src/prefs_image_viewer.h * src/prefs_matcher.c * src/prefs_matcher.h * src/prefs_message.c * src/prefs_msg_colors.c * src/prefs_msg_colors.h * src/prefs_other.c * src/prefs_quote.c * src/prefs_receive.c * src/prefs_send.c * src/prefs_spelling.c * src/prefs_spelling.h * src/prefs_summaries.c * src/prefs_summaries.h * src/prefs_summary_column.c * src/prefs_summary_column.h * src/prefs_template.c * src/prefs_template.h * src/prefs_themes.c * src/prefs_themes.h * src/prefs_toolbar.c * src/prefs_toolbar.h * src/prefs_wrapping.c * src/prefs_wrapping.h * src/privacy.c * src/privacy.h * src/procheader.c * src/procheader.h * src/procmime.c * src/procmime.h * src/procmsg.c * src/procmsg.h * src/quote_fmt.c * src/quote_fmt_parse.y * src/recv.c * src/recv.h * src/remotefolder.c * src/remotefolder.h * src/send_message.c * src/send_message.h * src/setup.c * src/setup.h * src/sourcewindow.c * src/sourcewindow.h * src/ssl_manager.c * src/ssl_manager.h * src/statusbar.c * src/statusbar.h * src/stock_pixmap.c * src/stock_pixmap.h * src/summary_search.c * src/summary_search.h * src/summaryview.c * src/summaryview.h * src/textview.c * src/textview.h * src/toolbar.c * src/toolbar.h * src/undo.c * src/undo.h * src/unmime.c * src/unmime.h * src/vcard.c * src/vcard.h * src/wizard.c * src/wizard.h * src/common/base64.c * src/common/base64.h * src/common/defs.h * src/common/hooks.c * src/common/hooks.h * src/common/log.c * src/common/log.h * src/common/mgutils.c * src/common/mgutils.h * src/common/nntp.c * src/common/nntp.h * src/common/passcrypt.c * src/common/passcrypt.h.in * src/common/plugin.c * src/common/plugin.h * src/common/prefs.c * src/common/prefs.h * src/common/progressindicator.c * src/common/progressindicator.h * src/common/quoted-printable.c * src/common/quoted-printable.h * src/common/session.c * src/common/session.h * src/common/smtp.c * src/common/smtp.h * src/common/socket.c * src/common/socket.h * src/common/ssl.c * src/common/ssl.h * src/common/ssl_certificate.c * src/common/ssl_certificate.h * src/common/stringtable.c * src/common/stringtable.h * src/common/template.c * src/common/template.h * src/common/timing.h * src/common/utils.c * src/common/utils.h * src/common/version.h.in * src/common/xml.c * src/common/xml.h * src/common/xmlprops.c * src/common/xmlprops.h * src/gtk/about.c * src/gtk/colorlabel.c * src/gtk/colorsel.c * src/gtk/colorsel.h * src/gtk/combobox.c * src/gtk/combobox.h * src/gtk/description_window.c * src/gtk/description_window.h * src/gtk/filesel.c * src/gtk/filesel.h * src/gtk/foldersort.c * src/gtk/foldersort.h * src/gtk/gtksctree.c * src/gtk/gtkutils.c * src/gtk/gtkutils.h * src/gtk/inputdialog.c * src/gtk/inputdialog.h * src/gtk/logwindow.c * src/gtk/logwindow.h * src/gtk/manage_window.c * src/gtk/manage_window.h * src/gtk/menu.c * src/gtk/menu.h * src/gtk/pluginwindow.c * src/gtk/pluginwindow.h * src/gtk/prefswindow.c * src/gtk/prefswindow.h * src/gtk/progressdialog.c * src/gtk/progressdialog.h * src/gtk/sslcertwindow.c * src/gtk/sslcertwindow.h * src/plugins/bogofilter/bogofilter.c * src/plugins/bogofilter/bogofilter.h * src/plugins/bogofilter/bogofilter_gtk.c * src/plugins/clamav/clamav_plugin.c * src/plugins/clamav/clamav_plugin.h * src/plugins/clamav/clamav_plugin_gtk.c * src/plugins/demo/demo.c * src/plugins/dillo_viewer/dillo_prefs.c * src/plugins/dillo_viewer/dillo_prefs.h * src/plugins/dillo_viewer/dillo_viewer.c * src/plugins/pgpcore/passphrase.c * src/plugins/pgpcore/passphrase.h * src/plugins/pgpcore/pgp_viewer.c * src/plugins/pgpcore/pgp_viewer.h * src/plugins/pgpcore/plugin.c * src/plugins/pgpcore/select-keys.c * src/plugins/pgpcore/select-keys.h * src/plugins/pgpcore/sgpgme.c * src/plugins/pgpcore/sgpgme.h * src/plugins/pgpinline/pgpinline.c * src/plugins/pgpinline/pgpinline.h * src/plugins/pgpinline/plugin.c * src/plugins/pgpmime/pgpmime.c * src/plugins/pgpmime/pgpmime.h * src/plugins/pgpmime/plugin.c * src/plugins/spamassassin/spamassassin.c * src/plugins/spamassassin/spamassassin.h * src/plugins/spamassassin/spamassassin_gtk.c * src/plugins/trayicon/trayicon.c it's 2007, update the year in the copyright headers
945 lines
18 KiB
Text
945 lines
18 KiB
Text
/*
|
|
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
|
|
* Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail Team
|
|
*
|
|
* 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 of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
*/
|
|
|
|
%{
|
|
|
|
#include "defs.h"
|
|
|
|
#include <glib.h>
|
|
#include <glib/gi18n.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include "procmsg.h"
|
|
#include "procmime.h"
|
|
#include "utils.h"
|
|
#include "codeconv.h"
|
|
#include "procheader.h"
|
|
#include "gtk/inputdialog.h"
|
|
|
|
#include "quote_fmt.h"
|
|
#include "quote_fmt_lex.h"
|
|
|
|
/* decl */
|
|
/*
|
|
flex quote_fmt.l
|
|
bison -p quote_fmt quote_fmt.y
|
|
*/
|
|
|
|
int yylex(void);
|
|
|
|
static MsgInfo *msginfo = NULL;
|
|
static PrefsAccount *account = NULL;
|
|
static gboolean *visible = NULL;
|
|
static gboolean dry_run = FALSE;
|
|
static gint maxsize = 0;
|
|
static gint stacksize = 0;
|
|
static GHashTable *var_table = NULL;
|
|
|
|
typedef struct st_buffer
|
|
{
|
|
gchar *buffer;
|
|
gint bufsize;
|
|
gint bufmax;
|
|
} st_buffer;
|
|
|
|
static struct st_buffer main_expr = { NULL, 0, 0 };
|
|
static struct st_buffer sub_expr = { NULL, 0, 0 };
|
|
static struct st_buffer* current = NULL;
|
|
|
|
static const gchar *quote_str = NULL;
|
|
static const gchar *body = NULL;
|
|
static gint error = 0;
|
|
|
|
static gint cursor_pos = -1;
|
|
|
|
extern int quote_fmt_firsttime;
|
|
|
|
static void add_visibility(gboolean val)
|
|
{
|
|
stacksize++;
|
|
if (maxsize < stacksize) {
|
|
maxsize += 128;
|
|
visible = g_realloc(visible, maxsize * sizeof(gboolean));
|
|
if (visible == NULL)
|
|
maxsize = 0;
|
|
}
|
|
|
|
visible[stacksize - 1] = val;
|
|
}
|
|
|
|
static void remove_visibility(void)
|
|
{
|
|
stacksize--;
|
|
if (stacksize < 0) {
|
|
g_warning("Error: visibility stack underflow\n");
|
|
stacksize = 0;
|
|
}
|
|
}
|
|
|
|
static void add_buffer(const gchar *s)
|
|
{
|
|
gint len;
|
|
|
|
if (s == NULL)
|
|
return;
|
|
|
|
len = strlen(s);
|
|
if (current->bufsize + len + 1 > current->bufmax) {
|
|
if (current->bufmax == 0)
|
|
current->bufmax = 128;
|
|
while (current->bufsize + len + 1 > current->bufmax)
|
|
current->bufmax *= 2;
|
|
current->buffer = g_realloc(current->buffer, current->bufmax);
|
|
}
|
|
strcpy(current->buffer + current->bufsize, s);
|
|
current->bufsize += len;
|
|
}
|
|
|
|
static void clear_buffer(void)
|
|
{
|
|
if (current->buffer)
|
|
*current->buffer = '\0';
|
|
else
|
|
/* force to an empty string, as buffer should not be left unallocated */
|
|
add_buffer("");
|
|
current->bufsize = 0;
|
|
}
|
|
|
|
gchar *quote_fmt_get_buffer(void)
|
|
{
|
|
if (current != &main_expr)
|
|
g_warning("Error: parser still in sub-expr mode\n");
|
|
|
|
if (error != 0)
|
|
return NULL;
|
|
else
|
|
return current->buffer;
|
|
}
|
|
|
|
gint quote_fmt_get_cursor_pos(void)
|
|
{
|
|
return cursor_pos;
|
|
}
|
|
|
|
#define INSERT(buf) \
|
|
if (stacksize != 0 && visible[stacksize - 1])\
|
|
add_buffer(buf); \
|
|
|
|
#define INSERT_CHARACTER(chr) \
|
|
if (stacksize != 0 && visible[stacksize - 1]) { \
|
|
gchar tmp[2]; \
|
|
tmp[0] = (chr); \
|
|
tmp[1] = '\0'; \
|
|
add_buffer(tmp); \
|
|
}
|
|
|
|
void quote_fmt_reset_vartable(void)
|
|
{
|
|
if (var_table) {
|
|
g_hash_table_destroy(var_table);
|
|
var_table = NULL;
|
|
}
|
|
}
|
|
|
|
void quote_fmt_init(MsgInfo *info, const gchar *my_quote_str,
|
|
const gchar *my_body, gboolean my_dry_run,
|
|
PrefsAccount *compose_account)
|
|
{
|
|
quote_str = my_quote_str;
|
|
body = my_body;
|
|
msginfo = info;
|
|
account = compose_account;
|
|
dry_run = my_dry_run;
|
|
stacksize = 0;
|
|
add_visibility(TRUE);
|
|
main_expr.bufmax = 0;
|
|
sub_expr.bufmax = 0;
|
|
current = &main_expr;
|
|
clear_buffer();
|
|
error = 0;
|
|
|
|
if (!var_table)
|
|
var_table = g_hash_table_new_full(g_str_hash, g_str_equal,
|
|
g_free, g_free);
|
|
|
|
/*
|
|
* force LEX initialization
|
|
*/
|
|
quote_fmt_firsttime = 1;
|
|
cursor_pos = -1;
|
|
}
|
|
|
|
void quote_fmterror(char *str)
|
|
{
|
|
g_warning("Error: %s\n", str);
|
|
error = 1;
|
|
}
|
|
|
|
int quote_fmtwrap(void)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
static int isseparator(int ch)
|
|
{
|
|
return g_ascii_isspace(ch) || ch == '.' || ch == '-';
|
|
}
|
|
|
|
static void quote_fmt_show_date(const MsgInfo *msginfo, const gchar *format)
|
|
{
|
|
char result[100];
|
|
char *rptr;
|
|
char zone[6];
|
|
struct tm lt;
|
|
const char *fptr;
|
|
const char *zptr;
|
|
|
|
if (!msginfo->date)
|
|
return;
|
|
|
|
/*
|
|
* ALF - GNU C's strftime() has a nice format specifier
|
|
* for time zone offset (%z). Non-standard however, so
|
|
* emulate it.
|
|
*/
|
|
|
|
#define RLEFT (sizeof result) - (rptr - result)
|
|
#define STR_SIZE(x) (sizeof (x) - 1)
|
|
|
|
zone[0] = 0;
|
|
|
|
if (procheader_date_parse_to_tm(msginfo->date, <, zone)) {
|
|
/*
|
|
* break up format string in tiny bits delimited by valid %z's and
|
|
* 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;
|
|
const char *p;
|
|
char *tmp;
|
|
|
|
if (NULL != (zptr = strstr(fptr, "%z"))) {
|
|
/*
|
|
* count nr. of prepended percent chars
|
|
*/
|
|
for (perc = 0, p = zptr; p && p >= format && *p == '%'; p--, perc++)
|
|
;
|
|
/*
|
|
* feed to strftime()
|
|
*/
|
|
tmp = g_strndup(fptr, zptr - fptr + (perc % 2 ? 0 : STR_SIZE("%z")));
|
|
if (tmp) {
|
|
rptr += strftime(rptr, RLEFT, tmp, <);
|
|
g_free(tmp);
|
|
}
|
|
/*
|
|
* append time zone offset
|
|
*/
|
|
if (zone[0] && perc % 2)
|
|
rptr += g_snprintf(rptr, RLEFT, "%s", zone);
|
|
fptr = zptr + STR_SIZE("%z");
|
|
} else {
|
|
rptr += strftime(rptr, RLEFT, fptr, <);
|
|
fptr = NULL;
|
|
}
|
|
}
|
|
|
|
if (g_utf8_validate(result, -1, NULL)) {
|
|
INSERT(result);
|
|
} else {
|
|
gchar *utf = conv_codeset_strdup(result,
|
|
conv_get_locale_charset_str_no_utf8(),
|
|
CS_INTERNAL);
|
|
if (utf == NULL ||
|
|
!g_utf8_validate(utf, -1, NULL)) {
|
|
g_free(utf);
|
|
utf = g_malloc(strlen(result)*2+1);
|
|
conv_localetodisp(utf,
|
|
strlen(result)*2+1, result);
|
|
}
|
|
if (g_utf8_validate(utf, -1, NULL)) {
|
|
INSERT(utf);
|
|
}
|
|
g_free(utf);
|
|
}
|
|
}
|
|
#undef STR_SIZE
|
|
#undef RLEFT
|
|
}
|
|
|
|
static void quote_fmt_show_first_name(const MsgInfo *msginfo)
|
|
{
|
|
guchar *p;
|
|
gchar *str;
|
|
|
|
if (!msginfo->fromname)
|
|
return;
|
|
|
|
p = (guchar*)strchr(msginfo->fromname, ',');
|
|
if (p != NULL) {
|
|
/* fromname is like "Duck, Donald" */
|
|
p++;
|
|
while (*p && isspace(*p)) p++;
|
|
str = alloca(strlen((char *)p) + 1);
|
|
if (str != NULL) {
|
|
strcpy(str, (char *)p);
|
|
INSERT(str);
|
|
}
|
|
} else {
|
|
/* fromname is like "Donald Duck" */
|
|
str = alloca(strlen(msginfo->fromname) + 1);
|
|
if (str != NULL) {
|
|
strcpy(str, msginfo->fromname);
|
|
p = (guchar *)str;
|
|
while (*p && !isspace(*p)) p++;
|
|
*p = '\0';
|
|
INSERT(str);
|
|
}
|
|
}
|
|
}
|
|
|
|
static void quote_fmt_show_last_name(const MsgInfo *msginfo)
|
|
{
|
|
gchar *p;
|
|
gchar *str;
|
|
|
|
/* This probably won't work together very well with Middle
|
|
names and the like - thth */
|
|
if (!msginfo->fromname)
|
|
return;
|
|
|
|
str = alloca(strlen(msginfo->fromname) + 1);
|
|
if (str != NULL) {
|
|
strcpy(str, msginfo->fromname);
|
|
p = strchr(str, ',');
|
|
if (p != NULL) {
|
|
/* fromname is like "Duck, Donald" */
|
|
*p = '\0';
|
|
INSERT(str);
|
|
} else {
|
|
/* fromname is like "Donald Duck" */
|
|
p = str;
|
|
while (*p && !isspace(*p)) p++;
|
|
if (*p) {
|
|
/* We found a space. Get first
|
|
none-space char and insert
|
|
rest of string from there. */
|
|
while (*p && isspace(*p)) p++;
|
|
if (*p) {
|
|
INSERT(p);
|
|
} else {
|
|
/* If there is no none-space
|
|
char, just insert whole
|
|
fromname. */
|
|
INSERT(str);
|
|
}
|
|
} else {
|
|
/* If there is no space, just
|
|
insert whole fromname. */
|
|
INSERT(str);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static void quote_fmt_show_sender_initial(const MsgInfo *msginfo)
|
|
{
|
|
#define MAX_SENDER_INITIAL 20
|
|
gchar tmp[MAX_SENDER_INITIAL];
|
|
guchar *p;
|
|
gchar *cur;
|
|
gint len = 0;
|
|
|
|
if (!msginfo->fromname)
|
|
return;
|
|
|
|
p = (guchar *)msginfo->fromname;
|
|
cur = tmp;
|
|
while (*p) {
|
|
if (*p && g_utf8_validate((gchar *)p, 1, NULL)) {
|
|
*cur = toupper(*p);
|
|
cur++;
|
|
len++;
|
|
if (len >= MAX_SENDER_INITIAL - 1)
|
|
break;
|
|
} else
|
|
break;
|
|
while (*p && !isseparator(*p)) p++;
|
|
while (*p && isseparator(*p)) p++;
|
|
}
|
|
*cur = '\0';
|
|
INSERT(tmp);
|
|
}
|
|
|
|
static void quote_fmt_show_msg(MsgInfo *msginfo, const gchar *body,
|
|
gboolean quoted, gboolean signature,
|
|
const gchar *quote_str)
|
|
{
|
|
gchar buf[BUFFSIZE];
|
|
FILE *fp;
|
|
|
|
if (!(msginfo->folder || body))
|
|
return;
|
|
|
|
if (body)
|
|
fp = str_open_as_stream(body);
|
|
else {
|
|
if (procmime_msginfo_is_encrypted(msginfo))
|
|
fp = procmime_get_first_encrypted_text_content(msginfo);
|
|
else
|
|
fp = procmime_get_first_text_content(msginfo);
|
|
}
|
|
|
|
if (fp == NULL)
|
|
g_warning("Can't get text part\n");
|
|
else {
|
|
while (fgets(buf, sizeof(buf), fp) != NULL) {
|
|
strcrchomp(buf);
|
|
|
|
if (!signature && strncmp(buf, "-- \n", 4) == 0)
|
|
break;
|
|
|
|
if (quoted && quote_str)
|
|
INSERT(quote_str);
|
|
|
|
INSERT(buf);
|
|
}
|
|
fclose(fp);
|
|
}
|
|
}
|
|
|
|
static void quote_fmt_insert_file(const gchar *filename)
|
|
{
|
|
FILE *file;
|
|
char buffer[256];
|
|
|
|
if ((file = g_fopen(filename, "rb")) != NULL) {
|
|
while (fgets(buffer, sizeof(buffer), file)) {
|
|
INSERT(buffer);
|
|
}
|
|
fclose(file);
|
|
}
|
|
|
|
}
|
|
|
|
static void quote_fmt_insert_program_output(const gchar *progname)
|
|
{
|
|
FILE *file;
|
|
char buffer[256];
|
|
|
|
if ((file = popen(progname, "r")) != NULL) {
|
|
while (fgets(buffer, sizeof(buffer), file)) {
|
|
INSERT(buffer);
|
|
}
|
|
pclose(file);
|
|
}
|
|
}
|
|
|
|
static void quote_fmt_insert_user_input(const gchar *varname)
|
|
{
|
|
gchar *buf = NULL;
|
|
gchar *text = NULL;
|
|
|
|
if (dry_run)
|
|
return;
|
|
|
|
if ((text = g_hash_table_lookup(var_table, varname)) == NULL) {
|
|
buf = g_strdup_printf(_("Enter text to replace '%s'"), varname);
|
|
text = input_dialog(_("Enter variable"), buf, "");
|
|
g_free(buf);
|
|
if (!text)
|
|
return;
|
|
g_hash_table_insert(var_table, g_strdup(varname), g_strdup(text));
|
|
} else {
|
|
/* don't free the one in hashtable at the end */
|
|
text = g_strdup(text);
|
|
}
|
|
|
|
if (!text)
|
|
return;
|
|
INSERT(text);
|
|
g_free(text);
|
|
}
|
|
|
|
%}
|
|
|
|
%union {
|
|
char chr;
|
|
char str[256];
|
|
}
|
|
|
|
/* tokens SHOW */
|
|
%token SHOW_NEWSGROUPS
|
|
%token SHOW_DATE SHOW_FROM SHOW_FULLNAME SHOW_FIRST_NAME SHOW_LAST_NAME
|
|
%token SHOW_SENDER_INITIAL SHOW_SUBJECT SHOW_TO SHOW_MESSAGEID
|
|
%token SHOW_PERCENT SHOW_CC SHOW_REFERENCES SHOW_MESSAGE
|
|
%token SHOW_QUOTED_MESSAGE SHOW_BACKSLASH SHOW_TAB
|
|
%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
|
|
/* tokens QUERY */
|
|
%token QUERY_DATE QUERY_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
|
|
/* tokens QUERY_NOT */
|
|
%token QUERY_NOT_DATE QUERY_NOT_FROM
|
|
%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
|
|
/* other tokens */
|
|
%token INSERT_FILE INSERT_PROGRAMOUTPUT INSERT_USERINPUT
|
|
%token OPARENT CPARENT
|
|
%token CHARACTER
|
|
%token SHOW_DATE_EXPR
|
|
%token SET_CURSOR_POS
|
|
|
|
%start quote_fmt
|
|
|
|
%token <chr> CHARACTER
|
|
%type <chr> character
|
|
%type <str> string
|
|
|
|
%%
|
|
|
|
quote_fmt:
|
|
character_or_special_or_insert_or_query_list ;
|
|
|
|
sub_expr:
|
|
character_or_special_list ;
|
|
|
|
character_or_special_or_insert_or_query_list:
|
|
character_or_special_or_insert_or_query character_or_special_or_insert_or_query_list
|
|
| character_or_special_or_insert_or_query ;
|
|
|
|
character_or_special_list:
|
|
character_or_special character_or_special_list
|
|
| character_or_special ;
|
|
|
|
character_or_special_or_insert_or_query:
|
|
character_or_special
|
|
| query
|
|
| query_not
|
|
| insert ;
|
|
|
|
character_or_special:
|
|
special
|
|
| character
|
|
{
|
|
INSERT_CHARACTER($1);
|
|
};
|
|
|
|
character:
|
|
CHARACTER
|
|
;
|
|
|
|
string:
|
|
CHARACTER
|
|
{
|
|
$$[0] = $1;
|
|
$$[1] = '\0';
|
|
}
|
|
| string CHARACTER
|
|
{
|
|
int len;
|
|
|
|
strncpy($$, $1, sizeof($$));
|
|
$$[sizeof($$) - 1] = '\0';
|
|
len = strlen($$);
|
|
if (len + 1 < sizeof($$)) {
|
|
$$[len + 1] = '\0';
|
|
$$[len] = $2;
|
|
}
|
|
};
|
|
|
|
special:
|
|
SHOW_NEWSGROUPS
|
|
{
|
|
if (msginfo->newsgroups)
|
|
INSERT(msginfo->newsgroups);
|
|
}
|
|
| SHOW_DATE_EXPR OPARENT string CPARENT
|
|
{
|
|
quote_fmt_show_date(msginfo, $3);
|
|
}
|
|
| SHOW_DATE
|
|
{
|
|
if (msginfo->date)
|
|
INSERT(msginfo->date);
|
|
}
|
|
| SHOW_FROM
|
|
{
|
|
if (msginfo->from)
|
|
INSERT(msginfo->from);
|
|
}
|
|
| SHOW_FULLNAME
|
|
{
|
|
if (msginfo->fromname)
|
|
INSERT(msginfo->fromname);
|
|
}
|
|
| SHOW_FIRST_NAME
|
|
{
|
|
quote_fmt_show_first_name(msginfo);
|
|
}
|
|
| SHOW_LAST_NAME
|
|
{
|
|
quote_fmt_show_last_name(msginfo);
|
|
}
|
|
| SHOW_SENDER_INITIAL
|
|
{
|
|
quote_fmt_show_sender_initial(msginfo);
|
|
}
|
|
| SHOW_SUBJECT
|
|
{
|
|
if (msginfo->subject)
|
|
INSERT(msginfo->subject);
|
|
}
|
|
| SHOW_TO
|
|
{
|
|
if (msginfo->to)
|
|
INSERT(msginfo->to);
|
|
}
|
|
| SHOW_MESSAGEID
|
|
{
|
|
if (msginfo->msgid)
|
|
INSERT(msginfo->msgid);
|
|
}
|
|
| SHOW_PERCENT
|
|
{
|
|
INSERT("%");
|
|
}
|
|
| SHOW_CC
|
|
{
|
|
if (msginfo->cc)
|
|
INSERT(msginfo->cc);
|
|
}
|
|
| SHOW_REFERENCES
|
|
{
|
|
GSList *item;
|
|
|
|
INSERT(msginfo->inreplyto);
|
|
for (item = msginfo->references; item != NULL; item = g_slist_next(item))
|
|
if (item->data)
|
|
INSERT(item->data);
|
|
}
|
|
| SHOW_MESSAGE
|
|
{
|
|
quote_fmt_show_msg(msginfo, body, FALSE, TRUE, quote_str);
|
|
}
|
|
| SHOW_QUOTED_MESSAGE
|
|
{
|
|
quote_fmt_show_msg(msginfo, body, TRUE, TRUE, quote_str);
|
|
}
|
|
| SHOW_MESSAGE_NO_SIGNATURE
|
|
{
|
|
quote_fmt_show_msg(msginfo, body, FALSE, FALSE, quote_str);
|
|
}
|
|
| SHOW_QUOTED_MESSAGE_NO_SIGNATURE
|
|
{
|
|
quote_fmt_show_msg(msginfo, body, TRUE, FALSE, quote_str);
|
|
}
|
|
| SHOW_ACCOUNT_FULL_NAME
|
|
{
|
|
if (account && account->name)
|
|
INSERT(account->name);
|
|
}
|
|
| SHOW_ACCOUNT_MAIL_ADDRESS
|
|
{
|
|
if (account && account->address)
|
|
INSERT(account->address);
|
|
}
|
|
| SHOW_ACCOUNT_NAME
|
|
{
|
|
if (account && account->account_name)
|
|
INSERT(account->account_name);
|
|
}
|
|
| SHOW_ACCOUNT_ORGANIZATION
|
|
{
|
|
if (account && account->organization)
|
|
INSERT(account->organization);
|
|
}
|
|
| SHOW_BACKSLASH
|
|
{
|
|
INSERT("\\");
|
|
}
|
|
| SHOW_TAB
|
|
{
|
|
INSERT("\t");
|
|
}
|
|
| SHOW_EOL
|
|
{
|
|
INSERT("\n");
|
|
}
|
|
| SHOW_QUESTION_MARK
|
|
{
|
|
INSERT("?");
|
|
}
|
|
| SHOW_EXCLAMATION_MARK
|
|
{
|
|
INSERT("!");
|
|
}
|
|
| SHOW_PIPE
|
|
{
|
|
INSERT("|");
|
|
}
|
|
| SHOW_OPARENT
|
|
{
|
|
INSERT("{");
|
|
}
|
|
| SHOW_CPARENT
|
|
{
|
|
INSERT("}");
|
|
}
|
|
| SET_CURSOR_POS
|
|
{
|
|
cursor_pos = current->bufsize;
|
|
};
|
|
|
|
query:
|
|
QUERY_DATE
|
|
{
|
|
add_visibility(msginfo->date != NULL);
|
|
}
|
|
OPARENT quote_fmt CPARENT
|
|
{
|
|
remove_visibility();
|
|
}
|
|
| QUERY_FROM
|
|
{
|
|
add_visibility(msginfo->from != NULL);
|
|
}
|
|
OPARENT quote_fmt CPARENT
|
|
{
|
|
remove_visibility();
|
|
}
|
|
| QUERY_FULLNAME
|
|
{
|
|
add_visibility(msginfo->fromname != NULL);
|
|
}
|
|
OPARENT quote_fmt CPARENT
|
|
{
|
|
remove_visibility();
|
|
}
|
|
| QUERY_SUBJECT
|
|
{
|
|
add_visibility(msginfo->subject != NULL);
|
|
}
|
|
OPARENT quote_fmt CPARENT
|
|
{
|
|
remove_visibility();
|
|
}
|
|
| QUERY_TO
|
|
{
|
|
add_visibility(msginfo->to != NULL);
|
|
}
|
|
OPARENT quote_fmt CPARENT
|
|
{
|
|
remove_visibility();
|
|
}
|
|
| QUERY_NEWSGROUPS
|
|
{
|
|
add_visibility(msginfo->newsgroups != NULL);
|
|
}
|
|
OPARENT quote_fmt CPARENT
|
|
{
|
|
remove_visibility();
|
|
}
|
|
| QUERY_MESSAGEID
|
|
{
|
|
add_visibility(msginfo->msgid != NULL);
|
|
}
|
|
OPARENT quote_fmt CPARENT
|
|
{
|
|
remove_visibility();
|
|
}
|
|
| QUERY_CC
|
|
{
|
|
add_visibility(msginfo->cc != NULL);
|
|
}
|
|
OPARENT quote_fmt CPARENT
|
|
{
|
|
remove_visibility();
|
|
}
|
|
| QUERY_REFERENCES
|
|
{
|
|
gboolean found;
|
|
GSList *item;
|
|
|
|
found = (msginfo->inreplyto != NULL);
|
|
for (item = msginfo->references; found == FALSE && item != NULL; item = g_slist_next(item))
|
|
if (item->data)
|
|
found = TRUE;
|
|
add_visibility(found == TRUE);
|
|
}
|
|
OPARENT quote_fmt CPARENT
|
|
{
|
|
remove_visibility();
|
|
}
|
|
| QUERY_ACCOUNT_FULL_NAME
|
|
{
|
|
add_visibility(account != NULL && account->name != NULL);
|
|
}
|
|
OPARENT quote_fmt CPARENT
|
|
{
|
|
remove_visibility();
|
|
}
|
|
| QUERY_ACCOUNT_ORGANIZATION
|
|
{
|
|
add_visibility(account != NULL && account->organization != NULL);
|
|
}
|
|
OPARENT quote_fmt CPARENT
|
|
{
|
|
remove_visibility();
|
|
};
|
|
|
|
query_not:
|
|
QUERY_NOT_DATE
|
|
{
|
|
add_visibility(msginfo->date == NULL);
|
|
}
|
|
OPARENT quote_fmt CPARENT
|
|
{
|
|
remove_visibility();
|
|
}
|
|
| QUERY_NOT_FROM
|
|
{
|
|
add_visibility(msginfo->from == NULL);
|
|
}
|
|
OPARENT quote_fmt CPARENT
|
|
{
|
|
remove_visibility();
|
|
}
|
|
| QUERY_NOT_FULLNAME
|
|
{
|
|
add_visibility(msginfo->fromname == NULL);
|
|
}
|
|
OPARENT quote_fmt CPARENT
|
|
{
|
|
remove_visibility();
|
|
}
|
|
| QUERY_NOT_SUBJECT
|
|
{
|
|
add_visibility(msginfo->subject == NULL);
|
|
}
|
|
OPARENT quote_fmt CPARENT
|
|
{
|
|
remove_visibility();
|
|
}
|
|
| QUERY_NOT_TO
|
|
{
|
|
add_visibility(msginfo->to == NULL);
|
|
}
|
|
OPARENT quote_fmt CPARENT
|
|
{
|
|
remove_visibility();
|
|
}
|
|
| QUERY_NOT_NEWSGROUPS
|
|
{
|
|
add_visibility(msginfo->newsgroups == NULL);
|
|
}
|
|
OPARENT quote_fmt CPARENT
|
|
{
|
|
remove_visibility();
|
|
}
|
|
| QUERY_NOT_MESSAGEID
|
|
{
|
|
add_visibility(msginfo->msgid == NULL);
|
|
}
|
|
OPARENT quote_fmt CPARENT
|
|
{
|
|
remove_visibility();
|
|
}
|
|
| QUERY_NOT_CC
|
|
{
|
|
add_visibility(msginfo->cc == NULL);
|
|
}
|
|
OPARENT quote_fmt CPARENT
|
|
{
|
|
remove_visibility();
|
|
}
|
|
| QUERY_NOT_REFERENCES
|
|
{
|
|
gboolean found;
|
|
GSList *item;
|
|
|
|
found = (msginfo->inreplyto != NULL);
|
|
for (item = msginfo->references; found == FALSE && item != NULL; item = g_slist_next(item))
|
|
if (item->data)
|
|
found = TRUE;
|
|
add_visibility(found == FALSE);
|
|
}
|
|
OPARENT quote_fmt CPARENT
|
|
{
|
|
remove_visibility();
|
|
}
|
|
| QUERY_NOT_ACCOUNT_FULL_NAME
|
|
{
|
|
add_visibility(account == NULL || account->name == NULL);
|
|
}
|
|
OPARENT quote_fmt CPARENT
|
|
{
|
|
remove_visibility();
|
|
}
|
|
| QUERY_NOT_ACCOUNT_ORGANIZATION
|
|
{
|
|
add_visibility(account == NULL || account->organization == NULL);
|
|
}
|
|
OPARENT quote_fmt CPARENT
|
|
{
|
|
remove_visibility();
|
|
};
|
|
|
|
insert:
|
|
INSERT_FILE
|
|
{
|
|
current = &sub_expr;
|
|
clear_buffer();
|
|
}
|
|
OPARENT sub_expr CPARENT
|
|
{
|
|
current = &main_expr;
|
|
if (!dry_run) {
|
|
quote_fmt_insert_file(sub_expr.buffer);
|
|
}
|
|
}
|
|
| INSERT_PROGRAMOUTPUT
|
|
{
|
|
current = &sub_expr;
|
|
clear_buffer();
|
|
}
|
|
OPARENT sub_expr CPARENT
|
|
{
|
|
current = &main_expr;
|
|
if (!dry_run) {
|
|
quote_fmt_insert_program_output(sub_expr.buffer);
|
|
}
|
|
}
|
|
| INSERT_USERINPUT
|
|
{
|
|
current = &sub_expr;
|
|
clear_buffer();
|
|
}
|
|
OPARENT sub_expr CPARENT
|
|
{
|
|
current = &main_expr;
|
|
if (!dry_run) {
|
|
quote_fmt_insert_user_input(sub_expr.buffer);
|
|
}
|
|
};
|