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

Set correct utf-8 email subject header (RFC1342) #6369

Merged
merged 2 commits into from
Nov 14, 2019
Merged

Set correct utf-8 email subject header (RFC1342) #6369

merged 2 commits into from
Nov 14, 2019

Conversation

islander
Copy link
Contributor

@islander islander commented Jun 13, 2018

Fix email notification subject header, according to RFC1342.

When using UTF-8 charset in Host or Services names, some mail clients can't correctly display notification e-mail headers (see question marks on screenshot). So we encode Subject header according to RFC1342.

1.5 SUBJ_ILLEGAL_CHARS Subject: has too many raw illegal characters
0.0 SUBJECT_NEEDS_ENCODING Subject is encoded but does not specify the encoding

icinga_utf8

@islander islander changed the title set correct utf8 email subject header (RFC1342) Set correct utf8 email subject header (RFC1342) Jun 13, 2018
@islander islander changed the title Set correct utf8 email subject header (RFC1342) Set correct utf-8 email subject header (RFC1342) Jun 13, 2018
@Crunsher Crunsher added the area/itl Template Library CheckCommands label Jun 13, 2018
@dnsmichi
Copy link
Contributor

Since this may affect *BSD, Gentoo and more, I have added team reviewers. Linux is probably tested already.

@dnsmichi dnsmichi added the TBD To be defined - We aren't certain about this yet label Jun 21, 2018
@dnsmichi
Copy link
Contributor

@prometheanfire @larsengels @mjbrooks an update please :)

@prometheanfire
Copy link

I haven't seen anything about this. Here's my neomutt output with headers.

Return-Path: <icinga@NOPE>
Delivered-To: NOPE
Received: from mx1.NOPE (localhost [127.0.0.1])
        by mx1.NOPE (Postfix) with UTF8SMTP id EHHHHHH
        for <NOPE@NOPE>; Fri, 19 Oct 2018 16:36:55 -0400 (EDT)
Received: by mx1.NOPE (Postfix, from userid EHHHHHH)
        id MEH; Fri, 19 Oct 2018 16:36:55 -0400 (EDT)
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on mx1.NOPE
X-Spam-Level:
X-Spam-Status: No, score=0.7 required=3.0 tests=BAYES_00,
        PP_MIME_FAKE_ASCII_TEXT,SUBJECT_NEEDS_ENCODING,SUBJ_ILLEGAL_CHARS
        autolearn=no autolearn_force=no version=3.4.1
Received: from foo.NOPE (netmon2.mthode.org [IPv6:never:gonna:give: you:up])
        by mx1.FOO (Postfix) with ESMTP id EHHHH
        for <foo@NOPE>; Fri, 19 Oct 2018 16:36:54 -0400 (EDT)
Received: by foo.NOPE (Postfix, from userid EHHH)
        id EHHHHH; Fri, 19 Oct 2018 20:36:24 +0000 (UTC)
Subject: [CUSTOM] ؏ي on netmon2.mthode.org is OK!
To: foo@NOPE
X-Mailer: mail (GNU Mailutils 3.4)
Message-Id: <MEH>
Date: Fri, 19 Oct 2018 20:36:24 +0000 (UTC)
From: icinga2 <icinga@NOPE>
X-Virus-Scanned: ClamAV using ClamSMTP

***** Service Monitoring on foo.NOPE *****

؏ي on NOPE is OK!

Info:    PING OK - Packet loss = 0%, RTA = 0.08 ms

When:    2018-10-19 20:36:24 +0000
Service: ؏ي
Host:    netmon2.mthode.org
IPv4:    10.0.1.212
IPv6:    2001:470:e1cc:1:f816:3eff:feaa:d4ad

Comment by admin:
  test utf8

@prometheanfire
Copy link

it looks like the gmail client on my phone shows the same thing though (pixel, android 9, oct 5 security update).

@prometheanfire
Copy link

Looks like the header for subject wasn't set as follows. (doesn't seem like it)

https://ncona.com/2011/06/using-utf-8-characters-on-an-e-mail-subject/

@dnsmichi
Copy link
Contributor

@dgoetz Can you please me out on this please? :)

@dgoetz
Copy link
Contributor

dgoetz commented Feb 12, 2019

I had a similar problem with a user using outlook and exchange getting message as winmail.dat instead of the body. My solution was to add -S "sendcharset=utf-8" to mailx. This would have the advantage to be more simple and also target the body and not only subject, but perhaps both fixes are required.

@islander Can you test this option if it solves your use case, too?

@bsdlme
Copy link
Contributor

bsdlme commented Feb 12, 2019

I haven't tested it, but on FreeBSD the port would need a new dependency on converters/base64 to encode the subject. No problem but I have to remember to add it if the patch gets accepted: :)

@islander
Copy link
Contributor Author

islander commented Feb 12, 2019

@islander Can you test this option if it solves your use case, too?

I'm using Debian 9.5 (Stretch), there is no such option: mailx: invalid option -- 'S'

# dpkg -l | grep mailx
ii  bsd-mailx                            8.1.2-0.20160123cvs-4

I can install heirloom-mailx, but it won't be clean solution, cause of this bug: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=867623. One workaround is to set alternatives manually:

    # update-alternatives --install /usr/bin/mailx mailx /usr/bin/heirloom-mailx \
    60 --slave /usr/bin/mail mail /usr/bin/heirloom-mailx \
    --slave /usr/share/man/man1/mail.1.gz mail.1.gz \
    /usr/share/man/man1/heirloom-mailx.1.gz --slave \
    /usr/share/man/man1/mailx.1.gz mailx.1.gz \
    /usr/share/man/man1/heirloom-mailx.1.gz
    
    # update-alternatives --set mailx /usr/bin/heirloom-mailx

Then notification mail comes with correctly encoded subject headers. But I'm not sure if these customizations won't affect other parts of Debian (cron, etc.), according to earlier mentioned Debian bug.

@dgoetz
Copy link
Contributor

dgoetz commented Feb 13, 2019

Does bsd-mailx work with -a 'charset="UTF-8"' which should be equivalent?

@islander
Copy link
Contributor Author

islander commented Feb 14, 2019

Does bsd-mailx work with -a 'charset="UTF-8"' which should be equivalent?

This option only adds charset header, but not makes base64-encoding of subject text (see RFC1342), so it's not working. Btw, correct syntax is -a 'Charset: UTF-8' at my installation at least.

@BuildTheRobots
Copy link

The attached mail-host-noficiation.sh script breaks amusingly on Centos 7.
Please see: #7510 (comment)

Copy link
Contributor

@robert-scheck robert-scheck left a comment

Choose a reason for hiding this comment

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

I don't understand why you would like to merge the fix from #7184 again, which is already in master…
Sorry, I got tricked by looking only to the second commit.

@dnsmichi dnsmichi added area/setup Installation, systemd, sample files and removed TBD To be defined - We aren't certain about this yet area/itl Template Library CheckCommands labels Nov 14, 2019
@dnsmichi dnsmichi added this to the 2.12.0 milestone Nov 14, 2019
@dnsmichi
Copy link
Contributor

Thanks for your work 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/setup Installation, systemd, sample files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants