Skip to content

Commit

Permalink
add html2nmail util that may be used for html_to_text_cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
d99kris committed Jun 29, 2024
1 parent c7d7f8d commit a6736ce
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ install(FILES src/nmail.1 DESTINATION share/man/man1)

# Utils
configure_file(src/oauth2nmail ${CMAKE_CURRENT_BINARY_DIR}/oauth2nmail COPYONLY)
configure_file(src/html2nmail ${CMAKE_CURRENT_BINARY_DIR}/html2nmail COPYONLY)
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/oauth2nmail DESTINATION bin)
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/html2nmail DESTINATION bin)

# Themes
macro(add_theme themename)
Expand All @@ -259,5 +261,6 @@ add_custom_target(uninstall
COMMAND "${CMAKE_COMMAND}" -E remove "${CMAKE_INSTALL_PREFIX}/bin/nmail"
COMMAND "${CMAKE_COMMAND}" -E remove "${CMAKE_INSTALL_PREFIX}/share/man/man1/nmail.1"
COMMAND "${CMAKE_COMMAND}" -E remove "${CMAKE_INSTALL_PREFIX}/bin/oauth2nmail"
COMMAND "${CMAKE_COMMAND}" -E remove "${CMAKE_INSTALL_PREFIX}/bin/html2nmail"
COMMAND "${CMAKE_COMMAND}" -E remove_directory "${CMAKE_INSTALL_PREFIX}/share/nmail"
)
44 changes: 44 additions & 0 deletions src/html2nmail
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

# html2nmail
#
# Copyright (c) 2024 Kristofer Berggren
# All rights reserved.
#
# nmail is distributed under the MIT license, see LICENSE for details.

INPATH=${1}

if [[ ! -f "${INPATH}" ]]; then
>&2 echo "usage: html2nmail <html-file>"
exit 1
fi

# 1 = no table in html file
NO_TABLE=$(grep -qi '<table' "${INPATH}" ; echo ${?})

if [[ "${NO_TABLE}" == "1" ]]; then
if command -v pandoc &> /dev/null; then
pandoc -f html -t plain+literate_haskell --wrap=preserve "${INPATH}"
exit ${?}
fi
fi

if command -v w3m &> /dev/null; then
w3m -T text/html -I utf-8 -dump "${INPATH}"
exit ${?}
fi

if command -v lynx &> /dev/null; then
lynx -assume_charset=utf-8 -display_charset=utf-8 -nomargins -dump "${INPATH}"
exit ${?}
fi

if command -v elinks &> /dev/null; then
elinks -dump-charset utf-8 -dump "${INPATH}"
exit ${?}
fi

>&2 echo "error: html2nmail found no supported html converter"
exit 1

2 changes: 1 addition & 1 deletion src/nmail.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man.
.TH NMAIL "1" "June 2024" "nmail v4.69" "User Commands"
.TH NMAIL "1" "June 2024" "nmail v4.70" "User Commands"
.SH NAME
nmail \- ncurses mail
.SH SYNOPSIS
Expand Down
2 changes: 1 addition & 1 deletion src/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "version.h"

#define NMAIL_VERSION "4.69"
#define NMAIL_VERSION "4.70"

std::string Version::GetBuildOs()
{
Expand Down

0 comments on commit a6736ce

Please sign in to comment.