Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support RFC5322 subject header for zed_notify_email() #13440

Merged
merged 1 commit into from
May 18, 2022
Merged

Support RFC5322 subject header for zed_notify_email() #13440

merged 1 commit into from
May 18, 2022

Conversation

heeplr
Copy link
Contributor

@heeplr heeplr commented May 9, 2022

Motivation and Context

Setting e-mail subject via ZED_EMAIL_OPTS doesn't always work. Small/lightweight MUAs (e.g. ssmtp) need a "Subject: ..." header in the mail body.

Description

If no @SUBJECT@ placeholder is found in ZED_EMAIL_OPTS, the notification file will be prepended with a subject header.

How Has This Been Tested?

#!/bin/sh

. "./zed-functions.sh"
. "./zed.rc"

echo "foo" > /tmp/test
zed_notify_email "Test notification" /tmp/test

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Library ABI change (libzfs, libzfs_core, libnvpair, libuutil and libzfsbootenv)
  • Documentation (a change to man pages or other documentation)

Checklist:

@behlendorf behlendorf added the Status: Code Review Needed Ready for review and testing label May 11, 2022
@behlendorf behlendorf requested a review from tonyhutter May 11, 2022 20:14
@tonyhutter
Copy link
Contributor

Could you squash your two commits and modify the commit message?:

zed: Support subject as header in zed_notify_email()

Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.

Signed-off-by: Daniel Hiepler <d-git@coderdu.de>

@tonyhutter
Copy link
Contributor

One of the lines in your commit message is over 80 chars long. Would you mind breaking it into two lines? (see my earlier commit message example) We typically don't have > 80 chars in a commit line unless there's a compelling reason to.

Other than that, it looks good to go!

Copy link
Contributor

