[vim/vim] Read and write eml files with DOS line endings (#8607)

20 views
Skip to first unread message

Martin Tournoij

unread,
Jul 22, 2021, 1:11:39 AM7/22/21
to vim/vim, Subscribed

These are "raw" dumps of emails, and pretty much everyone uses and
expects DOS line endings, as specified in RFC5322.


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/8607

Commit Summary

  • Read and write eml files with DOS line endings

File Changes

Patch Links:


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

codecov[bot]

unread,
Jul 22, 2021, 1:19:01 AM7/22/21
to vim/vim, Subscribed

Codecov Report

Merging #8607 (f1d11ed) into master (d8e4447) will decrease coverage by 1.84%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@

##           master    #8607      +/-   ##

==========================================

- Coverage   90.07%   88.22%   -1.85%     

==========================================

  Files         150      149       -1     

  Lines      169145   165186    -3959     

==========================================

- Hits       152350   145733    -6617     

- Misses      16795    19453    +2658     
Flag Coverage Δ
huge-clang-none ?
huge-gcc-none ?
huge-gcc-testgui 88.18% <ø> (-0.01%) ⬇️
huge-gcc-unittests 2.48% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/libvterm/src/rect.h 0.00% <0.00%> (-96.56%) ⬇️
src/libvterm/src/mouse.c 0.00% <0.00%> (-48.34%) ⬇️
src/libvterm/src/state.c 49.10% <0.00%> (-40.90%) ⬇️
src/libvterm/include/vterm.h 0.00% <0.00%> (-37.50%) ⬇️
src/libvterm/src/pen.c 49.85% <0.00%> (-34.81%) ⬇️
src/libvterm/src/keyboard.c 54.73% <0.00%> (-33.69%) ⬇️
src/mouse.c 58.59% <0.00%> (-30.60%) ⬇️
src/libvterm/src/encoding.c 45.54% <0.00%> (-27.73%) ⬇️
src/clipboard.c 65.27% <0.00%> (-18.60%) ⬇️
src/libvterm/src/vterm.c 48.57% <0.00%> (-18.10%) ⬇️
... and 128 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d8e4447...f1d11ed. Read the comment docs.

Tony Mechelynck

unread,
Jul 22, 2021, 2:25:27 AM7/22/21
to vim_dev, reply+ACY5DGHAGCNHGFRGCO...@reply.github.com, vim/vim, Subscribed
On Thu, Jul 22, 2021 at 7:11 AM Martin Tournoij
<vim-dev...@256bit.org> wrote:
>
> These are "raw" dumps of emails, and pretty much everyone uses and
> expects DOS line endings, as specified in RFC5322.

Warning: 'fileformats' (plural) is a global (only) setting. This means
that changing it, even with :setlocal, will change the global value
and therefore affect all files from then on. In particular, all files
(of any filetype) read thereafter will be written (if and when they
are) with DOS ends-of-lines, even if when read they had only Unix
ends-of-lines, since reading a unix-type file with 'fileformats' set
to "dos" (only) will recognize it as a DOS file. (In a DOS file,
either CR+LF or LF alone are accepted as an end-of-line when reading,
and all ends-of-lines, usually including the end of the last line, are
written as CR+LF when writing.)

Best regards,
Tony.

vim-dev ML

unread,
Jul 22, 2021, 2:25:45 AM7/22/21
to vim/vim, vim-dev ML, Your activity

On Thu, Jul 22, 2021 at 7:11 AM Martin Tournoij
***@***.***> wrote:
>
> These are "raw" dumps of emails, and pretty much everyone uses and
> expects DOS line endings, as specified in RFC5322.

Warning: 'fileformats' (plural) is a global (only) setting. This means
that changing it, even with :setlocal, will change the global value
and therefore affect all files from then on. In particular, all files
(of any filetype) read thereafter will be written (if and when they
are) with DOS ends-of-lines, even if when read they had only Unix
ends-of-lines, since reading a unix-type file with 'fileformats' set
to "dos" (only) will recognize it as a DOS file. (In a DOS file,
either CR+LF or LF alone are accepted as an end-of-line when reading,
and all ends-of-lines, usually including the end of the last line, are
written as CR+LF when writing.)

Best regards,
Tony.

Martin Tournoij

unread,
Jul 22, 2021, 2:30:54 AM7/22/21
to vim/vim, vim-dev ML, Push

@arp242 pushed 1 commit.

  • f085c67 Read and write eml files with DOS line endings


You are receiving this because you are subscribed to this thread.

View it on GitHub or unsubscribe.

Martin Tournoij

unread,
Jul 22, 2021, 2:31:20 AM7/22/21
to vim/vim, vim-dev ML, Comment

Ah, that is surprising! This setting should probably be global-local, but that's a different issue. I removed that for now, setting just fileformat=dos.


You are receiving this because you commented.

Bram Moolenaar

unread,
Jul 22, 2021, 7:11:45 AM7/22/21
to vim/vim, vim-dev ML, Comment

Setting 'fileformat' after loading a file doesn't have an effect. You would need to reload the file. And only do that if the 'fileformat' actually changed.
'fileformats' must be global, because it is used when reading a file, for which most likely no buffer exists yet.


You are receiving this because you commented.

Tony Mechelynck

unread,
Jul 22, 2021, 8:50:03 AM7/22/21
to vim/vim, vim-dev ML, Comment

Maybe a BufReadPre,BufNewFile autocommand could be created for *.eml, setting 'fileformat' (locally) to dos. This would read unix files without error, and write .eml files with CR+LF ends-of-lines, which is the correct format for email. But where to set up that autocommand? I suppose filetype.vim might be the right place, it sets up a lot of autocommands.

Just throwing an idea on the wall to see if it sticks. What do you people think of it?

Best regards,
Tony.


You are receiving this because you commented.

Martin Tournoij

unread,
Jul 22, 2021, 10:05:32 AM7/22/21
to vim/vim, vim-dev ML, Comment

Setting 'fileformat' after loading a file doesn't have an effect. You would need to reload the file. And only do that if the 'fileformat' actually changed.

In this case, that's actually just fine: loading a file with either \n and \r\n line-endings works, and saving them is always as \r\n with this change.

The reverse would be a bit more problematic, since loading a file with \r\n line-endings you need to tell Vim to interpret those \r's as line endings.

I've seen a lot of .eml files over the years from different systems on account of working a lot with email code, and I don't think I've ever seen one that wasn't with \r\n line endings.

The only issue is when people have "set fileformats=unix" in their vimrc, but that it arguably already not a great setting to add.


You are receiving this because you commented.

Bram Moolenaar

unread,
Oct 23, 2021, 5:16:05 PM10/23/21
to vim/vim, vim-dev ML, Comment

I'll include this and also add something to b:undo_ftplugin


You are receiving this because you commented.
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

Bram Moolenaar

unread,
Oct 23, 2021, 5:16:06 PM10/23/21
to vim/vim, vim-dev ML, Comment

Closed #8607.

Reply all
Reply to author
Forward
0 new messages