Added 'email attributes' option

SVN revision: 1430
This commit is contained in:
Stefan Ritt 2005-07-20 18:53:00 +00:00
parent b4167331ac
commit b33477f161
2 changed files with 126 additions and 65 deletions

View File

@ -1541,6 +1541,7 @@ individual logbook sections, one has to log in to each logbook separately.<p>
<LI><b><code>Use Email Heading Edit = &lt;string&gt;</code></b>
<LI><b><code>Omit Email To = 0|1</code></b>
<LI><b><code>Suppress Email to users = 0|1</code></b>
<LI><b><code>Email attributes = &lt;list&gt;</code></b>
</ul>
<p>
@ -1555,43 +1556,44 @@ contain attributes via the <b>"$"</b> substitution. If a logbook contains for
example an attribute <i>name</i> which contains email names, then one can
put <i>$name@domain</i> to form a valid email address.<p>
Multiple <b><code>Email xxx</code></b > 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:
<p>
<ul><code>Email type "Normal routine" = ...</code></ul>
<p>
The statement <b><code>Email All = &lt;list&gt;</code></b> sends an
email notification independent of the type and category. The <b><code>Use
Email Subject = &lt;string&gt;</b></code> statement specifies which text is
used as the email subject. The text can contain <b><code>$&lt;attribute&gt;
</code></b>statements which are substituted with the current value of that
attribute. For a full list of possible substitutions, see the
"<I>Subst &lt;attribute&gt;</I>" option. The <b><code>Use Email Heading
= &lt;string&gt;</code></b> specifies the text for the email heading line.
Default is <i>"A new entry has been submitted on [host]"</i>. The option
<b><code>Use Email Heading Edit = &lt;string&gt;</code></b> works the same
way for updated (edited) entries.<p>
Multiple <b><code>Email xxx</code></b > 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: <p> <ul><code>Email type
"Normal routine" = ...</code></ul> <p> The statement <b><code>Email All =
&lt;list&gt;</code></b> sends an email notification independent of the type and
category. The <b><code>Use Email Subject = &lt;string&gt;</b></code> statement
specifies which text is used as the email subject. The text can contain
<b><code>$&lt;attribute&gt; </code></b>statements which are substituted with the
current value of that attribute. For a full list of possible substitutions, see
the "<I>Subst &lt;attribute&gt;</I>" option. The <b><code>Use Email Heading =
&lt;string&gt;</code></b> specifies the text for the email heading line. Default
is <i>"A new entry has been submitted on [host]"</i>. The option <b><code>Use
Email Heading Edit = &lt;string&gt;</code></b> works the same way for updated
(edited) entries.<p>
The option <b><code>Use Email From = &lt;string&gt;
</code></b> is used for the "<I>From:</I>" field in the email.
Since more and more email servers do not accept invalid <I>"From:"</I> addresses in
order to reduce spam mail, it might be important that a "real" email address is used in
the <I>"From:"</I> field. By default, the email address of the currently logged in
user is used for the <I>"From:"</I> 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 <b><code>Use Email From</code></b> is used for the "<I>From:</I>" field.
Only if this option is not specified, a generic address <I>ELOG@&lt;hostname&gt;</I>
is used, which might be rejected by the SMTP server however.<p>
The option <b><code>Use Email From = &lt;string&gt; </code></b> is used for the
"<I>From:</I>" field in the email. Since more and more email servers do not
accept invalid <I>"From:"</I> addresses in order to reduce spam mail, it might
be important that a "real" email address is used in the <I>"From:"</I> field. By
default, the email address of the currently logged in user is used for the
<I>"From:"</I> 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
<b><code>Use Email From</code></b> is used for the "<I>From:</I>" field. Only if
this option is not specified, a generic address <I>ELOG@&lt;hostname&gt;</I> is
used, which might be rejected by the SMTP server however.<p>
If the flag <b><code>
Omit Email To</b></code> is set to <b>1</b>, the <i>To:</i> 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.
<p>
The flag <b><code>Suppress Email to users</b></code> can be set to <b>"1"</b> if email should
only be sent to the recipients of the <b><code>Email &lt;attribute&gt; &lt;value&gt; = &lt;list&gt;</code></b>
statements but not to the users who have registerd for automatic email notification.<p>
If the flag <b><code>Omit Email To</b></code> is set to <b>1</b>, the <i>To:</i>
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. <p> The flag <b><code>Suppress Email to
users</b></code> can be set to <b>"1"</b> if email should only be sent to the
recipients of the <b><code>Email &lt;attribute&gt; &lt;value&gt; =
&lt;list&gt;</code></b> statements but not to the users who have registerd for
automatic email notification.<p>
If one wants to send only some attributes but not all in an email notification,
one can use the option <b><code>Email attributes = &lt;list&gt;</code></b>,
where a subset of the attributes can be specified as well as their order.
<a name="flags"><hr>
<div class=section>&nbsp; Flags &nbsp;</div>
@ -1717,6 +1719,22 @@ If this flag is <b>1</b>, no email notifications are sent for edited messages,
only for new messages. The default is <b>0</b>.
<p>
<li><b><code>Email Encoding = &lt;n&gt;</code></b>
</br>
Specifies in which encoding an email is sent. &lt;n&gt; is the sum of following
flags:<br>
<ul>
<li>1 : Plain text
<li>2 : HTML in the form of the plain text, but with ELCode interpreted
<li>4 : Full HTML page as shown in elog
</ul>
So to send email in plain text and full HTML, set &lt;n&gt;
to <b>5</b>. Most email clients have the possibility then to switch from one view
to the other. Default is <b>2</b> (send everything).
<p>
<li><b><code>Back to main = 0|1</code></b>
</br>
If this flag is <b>1</b>, the "<I>List</I>" button takes you back to the logbook

View File

@ -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(&ltime);
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(&ltime);
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(&ltime);
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(&ltime);
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), "<tr><td bgcolor=\"#CCCCFF\">%s</td>", attr_list[j]);
sprintf(mail_text + strlen(mail_text), "<tr><td bgcolor=\"#CCCCFF\">%s</td>", attr_list[i]);
sprintf(mail_text + strlen(mail_text), "<td bgcolor=\"#DDEEBB\">%s</td></tr>\r\n", comment);
}
}