mutt/mutt_idna.c -rw-r--r-- 9.0 KiB
Support domain-literal values in email adddresses.

RFC 5322 defines the domain-literal:

   domain          =   dot-atom / domain-literal / obs-domain

   domain-literal  =   [CFWS] "[" *([FWS] dtext) [FWS] "]" [CFWS]

   dtext           =   %d33-90 /          ; Printable US-ASCII
                       %d94-126 /         ;  characters not including
                       obs-dtext          ;  "[", "]", or "\"

RFC 5321 defines possible literal values in section 4.1.3.

I think this was unnoticed (and possibly unimplemented) because it's a
rare use-case.  However, Stuart Gathman @sdgathman in the
ticket (#226) noted:

  The use case is replacing alpine with mutt for this fully
  decentralized usage:


  The only requirements are to support IPv6 and IPv6 literals (to
  avoid use of DNS).

Adding this slightly complicates the parser, because we can't wait to
decide whether it's a domain-literal until parse_mailboxdomain(), but
we also need to accommodate the CFWS.

Break out a parse_domain() function, with partial duplication of
parse_mailboxdomain()'s logic.

Also, add parse_literal() to the outer parser, because we need to
handle both name-addr and top level addr-spec.

The RFC822Errors[] are currently unused (and broken), but add a new
error code and message, in case those get fixed up and introduced to
the code in the future.

Disable IDNA encoding for domain-literals.
Clean up code indentation.

These are mostly automated changes corresponding to the emacs
  (c-set-style "linux")
  (setq c-basic-offset 2)
  (c-set-offset 'case-label '+)

Most of the code follows the convention:
  (add-to-list 'c-cleanup-list 'space-before-funcall)
but this is not enforced by this indentation cleanup.

Also, I personally dislike tabs, so I have:
  (setq-default indent-tabs-mode nil)
in my own configuration.  However I have no desire to change every line
just for that effect.  So this cleanup does nothing about the mix issue.

Some of the secondary files (e.g. regex.c) have been skipped.

I've also skipped crypt-gpgme.c, because I need to think about that
file.  Werner Koch and the GnuPG team contributed most it, and it
follows the Gnu indentation settings.  It should probably be made
uniform with Mutt, but I don't want to discourage future GnuPG
contribution to the file.

I manually reverted a few unsightly cleanups, and added a few tweeks
when I saw things that could be improved.
Remove trailing whitespace.

The result of
  find . -name "*.[ch]" -exec emacs -batch {} \
    --eval="(progn (delete-trailing-whitespace) (and (buffer-modified-p) (save-buffer)))" \;
13a2f614 — Matej Muzila 2 years ago
Add libidn2 support
merge default into stable
Convert copyright years to all use 4 digit years.

Vincent Lefèvre pointed out the common shortcut, e.g 1996-9, is
actually not allowed for copyright years.  Convert all the copyright
years (for mutt files) to use 4 digits.
Update copyright notices.

This patch only updates existing copyright notices in the source
files, using commit dates since the last copyright update in commits
e3af935cdb1a and f8fd60d8d3f2.

Add a notice to the COPYRIGHT file to refer to our mercurial
repository for the full commit history.

Add myself to the COPYRIGHT file and smime_keys.pl file.
Fix bad idn error on local mailboxes.  (closes #3795)

Commit 831abf39d53a pulled the mbox_to_udomain() call inside the
conversion functions.  Unfortunately, this causes local (user only)
mailboxes to be considered conversion errors instead of just skipping

Revert mbox_to_udomain() back to using a static buffer and pull back
into the mutt_addrlist_to_local/intl() functions.

Pass the user and domain into the conversion functions instead of the address.
Add user reversibility check in intl_to_local.

This ensures we don't lose information by converting to the local charset.
Add option 'idn_encode'; rename option 'use_idn' to 'idn_decode'.

This is patch 3 of 4 implementing support for SMTPUTF8 (RFC 6531).

Add an option to control whether international domains are encoded with
IDN or not.  This defaults to set, for backward compatibility.

Rename the use_idn option to idn_decode, since that more properly
reflects its purpose.
Rewrite address local-to-intl conversion functions.

This is patch 2 of 4 implementing support for SMTPUTF8 (RFC 6531).

Perform charset conversion from local to UTF-8 for both the user and
domain parts of the address.

If IDN is enabled and the options (added in the next patch) are turned
on, encode/decode the domain part.

Use the intl_checked and is_intl status bits to record the intl/local
status of the ADDRESS mailbox part.
Rename idna functions and bits for smtputf8 changes.

This is patch 1 of 4 implementing support for SMTPUTF8 (RFC 6531).

Change mutt_idna.c to be always compiled.  Remove the stub functions in
mutt_idna.h.  Instead, put #ifdefs around the idna function calls.  The
conversion functions will be fixed up in the next patch.

Rename the conversion functions to mutt_addrlist_to_intl() and
mutt_env_to_intl().  Rename the ADDRESS idna status bits to "intl"
status bits.
e2494538 — Thomas Roessler 11 years ago
Make IDNA code more readable
ecad84f5 — Brendan Cully 12 years ago
Update copyrights. Closes #3016.
I went through the logs of each file with a copyright header and
updated the years for the authors in the headers for any non-comment
changes they introduced. What a pain!
85e3a1a4 — Emanuele Giaquinta 12 years ago
Make some functions static.
1a34c31c — Brendan Cully 12 years ago
Clean up with/without-idn handling
ad3eb691 — Brendan Cully 12 years ago
Build no-op versions of new IDN functions if IDN is unavailable.
Closes #3122, #3123.
4af1c6d6 — Thomas Roessler 12 years ago
sorting efficiency
73879187 — Brendan Cully 13 years ago
Merge flea restore
98c86d03 — Brendan Cully 13 years ago
Merge $umask backout
bbf8fcd9 — Alain Bench 13 years ago
Remove buggy usage of M_ICONV_HOOK_TO flag in mutt_idna.c:mutt_idna_to_local().
Wipe unwanted code depending on M_ICONV_HOOK_TO in charset.c:mutt_iconv_open().
Totally wipe M_ICONV_HOOK_TO symbol.
Remove misusages of M_ICONV_HOOK_FROM flag in:
 - crypt-gpgme.c:print_utf8().
 - mutt_idna.c:mutt_idna_to_local() and mutt_local_to_idna().
 - pgp.c:pgp_traditional_encryptsign().
Document usage policy of M_ICONV_HOOK_FROM flag.
Cosmetic downcasing of some constant charset names (utf-8, euc-jp) for consistency.
Correction of a typo in the "iso8859-5" charset name.