Forgot to adjust default window size
[claws.git] / src / quote_fmt_parse.y
blobaf7f421462c7409410c97b0bd563757c1e9be644
1 /*
2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "defs.h"
24 #include <glib.h>
25 #include <glib/gi18n.h>
27 #include <ctype.h>
29 #include "procmsg.h"
30 #include "procmime.h"
31 #include "utils.h"
32 #include "codeconv.h"
33 #include "procheader.h"
34 #include "addr_compl.h"
35 #include "gtk/inputdialog.h"
37 #include "quote_fmt.h"
38 #include "quote_fmt_lex.h"
39 #include "account.h"
41 /* decl */
43 flex quote_fmt.l
44 bison -p quote_fmt quote_fmt.y
47 int yylex(void);
49 static MsgInfo *msginfo = NULL;
50 static PrefsAccount *account = NULL;
51 #ifdef USE_ENCHANT
52 static gchar default_dictionary[BUFFSIZE];
53 #endif
54 static gboolean *visible = NULL;
55 static gboolean dry_run = FALSE;
56 static gint maxsize = 0;
57 static gint stacksize = 0;
58 static GHashTable *var_table = NULL;
59 static GList *attachments = NULL;
61 typedef struct st_buffer
63 gchar *buffer;
64 gint bufsize;
65 gint bufmax;
66 } st_buffer;
68 static struct st_buffer main_expr = { NULL, 0, 0 };
69 static struct st_buffer sub_expr = { NULL, 0, 0 };
70 static struct st_buffer* current = NULL;
72 static const gchar *quote_str = NULL;
73 static const gchar *body = NULL;
74 static gint error = 0;
76 static gint cursor_pos = -1;
78 extern int quote_fmt_firsttime;
79 extern int line;
80 extern int escaped_string;
82 static void add_visibility(gboolean val)
84 stacksize++;
85 if (maxsize < stacksize) {
86 maxsize += 128;
87 visible = g_realloc(visible, maxsize * sizeof(gboolean));
88 if (visible == NULL)
89 maxsize = 0;
91 if (visible != NULL)
92 visible[stacksize - 1] = val;
95 static void remove_visibility(void)
97 stacksize--;
98 if (stacksize < 0) {
99 g_warning("Error: visibility stack underflow");
100 stacksize = 0;
104 static void add_buffer(const gchar *s)
106 gint len;
108 if (s == NULL)
109 return;
111 len = strlen(s);
112 if (current->bufsize + len + 1 > current->bufmax) {
113 if (current->bufmax == 0)
114 current->bufmax = 128;
115 while (current->bufsize + len + 1 > current->bufmax)
116 current->bufmax *= 2;
117 current->buffer = g_realloc(current->buffer, current->bufmax);
119 strcpy(current->buffer + current->bufsize, s);
120 current->bufsize += len;
123 static void clear_buffer(void)
125 if (current->buffer)
126 *current->buffer = '\0';
127 else
128 /* force to an empty string, as buffer should not be left unallocated */
129 add_buffer("");
130 current->bufsize = 0;
133 gchar *quote_fmt_get_buffer(void)
135 if (current != &main_expr)
136 g_warning("Error: parser still in sub-expr mode");
138 if (error != 0)
139 return NULL;
140 else
141 return current->buffer;
144 GList *quote_fmt_get_attachments_list(void)
146 return attachments;
149 gint quote_fmt_get_line(void)
151 return line;
154 gint quote_fmt_get_cursor_pos(void)
156 return cursor_pos;
159 #define INSERT(buf) \
160 if (stacksize != 0 && visible[stacksize - 1])\
161 add_buffer(buf); \
163 #define INSERT_CHARACTER(chr) \
164 if (stacksize != 0 && visible[stacksize - 1]) { \
165 gchar tmp[2]; \
166 tmp[0] = (chr); \
167 tmp[1] = '\0'; \
168 add_buffer(tmp); \
171 void quote_fmt_reset_vartable(void)
173 if (var_table) {
174 g_hash_table_destroy(var_table);
175 var_table = NULL;
177 if (attachments) {
178 GList *cur = attachments;
179 while (cur) {
180 g_free(cur->data);
181 cur = g_list_next(cur);
183 g_list_free(attachments);
184 attachments = NULL;
188 #ifdef USE_ENCHANT
189 void quote_fmt_init(MsgInfo *info, const gchar *my_quote_str,
190 const gchar *my_body, gboolean my_dry_run,
191 PrefsAccount *compose_account,
192 gboolean string_is_escaped,
193 GtkAspell *compose_gtkaspell)
194 #else
195 void quote_fmt_init(MsgInfo *info, const gchar *my_quote_str,
196 const gchar *my_body, gboolean my_dry_run,
197 PrefsAccount *compose_account,
198 gboolean string_is_escaped)
199 #endif
201 quote_str = my_quote_str;
202 body = my_body;
203 msginfo = info;
204 account = compose_account;
205 #ifdef USE_ENCHANT
206 gchar *dict = gtkaspell_get_default_dictionary(compose_gtkaspell);
207 if (dict)
208 strncpy2(default_dictionary, dict, sizeof(default_dictionary));
209 else
210 *default_dictionary = '\0';
211 #endif
212 dry_run = my_dry_run;
213 stacksize = 0;
214 add_visibility(TRUE);
215 main_expr.bufmax = 0;
216 sub_expr.bufmax = 0;
217 current = &main_expr;
218 clear_buffer();
219 error = 0;
220 line = 1;
221 escaped_string = string_is_escaped;
223 if (!var_table)
224 var_table = g_hash_table_new_full(g_str_hash, g_str_equal,
225 g_free, g_free);
228 * force LEX initialization
230 quote_fmt_firsttime = 1;
231 cursor_pos = -1;
234 void quote_fmterror(char *str)
236 g_warning("Error: %s at line %d", str, line);
237 error = 1;
240 int quote_fmtwrap(void)
242 return 1;
245 static int isseparator(int ch)
247 return g_ascii_isspace(ch) || ch == '.' || ch == '-';
251 * Search for glibc extended strftime timezone specs within haystack.
252 * If not found NULL is returned and the integer pointed by tzspeclen is
253 * not changed.
254 * If found a pointer to the start of the specification within haystack
255 * is returned and the integer pointed by tzspeclen is set to the lenght
256 * of specification.
258 static const char* strtzspec(const char *haystack, int *tzspeclen)
260 const char *p = NULL;
261 const char *q = NULL;
262 const char *r = NULL;
264 p = strstr(haystack, "%");
265 while (p != NULL) {
266 q = p + 1;
267 if (!*q) return NULL;
268 r = strchr("_-0^#", *q); /* skip flags */
269 if (r != NULL) {
270 ++q;
271 if (!*q) return NULL;
273 while (*q >= '0' && *q <= '9') ++q; /* skip width */
274 if (!*q) return NULL;
275 if (*q == 'z' || *q == 'Z') { /* numeric or name */
276 *tzspeclen = 1 + (q - p);
277 return p;
279 p = strstr(q, "%");
281 return NULL;
284 static void quote_fmt_show_date(const MsgInfo *msginfo, const gchar *format)
286 char result[100];
287 char *rptr;
288 char zone[6];
289 struct tm lt;
290 const char *fptr;
291 const char *zptr;
293 if (!msginfo->date)
294 return;
297 * ALF - GNU C's strftime() has a nice format specifier
298 * for time zone offset (%z). Non-standard however, so
299 * emulate it.
302 #define RLEFT (sizeof result) - (rptr - result)
304 zone[0] = 0;
306 if (procheader_date_parse_to_tm(msginfo->date, &lt, zone)) {
308 * break up format string in tiny bits delimited by valid %z's and
309 * feed it to strftime(). don't forget that '%%z' mean literal '%z'.
311 for (rptr = result, fptr = format; fptr && *fptr && rptr < &result[sizeof result - 1];) {
312 int perc, zlen;
313 const char *p;
314 char *tmp;
316 if (NULL != (zptr = strtzspec(fptr, &zlen))) {
318 * count nr. of prepended percent chars
320 for (perc = 0, p = zptr; p && p >= format && *p == '%'; p--, perc++)
323 * feed to strftime()
325 tmp = g_strndup(fptr, zptr - fptr + (perc % 2 ? 0 : zlen));
326 if (tmp) {
327 rptr += strftime(rptr, RLEFT, tmp, &lt);
328 g_free(tmp);
331 * append time zone offset
333 if (zone[0] && perc % 2)
334 rptr += g_snprintf(rptr, RLEFT, "%s", zone);
335 fptr = zptr + zlen;
336 } else {
337 rptr += strftime(rptr, RLEFT, fptr, &lt);
338 fptr = NULL;
342 if (g_utf8_validate(result, -1, NULL)) {
343 INSERT(result);
344 } else {
345 gchar *utf = conv_codeset_strdup(result,
346 conv_get_locale_charset_str_no_utf8(),
347 CS_INTERNAL);
348 if (utf == NULL ||
349 !g_utf8_validate(utf, -1, NULL)) {
350 g_free(utf);
351 utf = g_malloc(strlen(result)*2+1);
352 conv_localetodisp(utf,
353 strlen(result)*2+1, result);
355 if (g_utf8_validate(utf, -1, NULL)) {
356 INSERT(utf);
358 g_free(utf);
361 #undef RLEFT
364 static void quote_fmt_show_first_name(const MsgInfo *msginfo)
366 guchar *p;
367 gchar *str;
369 if (!msginfo->fromname)
370 return;
372 p = (guchar*)strchr(msginfo->fromname, ',');
373 if (p != NULL) {
374 /* fromname is like "Duck, Donald" */
375 p++;
376 while (*p && isspace(*p)) p++;
377 str = alloca(strlen((char *)p) + 1);
378 if (str != NULL) {
379 strcpy(str, (char *)p);
380 INSERT(str);
382 } else {
383 /* fromname is like "Donald Duck" */
384 str = alloca(strlen(msginfo->fromname) + 1);
385 if (str != NULL) {
386 strcpy(str, msginfo->fromname);
387 p = (guchar *)str;
388 while (*p && !isspace(*p)) p++;
389 *p = '\0';
390 INSERT(str);
395 static void quote_fmt_show_last_name(const MsgInfo *msginfo)
397 gchar *p;
398 gchar *str;
400 /* This probably won't work together very well with Middle
401 names and the like - thth */
402 if (!msginfo->fromname)
403 return;
405 str = alloca(strlen(msginfo->fromname) + 1);
406 if (str != NULL) {
407 strcpy(str, msginfo->fromname);
408 p = strchr(str, ',');
409 if (p != NULL) {
410 /* fromname is like "Duck, Donald" */
411 *p = '\0';
412 INSERT(str);
413 } else {
414 /* fromname is like "Donald Duck" */
415 p = str;
416 while (*p && !isspace(*p)) p++;
417 if (*p) {
418 /* We found a space. Get first
419 none-space char and insert
420 rest of string from there. */
421 while (*p && isspace(*p)) p++;
422 if (*p) {
423 INSERT(p);
424 } else {
425 /* If there is no none-space
426 char, just insert whole
427 fromname. */
428 INSERT(str);
430 } else {
431 /* If there is no space, just
432 insert whole fromname. */
433 INSERT(str);
439 static void quote_fmt_show_sender_initial(const MsgInfo *msginfo)
441 #define MAX_SENDER_INITIAL 20
442 gchar tmp[MAX_SENDER_INITIAL];
443 guchar *p;
444 gchar *cur;
445 gint len = 0;
447 if (!msginfo->fromname)
448 return;
450 p = (guchar *)msginfo->fromname;
451 cur = tmp;
452 while (*p) {
453 if (*p && g_utf8_validate((gchar *)p, 1, NULL)) {
454 *cur = toupper(*p);
455 cur++;
456 len++;
457 if (len >= MAX_SENDER_INITIAL - 1)
458 break;
459 } else
460 break;
461 while (*p && !isseparator(*p)) p++;
462 while (*p && isseparator(*p)) p++;
464 *cur = '\0';
465 INSERT(tmp);
468 static void quote_fmt_show_msg(MsgInfo *msginfo, const gchar *body,
469 gboolean quoted, gboolean signature,
470 const gchar *quote_str)
472 gchar buf[BUFFSIZE];
473 FILE *fp;
475 if (!(msginfo->folder || body))
476 return;
478 if (body)
479 fp = str_open_as_stream(body);
480 else {
481 if (MSG_IS_ENCRYPTED(msginfo->flags))
482 fp = procmime_get_first_encrypted_text_content(msginfo);
483 else
484 fp = procmime_get_first_text_content(msginfo);
487 if (fp == NULL)
488 g_warning("Can't get text part");
489 else {
490 while (fgets(buf, sizeof(buf), fp) != NULL) {
491 strcrchomp(buf);
493 if (!signature && strncmp(buf, "-- \n", 4) == 0)
494 break;
496 if (quoted && quote_str)
497 INSERT(quote_str);
499 INSERT(buf);
501 fclose(fp);
505 static void quote_fmt_insert_file(const gchar *filename)
507 FILE *file;
508 char buffer[256];
510 if ((file = g_fopen(filename, "rb")) != NULL) {
511 while (fgets(buffer, sizeof(buffer), file)) {
512 INSERT(buffer);
514 fclose(file);
519 static void quote_fmt_insert_program_output(const gchar *progname)
521 FILE *file;
522 char buffer[256];
524 if ((file = popen(progname, "r")) != NULL) {
525 while (fgets(buffer, sizeof(buffer), file)) {
526 INSERT(buffer);
528 pclose(file);
532 static void quote_fmt_insert_user_input(const gchar *varname)
534 gchar *buf = NULL;
535 gchar *text = NULL;
537 if (dry_run)
538 return;
540 if ((text = g_hash_table_lookup(var_table, varname)) == NULL) {
541 buf = g_strdup_printf(_("Enter text to replace '%s'"), varname);
542 text = input_dialog(_("Enter variable"), buf, "");
543 g_free(buf);
544 if (!text)
545 return;
546 g_hash_table_insert(var_table, g_strdup(varname), g_strdup(text));
547 } else {
548 /* don't free the one in hashtable at the end */
549 text = g_strdup(text);
552 if (!text)
553 return;
554 INSERT(text);
555 g_free(text);
558 static void quote_fmt_attach_file(const gchar *filename)
560 attachments = g_list_append(attachments, g_strdup(filename));
563 static gchar *quote_fmt_complete_address(const gchar *addr)
565 gint count;
566 gchar *res, *tmp, *email_addr;
567 gchar **split;
569 debug_print("quote_fmt_complete_address: %s\n", addr);
570 if (addr == NULL)
571 return NULL;
573 /* if addr is a list of message, try the 1st element only */
574 split = g_strsplit(addr, ",", -1);
575 if (!split || !split[0] || *split[0] == '\0') {
576 g_strfreev(split);
577 return NULL;
580 Xstrdup_a(email_addr, split[0], return NULL);
581 extract_address(email_addr);
582 if (!*email_addr) {
583 g_strfreev(split);
584 return NULL;
587 res = NULL;
588 start_address_completion(NULL);
589 if (1 < (count = complete_address(email_addr))) {
590 tmp = get_complete_address(1);
591 res = procheader_get_fromname(tmp);
592 g_free(tmp);
594 end_address_completion();
595 g_strfreev(split);
597 debug_print("quote_fmt_complete_address: matched %s\n", res);
598 return res;
603 %union {
604 char chr;
605 char str[256];
608 /* tokens SHOW */
609 %token SHOW_NEWSGROUPS
610 %token SHOW_DATE SHOW_FROM SHOW_FULLNAME SHOW_FIRST_NAME SHOW_LAST_NAME
611 %token SHOW_SENDER_INITIAL SHOW_SUBJECT SHOW_TO SHOW_MESSAGEID
612 %token SHOW_PERCENT SHOW_CC SHOW_REFERENCES SHOW_MESSAGE
613 %token SHOW_QUOTED_MESSAGE SHOW_BACKSLASH SHOW_TAB SHOW_MAIL_ADDRESS
614 %token SHOW_QUOTED_MESSAGE_NO_SIGNATURE SHOW_MESSAGE_NO_SIGNATURE
615 %token SHOW_EOL SHOW_QUESTION_MARK SHOW_EXCLAMATION_MARK SHOW_PIPE SHOW_OPARENT SHOW_CPARENT
616 %token SHOW_ACCOUNT_FULL_NAME SHOW_ACCOUNT_MAIL_ADDRESS SHOW_ACCOUNT_NAME SHOW_ACCOUNT_ORGANIZATION
617 %token SHOW_ACCOUNT_DICT SHOW_ACCOUNT_SIG SHOW_ACCOUNT_SIGPATH
618 %token SHOW_DICT SHOW_TAGS
619 %token SHOW_ADDRESSBOOK_COMPLETION_FOR_CC
620 %token SHOW_ADDRESSBOOK_COMPLETION_FOR_FROM
621 %token SHOW_ADDRESSBOOK_COMPLETION_FOR_TO
622 /* tokens QUERY */
623 %token QUERY_DATE QUERY_FROM
624 %token QUERY_FULLNAME QUERY_SUBJECT QUERY_TO QUERY_NEWSGROUPS
625 %token QUERY_MESSAGEID QUERY_CC QUERY_REFERENCES
626 %token QUERY_ACCOUNT_FULL_NAME QUERY_ACCOUNT_ORGANIZATION QUERY_ACCOUNT_DICT
627 %token QUERY_ACCOUNT_SIG QUERY_ACCOUNT_SIGPATH
628 %token QUERY_DICT
629 %token QUERY_CC_FOUND_IN_ADDRESSBOOK
630 %token QUERY_FROM_FOUND_IN_ADDRESSBOOK
631 %token QUERY_TO_FOUND_IN_ADDRESSBOOK
632 /* tokens QUERY_NOT */
633 %token QUERY_NOT_DATE QUERY_NOT_FROM
634 %token QUERY_NOT_FULLNAME QUERY_NOT_SUBJECT QUERY_NOT_TO QUERY_NOT_NEWSGROUPS
635 %token QUERY_NOT_MESSAGEID QUERY_NOT_CC QUERY_NOT_REFERENCES
636 %token QUERY_NOT_ACCOUNT_FULL_NAME QUERY_NOT_ACCOUNT_ORGANIZATION QUERY_NOT_ACCOUNT_DICT
637 %token QUERY_NOT_ACCOUNT_SIG QUERY_NOT_ACCOUNT_SIGPATH
638 %token QUERY_NOT_DICT
639 %token QUERY_NOT_CC_FOUND_IN_ADDRESSBOOK
640 %token QUERY_NOT_FROM_FOUND_IN_ADDRESSBOOK
641 %token QUERY_NOT_TO_FOUND_IN_ADDRESSBOOK
642 /* other tokens */
643 %token INSERT_FILE INSERT_PROGRAMOUTPUT INSERT_USERINPUT
644 %token ATTACH_FILE
645 %token OPARENT CPARENT
646 %token CHARACTER
647 %token SHOW_DATE_EXPR
648 %token SET_CURSOR_POS
650 %start quote_fmt
652 %type <chr> CHARACTER
653 %type <chr> character
654 %type <str> string
658 quote_fmt:
659 character_or_special_or_insert_or_query_list ;
661 sub_expr:
662 character_or_special_list ;
664 character_or_special_or_insert_or_query_list:
665 character_or_special_or_insert_or_query character_or_special_or_insert_or_query_list
666 | character_or_special_or_insert_or_query ;
668 character_or_special_list:
669 character_or_special character_or_special_list
670 | character_or_special ;
672 character_or_special_or_insert_or_query:
673 character_or_special
674 | query
675 | query_not
676 | insert
677 | attach ;
679 character_or_special:
680 special
681 | character
683 INSERT_CHARACTER($1);
686 character:
687 CHARACTER
690 string:
691 CHARACTER
693 $$[0] = $1;
694 $$[1] = '\0';
696 | string CHARACTER
698 size_t len;
700 strncpy($$, $1, sizeof($$));
701 $$[sizeof($$) - 1] = '\0';
702 len = strlen($$);
703 if (len + 1 < sizeof($$)) {
704 $$[len + 1] = '\0';
705 $$[len] = $2;
709 special:
710 SHOW_NEWSGROUPS
712 if (msginfo->newsgroups)
713 INSERT(msginfo->newsgroups);
715 | SHOW_DATE_EXPR OPARENT string CPARENT
717 quote_fmt_show_date(msginfo, $3);
719 | SHOW_DATE
721 if (msginfo->date)
722 INSERT(msginfo->date);
724 | SHOW_FROM
726 if (msginfo->from)
727 INSERT(msginfo->from);
729 | SHOW_MAIL_ADDRESS
731 if (msginfo->from) {
732 gchar *stripped_address = g_strdup(msginfo->from);
733 extract_address(stripped_address);
734 INSERT(stripped_address);
735 g_free(stripped_address);
738 | SHOW_FULLNAME
740 if (msginfo->fromname)
741 INSERT(msginfo->fromname);
743 | SHOW_FIRST_NAME
745 quote_fmt_show_first_name(msginfo);
747 | SHOW_LAST_NAME
749 quote_fmt_show_last_name(msginfo);
751 | SHOW_SENDER_INITIAL
753 quote_fmt_show_sender_initial(msginfo);
755 | SHOW_SUBJECT
757 if (msginfo->subject)
758 INSERT(msginfo->subject);
760 | SHOW_TO
762 if (msginfo->to)
763 INSERT(msginfo->to);
765 | SHOW_MESSAGEID
767 if (msginfo->msgid)
768 INSERT(msginfo->msgid);
770 | SHOW_PERCENT
772 INSERT("%");
774 | SHOW_CC
776 if (msginfo->cc)
777 INSERT(msginfo->cc);
779 | SHOW_REFERENCES
781 GSList *item;
783 INSERT(msginfo->inreplyto);
784 for (item = msginfo->references; item != NULL; item = g_slist_next(item))
785 if (item->data)
786 INSERT(item->data);
788 | SHOW_MESSAGE
790 quote_fmt_show_msg(msginfo, body, FALSE, TRUE, quote_str);
792 | SHOW_QUOTED_MESSAGE
794 quote_fmt_show_msg(msginfo, body, TRUE, TRUE, quote_str);
796 | SHOW_MESSAGE_NO_SIGNATURE
798 quote_fmt_show_msg(msginfo, body, FALSE, FALSE, quote_str);
800 | SHOW_QUOTED_MESSAGE_NO_SIGNATURE
802 quote_fmt_show_msg(msginfo, body, TRUE, FALSE, quote_str);
804 | SHOW_ACCOUNT_FULL_NAME
806 if (account && account->name)
807 INSERT(account->name);
809 | SHOW_ACCOUNT_MAIL_ADDRESS
811 if (account && account->address)
812 INSERT(account->address);
814 | SHOW_ACCOUNT_NAME
816 if (account && account->account_name)
817 INSERT(account->account_name);
819 | SHOW_ACCOUNT_ORGANIZATION
821 if (account && account->organization)
822 INSERT(account->organization);
824 | SHOW_ACCOUNT_SIG
826 gchar *str = account_get_signature_str(account);
827 INSERT(str);
828 g_free(str);
830 | SHOW_ACCOUNT_SIGPATH
832 if (account && account->sig_path)
833 INSERT(account->sig_path);
835 | SHOW_ACCOUNT_DICT
837 #ifdef USE_ENCHANT
838 if (account && account->enable_default_dictionary) {
839 gchar *dictname = g_path_get_basename(account->default_dictionary);
840 INSERT(dictname);
841 g_free(dictname);
843 #endif
845 | SHOW_DICT
847 #ifdef USE_ENCHANT
848 INSERT(default_dictionary);
849 #endif
851 | SHOW_TAGS
853 gchar *tags = procmsg_msginfo_get_tags_str(msginfo);
854 if (tags) {
855 INSERT(tags);
857 g_free(tags);
859 | SHOW_BACKSLASH
861 INSERT("\\");
863 | SHOW_TAB
865 INSERT("\t");
867 | SHOW_EOL
869 INSERT("\n");
871 | SHOW_QUESTION_MARK
873 INSERT("?");
875 | SHOW_EXCLAMATION_MARK
877 INSERT("!");
879 | SHOW_PIPE
881 INSERT("|");
883 | SHOW_OPARENT
885 INSERT("{");
887 | SHOW_CPARENT
889 INSERT("}");
891 | SET_CURSOR_POS
893 if (current->buffer)
894 cursor_pos = g_utf8_strlen(current->buffer, -1);
895 else
896 cursor_pos = 0;
898 | SHOW_ADDRESSBOOK_COMPLETION_FOR_CC
900 gchar *tmp = quote_fmt_complete_address(msginfo->cc);
901 if (tmp) {
902 INSERT(tmp);
903 g_free(tmp);
906 | SHOW_ADDRESSBOOK_COMPLETION_FOR_FROM
908 gchar *tmp = quote_fmt_complete_address(msginfo->from);
909 if (tmp) {
910 INSERT(tmp);
911 g_free(tmp);
914 | SHOW_ADDRESSBOOK_COMPLETION_FOR_TO
916 gchar *tmp = quote_fmt_complete_address(msginfo->to);
917 if (tmp) {
918 INSERT(tmp);
919 g_free(tmp);
923 query:
924 QUERY_DATE
926 add_visibility(msginfo->date != NULL);
928 OPARENT quote_fmt CPARENT
930 remove_visibility();
932 | QUERY_FROM
934 add_visibility(msginfo->from != NULL);
936 OPARENT quote_fmt CPARENT
938 remove_visibility();
940 | QUERY_FULLNAME
942 add_visibility(msginfo->fromname != NULL);
944 OPARENT quote_fmt CPARENT
946 remove_visibility();
948 | QUERY_SUBJECT
950 add_visibility(msginfo->subject != NULL);
952 OPARENT quote_fmt CPARENT
954 remove_visibility();
956 | QUERY_TO
958 add_visibility(msginfo->to != NULL);
960 OPARENT quote_fmt CPARENT
962 remove_visibility();
964 | QUERY_NEWSGROUPS
966 add_visibility(msginfo->newsgroups != NULL);
968 OPARENT quote_fmt CPARENT
970 remove_visibility();
972 | QUERY_MESSAGEID
974 add_visibility(msginfo->msgid != NULL);
976 OPARENT quote_fmt CPARENT
978 remove_visibility();
980 | QUERY_CC
982 add_visibility(msginfo->cc != NULL);
984 OPARENT quote_fmt CPARENT
986 remove_visibility();
988 | QUERY_REFERENCES
990 gboolean found;
991 GSList *item;
993 found = (msginfo->inreplyto != NULL);
994 for (item = msginfo->references; found == FALSE && item != NULL; item = g_slist_next(item))
995 if (item->data)
996 found = TRUE;
997 add_visibility(found == TRUE);
999 OPARENT quote_fmt CPARENT
1001 remove_visibility();
1003 | QUERY_ACCOUNT_FULL_NAME
1005 add_visibility(account != NULL && account->name != NULL);
1007 OPARENT quote_fmt CPARENT
1009 remove_visibility();
1011 | QUERY_ACCOUNT_ORGANIZATION
1013 add_visibility(account != NULL && account->organization != NULL);
1015 OPARENT quote_fmt CPARENT
1017 remove_visibility();
1019 | QUERY_ACCOUNT_SIG
1021 gchar *str = account_get_signature_str(account);
1022 add_visibility(str != NULL && * str != '\0');
1023 g_free(str);
1025 OPARENT quote_fmt CPARENT
1027 remove_visibility();
1029 | QUERY_ACCOUNT_SIGPATH
1031 add_visibility(account != NULL && account->sig_path != NULL
1032 && *account->sig_path != '\0');
1034 OPARENT quote_fmt CPARENT
1036 remove_visibility();
1038 | QUERY_ACCOUNT_DICT
1040 #ifdef USE_ENCHANT
1041 add_visibility(account != NULL && account->enable_default_dictionary == TRUE &&
1042 account->default_dictionary != NULL && *account->default_dictionary != '\0');
1043 #else
1044 add_visibility(FALSE);
1045 #endif
1047 OPARENT quote_fmt CPARENT
1049 remove_visibility();
1051 | QUERY_DICT
1053 #ifdef USE_ENCHANT
1054 add_visibility(*default_dictionary != '\0');
1055 #else
1056 add_visibility(FALSE);
1057 #endif
1059 OPARENT quote_fmt CPARENT
1061 remove_visibility();
1063 | QUERY_CC_FOUND_IN_ADDRESSBOOK
1065 gchar *tmp = quote_fmt_complete_address(msginfo->cc);
1066 add_visibility(tmp != NULL && *tmp != '\0');
1067 g_free(tmp);
1069 OPARENT quote_fmt CPARENT
1071 remove_visibility();
1073 | QUERY_FROM_FOUND_IN_ADDRESSBOOK
1075 gchar *tmp = quote_fmt_complete_address(msginfo->from);
1076 add_visibility(tmp != NULL && *tmp != '\0');
1077 g_free(tmp);
1079 OPARENT quote_fmt CPARENT
1081 remove_visibility();
1083 | QUERY_TO_FOUND_IN_ADDRESSBOOK
1085 gchar *tmp = quote_fmt_complete_address(msginfo->to);
1086 add_visibility(tmp != NULL && *tmp != '\0');
1087 g_free(tmp);
1089 OPARENT quote_fmt CPARENT
1091 remove_visibility();
1094 query_not:
1095 QUERY_NOT_DATE
1097 add_visibility(msginfo->date == NULL);
1099 OPARENT quote_fmt CPARENT
1101 remove_visibility();
1103 | QUERY_NOT_FROM
1105 add_visibility(msginfo->from == NULL);
1107 OPARENT quote_fmt CPARENT
1109 remove_visibility();
1111 | QUERY_NOT_FULLNAME
1113 add_visibility(msginfo->fromname == NULL);
1115 OPARENT quote_fmt CPARENT
1117 remove_visibility();
1119 | QUERY_NOT_SUBJECT
1121 add_visibility(msginfo->subject == NULL);
1123 OPARENT quote_fmt CPARENT
1125 remove_visibility();
1127 | QUERY_NOT_TO
1129 add_visibility(msginfo->to == NULL);
1131 OPARENT quote_fmt CPARENT
1133 remove_visibility();
1135 | QUERY_NOT_NEWSGROUPS
1137 add_visibility(msginfo->newsgroups == NULL);
1139 OPARENT quote_fmt CPARENT
1141 remove_visibility();
1143 | QUERY_NOT_MESSAGEID
1145 add_visibility(msginfo->msgid == NULL);
1147 OPARENT quote_fmt CPARENT
1149 remove_visibility();
1151 | QUERY_NOT_CC
1153 add_visibility(msginfo->cc == NULL);
1155 OPARENT quote_fmt CPARENT
1157 remove_visibility();
1159 | QUERY_NOT_REFERENCES
1161 gboolean found;
1162 GSList *item;
1164 found = (msginfo->inreplyto != NULL);
1165 for (item = msginfo->references; found == FALSE && item != NULL; item = g_slist_next(item))
1166 if (item->data)
1167 found = TRUE;
1168 add_visibility(found == FALSE);
1170 OPARENT quote_fmt CPARENT
1172 remove_visibility();
1174 | QUERY_NOT_ACCOUNT_FULL_NAME
1176 add_visibility(account == NULL || account->name == NULL);
1178 OPARENT quote_fmt CPARENT
1180 remove_visibility();
1182 | QUERY_NOT_ACCOUNT_ORGANIZATION
1184 add_visibility(account == NULL || account->organization == NULL);
1186 OPARENT quote_fmt CPARENT
1188 remove_visibility();
1190 | QUERY_NOT_ACCOUNT_SIG
1192 gchar *str = account_get_signature_str(account);
1193 add_visibility(str == NULL || *str == '\0');
1194 g_free(str);
1196 OPARENT quote_fmt CPARENT
1198 remove_visibility();
1200 | QUERY_NOT_ACCOUNT_SIGPATH
1202 add_visibility(account == NULL || account->sig_path == NULL
1203 || *account->sig_path == '\0');
1205 OPARENT quote_fmt CPARENT
1207 remove_visibility();
1209 | QUERY_NOT_ACCOUNT_DICT
1211 #ifdef USE_ENCHANT
1212 add_visibility(account == NULL || account->enable_default_dictionary == FALSE
1213 || *account->default_dictionary == '\0');
1214 #else
1215 add_visibility(FALSE);
1216 #endif
1218 OPARENT quote_fmt CPARENT
1220 remove_visibility();
1222 | QUERY_NOT_DICT
1224 #ifdef USE_ENCHANT
1225 add_visibility(*default_dictionary == '\0');
1226 #else
1227 add_visibility(FALSE);
1228 #endif
1230 OPARENT quote_fmt CPARENT
1232 remove_visibility();
1234 | QUERY_NOT_CC_FOUND_IN_ADDRESSBOOK
1236 gchar *tmp = quote_fmt_complete_address(msginfo->cc);
1237 add_visibility(tmp == NULL || *tmp == '\0');
1238 g_free(tmp);
1240 OPARENT quote_fmt CPARENT
1242 remove_visibility();
1244 | QUERY_NOT_FROM_FOUND_IN_ADDRESSBOOK
1246 gchar *tmp = quote_fmt_complete_address(msginfo->from);
1247 add_visibility(tmp == NULL || *tmp == '\0');
1248 g_free(tmp);
1250 OPARENT quote_fmt CPARENT
1252 remove_visibility();
1254 | QUERY_NOT_TO_FOUND_IN_ADDRESSBOOK
1256 gchar *tmp = quote_fmt_complete_address(msginfo->to);
1257 add_visibility(tmp == NULL || *tmp == '\0');
1258 g_free(tmp);
1260 OPARENT quote_fmt CPARENT
1262 remove_visibility();
1265 insert:
1266 INSERT_FILE
1268 current = &sub_expr;
1269 clear_buffer();
1271 OPARENT sub_expr CPARENT
1273 current = &main_expr;
1274 if (!dry_run) {
1275 quote_fmt_insert_file(sub_expr.buffer);
1278 | INSERT_PROGRAMOUTPUT
1280 current = &sub_expr;
1281 clear_buffer();
1283 OPARENT sub_expr CPARENT
1285 current = &main_expr;
1286 if (!dry_run) {
1287 quote_fmt_insert_program_output(sub_expr.buffer);
1290 | INSERT_USERINPUT
1292 current = &sub_expr;
1293 clear_buffer();
1295 OPARENT sub_expr CPARENT
1297 current = &main_expr;
1298 if (!dry_run) {
1299 quote_fmt_insert_user_input(sub_expr.buffer);
1303 attach:
1304 ATTACH_FILE
1306 current = &sub_expr;
1307 clear_buffer();
1309 OPARENT sub_expr CPARENT
1311 current = &main_expr;
1312 if (!dry_run) {
1313 quote_fmt_attach_file(sub_expr.buffer);