From b33477f161ba9647f83f9d94630e8f3005bc0f17 Mon Sep 17 00:00:00 2001 From: Stefan Ritt Date: Wed, 20 Jul 2005 18:53:00 +0000 Subject: [PATCH] Added 'email attributes' option SVN revision: 1430 --- doc/config.html | 88 +++++++++++++++++++++++++---------------- src/elogd.c | 103 ++++++++++++++++++++++++++++++++++-------------- 2 files changed, 126 insertions(+), 65 deletions(-) diff --git a/doc/config.html b/doc/config.html index b29d641d..d5a72883 100755 --- a/doc/config.html +++ b/doc/config.html @@ -1541,6 +1541,7 @@ individual logbook sections, one has to log in to each logbook separately.

  • Use Email Heading Edit = <string>
  • Omit Email To = 0|1
  • Suppress Email to users = 0|1 +
  • Email attributes = <list>

    @@ -1555,43 +1556,44 @@ contain attributes via the "$" substitution. If a logbook contains for example an attribute name which contains email names, then one can put $name@domain to form a valid email address.

    -Multiple Email xxx statements may occur in a configuration -file. If either the attribute or the value contains one or more blanks the string -must be enclosed with quotation marks, as in: -

    -

    -

    -The statement Email All = <list> sends an -email notification independent of the type and category. The Use -Email Subject = <string> statement specifies which text is -used as the email subject. The text can contain $<attribute> -statements which are substituted with the current value of that -attribute. For a full list of possible substitutions, see the -"Subst <attribute>" option. The Use Email Heading -= <string> specifies the text for the email heading line. -Default is "A new entry has been submitted on [host]". The option -Use Email Heading Edit = <string> works the same -way for updated (edited) entries.

    +Multiple Email xxx statements may occur in a configuration +file. If either the attribute or the value contains one or more blanks the +string must be enclosed with quotation marks, as in:

    The statement Email All = +<list> sends an email notification independent of the type and +category. The Use Email Subject = <string> statement +specifies which text is used as the email subject. The text can contain +$<attribute> statements which are substituted with the +current value of that attribute. For a full list of possible substitutions, see +the "Subst <attribute>" option. The Use Email Heading = +<string> specifies the text for the email heading line. Default +is "A new entry has been submitted on [host]". The option Use +Email Heading Edit = <string> works the same way for updated +(edited) entries.

    -The option Use Email From = <string> - is used for the "From:" field in the email. -Since more and more email servers do not accept invalid "From:" addresses in -order to reduce spam mail, it might be important that a "real" email address is used in -the "From:" field. By default, the email address of the currently logged in -user is used for the "From:" field. If no user is logged in, or the current -user has not specified a email address in the password database, the setting -of the option Use Email From is used for the "From:" field. -Only if this option is not specified, a generic address ELOG@<hostname> -is used, which might be rejected by the SMTP server however.

    +The option Use Email From = <string> is used for the +"From:" field in the email. Since more and more email servers do not +accept invalid "From:" addresses in order to reduce spam mail, it might +be important that a "real" email address is used in the "From:" field. By +default, the email address of the currently logged in user is used for the +"From:" field. If no user is logged in, or the current user has not +specified a email address in the password database, the setting of the option +Use Email From is used for the "From:" field. Only if +this option is not specified, a generic address ELOG@<hostname> is +used, which might be rejected by the SMTP server however.

    -If the flag -Omit Email To is set to 1, the To: field in the email is -left empty instead set to the real email address of the recipients. This can -be useful if one recipient should not see the email addresses of the other recipients. -

    -The flag Suppress Email to users can be set to "1" if email should -only be sent to the recipients of the Email <attribute> <value> = <list> -statements but not to the users who have registerd for automatic email notification.

    +If the flag Omit Email To is set to 1, the To: +field in the email is left empty instead set to the real email address of the +recipients. This can be useful if one recipient should not see the email +addresses of the other recipients.

    The flag Suppress Email to +users can be set to "1" if email should only be sent to the +recipients of the Email <attribute> <value> = +<list> statements but not to the users who have registerd for +automatic email notification.

    + +If one wants to send only some attributes but not all in an email notification, +one can use the option Email attributes = <list>, +where a subset of the attributes can be specified as well as their order.


      Flags  
    @@ -1717,6 +1719,22 @@ If this flag is 1, no email notifications are sent for edited messages, only for new messages. The default is 0.

    +

  • Email Encoding = <n> +
    +Specifies in which encoding an email is sent. <n> is the sum of following +flags:
    + +
      +
    • 1 : Plain text +
    • 2 : HTML in the form of the plain text, but with ELCode interpreted +
    • 4 : Full HTML page as shown in elog +
    + +So to send email in plain text and full HTML, set <n> +to 5. Most email clients have the possibility then to switch from one view +to the other. Default is 2 (send everything). +

    +

  • Back to main = 0|1
    If this flag is 1, the "List" button takes you back to the logbook diff --git a/src/elogd.c b/src/elogd.c index 40fb2279..c361c282 100755 --- a/src/elogd.c +++ b/src/elogd.c @@ -6,6 +6,9 @@ Contents: Web server program for Electronic Logbook ELOG $Log$ + Revision 1.704 2005/07/20 18:53:00 ritt + Added 'email attributes' option + Revision 1.703 2005/07/16 10:18:17 ritt Added '\' as escape character for HTML and ELCode tags @@ -3442,7 +3445,7 @@ void check_config_file(BOOL force) parse_config_file(config_file); } } else - eprintf("Cannot stat() config file; %s\n", strerror(errno)); + eprintf("Cannot stat() config file \"%s\": %s\n", config_file, strerror(errno)); } /*-------------------------------------------------------------------*/ @@ -18162,9 +18165,9 @@ void show_elog_thread(LOGBOOK * lbs, int message_id) void format_email_text(LOGBOOK * lbs, char attrib[MAX_N_ATTR][NAME_LENGTH], int old_mail, char *url, char *mail_text) { - int j, k, flags; - char str[NAME_LENGTH + 100], str2[256], mail_from[256], format[256]; - char comment[256]; + int i, j, k, flags, n_email_attr, attr_index[MAX_N_ATTR]; + char str[NAME_LENGTH + 100], str2[256], mail_from[256], format[256], + list[MAX_N_ATTR][NAME_LENGTH], comment[256]; time_t ltime; struct tm *pts; @@ -18198,33 +18201,53 @@ void format_email_text(LOGBOOK * lbs, char attrib[MAX_N_ATTR][NAME_LENGTH], int sprintf(mail_text + strlen(mail_text), "%s : %s\r\n", loc("Logbook"), lbs->name); if (flags & 2) { - for (j = 0; j < lbs->n_attr; j++) { + + if (getcfg(lbs->name, "Email attributes", str, sizeof(str))) { + n_email_attr = strbreak(str, list, MAX_N_ATTR, ","); + for (i = 0; i < n_email_attr; i++) { + for (j = 0; j < lbs->n_attr; j++) + if (strieq(attr_list[j], list[i])) + break; + if (!strieq(attr_list[j], list[i])) + /* attribute not found */ + j = 0; + attr_index[i] = j; + } + } else { + for (i = 0; i < lbs->n_attr; i++) + attr_index[i] = i; + n_email_attr = lbs->n_attr; + } + + for (j = 0; j < n_email_attr; j++) { + + i = attr_index[j]; strcpy(str, " "); - memcpy(str, attr_list[j], strlen(attr_list[j])); + memcpy(str, attr_list[i], strlen(attr_list[i])); comment[0] = 0; - if (attr_flags[j] & AF_ICON) { + if (attr_flags[i] & AF_ICON) { - sprintf(str2, "Icon comment %s", attrib[j]); + sprintf(str2, "Icon comment %s", attrib[i]); getcfg(lbs->name, str2, comment, sizeof(comment)); - } else if (attr_flags[j] & AF_DATE) { + } else if (attr_flags[i] & AF_DATE) { if (!getcfg(lbs->name, "Date format", format, sizeof(format))) strcpy(format, DEFAULT_DATE_FORMAT); - ltime = atoi(attrib[j]); + ltime = atoi(attrib[i]); pts = localtime(<ime); if (ltime == 0) strcpy(comment, "-"); else my_strftime(comment, sizeof(str), format, pts); - } else if (attr_flags[j] & AF_DATETIME) { + } else if (attr_flags[i] & AF_DATETIME) { if (!getcfg(lbs->name, "Time format", format, sizeof(format))) strcpy(format, DEFAULT_TIME_FORMAT); - ltime = atoi(attrib[j]); + ltime = atoi(attrib[i]); pts = localtime(<ime); if (ltime == 0) strcpy(comment, "-"); @@ -18233,10 +18256,10 @@ void format_email_text(LOGBOOK * lbs, char attrib[MAX_N_ATTR][NAME_LENGTH], int } if (!comment[0]) - strcpy(comment, attrib[j]); + strcpy(comment, attrib[i]); - if (strieq(attr_options[j][0], "boolean")) - strcpy(comment, atoi(attrib[j]) ? loc("Yes") : loc("No")); + if (strieq(attr_options[i][0], "boolean")) + strcpy(comment, atoi(attrib[i]) ? loc("Yes") : loc("No")); for (k = strlen(str) - 1; k > 0; k--) if (str[k] != ' ') @@ -18267,9 +18290,9 @@ void format_email_text(LOGBOOK * lbs, char attrib[MAX_N_ATTR][NAME_LENGTH], int void format_email_html(LOGBOOK * lbs, char attrib[MAX_N_ATTR][NAME_LENGTH], int old_mail, char *encoding, char *url, char *mail_text) { - int j, k, flags; - char str[NAME_LENGTH + 100], str2[256], mail_from[256], format[256]; - char comment[256]; + int i, j, k, flags, n_email_attr, attr_index[MAX_N_ATTR]; + char str[NAME_LENGTH + 100], str2[256], mail_from[256], format[256], + list[MAX_N_ATTR][NAME_LENGTH], comment[256]; time_t ltime; struct tm *pts; @@ -18310,33 +18333,53 @@ void format_email_html(LOGBOOK * lbs, char attrib[MAX_N_ATTR][NAME_LENGTH], int } if (flags & 2) { - for (j = 0; j < lbs->n_attr; j++) { + + if (getcfg(lbs->name, "Email attributes", str, sizeof(str))) { + n_email_attr = strbreak(str, list, MAX_N_ATTR, ","); + for (i = 0; i < n_email_attr; i++) { + for (j = 0; j < lbs->n_attr; j++) + if (strieq(attr_list[j], list[i])) + break; + if (!strieq(attr_list[j], list[i])) + /* attribute not found */ + j = 0; + attr_index[i] = j; + } + } else { + for (i = 0; i < lbs->n_attr; i++) + attr_index[i] = i; + n_email_attr = lbs->n_attr; + } + + for (j = 0; j < n_email_attr; j++) { + + i = attr_index[j]; strcpy(str, " "); - memcpy(str, attr_list[j], strlen(attr_list[j])); + memcpy(str, attr_list[i], strlen(attr_list[i])); comment[0] = 0; - if (attr_flags[j] & AF_ICON) { + if (attr_flags[i] & AF_ICON) { - sprintf(str2, "Icon comment %s", attrib[j]); + sprintf(str2, "Icon comment %s", attrib[i]); getcfg(lbs->name, str2, comment, sizeof(comment)); - } else if (attr_flags[j] & AF_DATE) { + } else if (attr_flags[i] & AF_DATE) { if (!getcfg(lbs->name, "Date format", format, sizeof(format))) strcpy(format, DEFAULT_DATE_FORMAT); - ltime = atoi(attrib[j]); + ltime = atoi(attrib[i]); pts = localtime(<ime); if (ltime == 0) strcpy(comment, "-"); else my_strftime(comment, sizeof(str), format, pts); - } else if (attr_flags[j] & AF_DATETIME) { + } else if (attr_flags[i] & AF_DATETIME) { if (!getcfg(lbs->name, "Time format", format, sizeof(format))) strcpy(format, DEFAULT_TIME_FORMAT); - ltime = atoi(attrib[j]); + ltime = atoi(attrib[i]); pts = localtime(<ime); if (ltime == 0) strcpy(comment, "-"); @@ -18345,16 +18388,16 @@ void format_email_html(LOGBOOK * lbs, char attrib[MAX_N_ATTR][NAME_LENGTH], int } if (!comment[0]) - strcpy(comment, attrib[j]); + strcpy(comment, attrib[i]); - if (strieq(attr_options[j][0], "boolean")) - strcpy(comment, atoi(attrib[j]) ? loc("Yes") : loc("No")); + if (strieq(attr_options[i][0], "boolean")) + strcpy(comment, atoi(attrib[i]) ? loc("Yes") : loc("No")); for (k = strlen(str) - 1; k > 0; k--) if (str[k] != ' ') break; - sprintf(mail_text + strlen(mail_text), "%s", attr_list[j]); + sprintf(mail_text + strlen(mail_text), "%s", attr_list[i]); sprintf(mail_text + strlen(mail_text), "%s\r\n", comment); } }