@nabijaczleweli nabijaczleweli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In-placing /dev/null ($# -eq 1) fails, and editing the message in-place breaks expectations (and possibly mangles the message repeatedly forever); this is better served as

    if [ "${ZED_EMAIL_OPTS%@SUBJECT@*}" = "${ZED_EMAIL_OPTS}" ]; then
        [ -s "${pathname}" ] && sed -i "1iSubject: ${subject}
" "${pathname}" || echo "Subject: ${subject}"
    else
        cat "${pathname}"
    fi | eval ${ZED_EMAIL_PROG} ${ZED_EMAIL_OPTS} >/dev/null 2>&1

or, well,

    {
        [ "${ZED_EMAIL_OPTS%@SUBJECT@*}" = "${ZED_EMAIL_OPTS}" ] && echo "Subject: ${subject}"
        cat "${pathname}"
    } | eval ${ZED_EMAIL_PROG} ${ZED_EMAIL_OPTS} >/dev/null 2>&1

cmd/zed/zed.d/zed-functions.sh Outdated Show resolved Hide resolved
cmd/zed/zed.d/zed-functions.sh Outdated Show resolved Hide resolved
@heeplr
Copy link
Contributor Author

heeplr commented May 17, 2022

@nabijaczleweli thanks, good catch! I adressed those issues.

Also I've added a default subject, so mail notifications don't get discarded if the subject is empty. @tonyhutter Should I squash those commits? (I didn't since I'd see them as different changes but can do if that's better.)

I tested with:

#!/bin/sh

. "./zed-functions.sh"
. "./zed.rc"

echo "foo" > /tmp/test

zed_notify_email "Test notification" /tmp/test
zed_notify_email "Test no body" /dev/null
zed_notify_email "" /tmp/test

rm /tmp/test

@nabijaczleweli
Copy link
Contributor

Yeah, code-wise that's fine. I'm not sure what the point of the comments is, though, since they're all, almost literally

# echo subject header
echo "Subject: $subject"

and they make up 90% of the diff

@heeplr
Copy link
Contributor Author

heeplr commented May 17, 2022

@nabijaczleweli the point of the comments is to serve as alternative or addition to the actual code to describe what's going on to everybody, even those who don't instantly recognize what the code is doing.

The section you cited was already changed in the current diff. I agree that this was a superflous comment.

and they make up 90% of the diff

I could optimize the diff for size but I'd abstain from that as they don't impose a lot of cost. Although I'd welcome anyone to remove them if they don't fit the general style and wouldn't insist on them.

@behlendorf behlendorf requested a review from tonyhutter May 17, 2022 16:21
@tonyhutter
Copy link
Contributor

@heeplr yes, please squash the commits.

Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels May 18, 2022
@behlendorf behlendorf merged commit 08b32c6 into openzfs:master May 18, 2022
behlendorf pushed a commit to behlendorf/zfs that referenced this pull request May 25, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
behlendorf pushed a commit that referenced this pull request May 27, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes #13440
nicman23 pushed a commit to nicman23/zfs that referenced this pull request Aug 22, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
nicman23 pushed a commit to nicman23/zfs that referenced this pull request Aug 22, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
lundman pushed a commit to openzfsonwindows/openzfs that referenced this pull request Sep 12, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
beren12 pushed a commit to beren12/zfs that referenced this pull request Sep 19, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
andrewc12 pushed a commit to andrewc12/openzfs that referenced this pull request Sep 23, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
andrewc12 pushed a commit to andrewc12/openzfs that referenced this pull request Sep 23, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
andrewc12 pushed a commit to andrewc12/openzfs that referenced this pull request Sep 23, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
andrewc12 pushed a commit to andrewc12/openzfs that referenced this pull request Sep 23, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
andrewc12 pushed a commit to andrewc12/openzfs that referenced this pull request Sep 23, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
andrewc12 pushed a commit to andrewc12/openzfs that referenced this pull request Sep 23, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
andrewc12 pushed a commit to andrewc12/openzfs that referenced this pull request Sep 23, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
andrewc12 pushed a commit to andrewc12/openzfs that referenced this pull request Sep 23, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
andrewc12 pushed a commit to andrewc12/openzfs that referenced this pull request Sep 23, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
andrewc12 pushed a commit to andrewc12/openzfs that referenced this pull request Sep 23, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
andrewc12 pushed a commit to andrewc12/openzfs that referenced this pull request Sep 23, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
andrewc12 pushed a commit to andrewc12/openzfs that referenced this pull request Sep 23, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
andrewc12 pushed a commit to andrewc12/openzfs that referenced this pull request Sep 23, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
andrewc12 pushed a commit to andrewc12/openzfs that referenced this pull request Sep 23, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
andrewc12 pushed a commit to andrewc12/openzfs that referenced this pull request Sep 23, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
andrewc12 pushed a commit to andrewc12/openzfs that referenced this pull request Sep 23, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
andrewc12 pushed a commit to andrewc12/openzfs that referenced this pull request Sep 23, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
andrewc12 pushed a commit to andrewc12/openzfs that referenced this pull request Sep 23, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
andrewc12 pushed a commit to andrewc12/openzfs that referenced this pull request Sep 23, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
andrewc12 pushed a commit to andrewc12/openzfs that referenced this pull request Sep 23, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
andrewc12 pushed a commit to andrewc12/openzfs that referenced this pull request Sep 23, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
andrewc12 pushed a commit to andrewc12/openzfs that referenced this pull request Sep 23, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
andrewc12 pushed a commit to andrewc12/openzfs that referenced this pull request Sep 23, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
andrewc12 pushed a commit to andrewc12/openzfs that referenced this pull request Sep 23, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
andrewc12 pushed a commit to andrewc12/openzfs that referenced this pull request Sep 23, 2022
Some minimal MUAs don't support passing the subjects as cmdline option.
This commit checks if "@subject@" is missing in ZED_EMAIL_OPTS and then
prepends a subject header to the notification message.
Also set a default for ${subject}.

Reviewed-by: Ahelenia Ziemia<C5><84>ska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Daniel Hiepler <d-git@coderdu.de>
Closes openzfs#13440
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Accepted Ready to integrate (reviewed, tested)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants