muttprint

Muttprint is a tool to print an email message in mutt: The documentation – at least here on Debian/unstable, and as of today – in some important sections seems to be a bit useless. That’s why you’re here, right … :) … ?

For example this setting in ~/.muttrc that is recommended in
/usr/share/doc/muttprint/manual/manual-en.pdf.gz
is useless here:

# Dump all headers
macro index p "<display-toggle-weed> <print-message> <display-toggle-weed> <exit>"
macro pager p "<display-toggle-weed> <print-message> <display-toggle-weed>"

Well: wrong, I was lying: the documentation mentioned above says, just a few words later, to set

# No confirmation before printing
set print="yes"

If you have this last line in your ~/.muttrc chances are good that things go well for mutt printings … Problem with this setting: printing seems to start immediately, without confirmation, after typing 'p' in mutt. Here’s a nice workaround for that:

Simply direct the print-out to your favorite gv viewer. I use 'kghostview' for it. So the necessary setting for that would be something like this in ~/.muttprintrc:

PRINT_COMMAND="kghostview – "

Leaving away the hyphen in the line above might yield an empty page …

Please see my complete ~/.muttprintrc near the end of this post.

Note that in ~/.muttprintrc some options set to the "PRINTED_HEADERS=" line seem to get ignored in the actual print-out. Don’t ask me why, because I don’t get that …

Here’s what might be necessary for your ~/.muttrc, too :

set print_command="muttprint"
set print_split

So with the settings mentioned here, to print an email it should be enough to open it, then maybe toggling the display of headers or not by typing 'h', and then 'p' for the actual preview …

Result: Reading the available documentation for muttprint on Debian, added to the few hints from here should give you nice prints from within mutt. … :)

Following the mentioned config settings in one place. Relevant lines in ~/.muttrc:


#### muttprint:
set print_command="muttprint"
set print_split

# Dump all headers
macro index p "<display-toggle-weed> <print-message> <display-toggle-weed> <exit>"
macro pager p "<display-toggle-weed> <print-message> <display-toggle-weed>"

# No confirmation before printing
set print="yes"

And here comes ~/.muttprintrc:

# MUTTPRINT configuration file
#
# ~/.muttprintrc or /etc/Muttprintrc
# ~/.muttprintrc

#
# Here you can configure your printer
# To print in a file, use the following entry:
# PRINTER="TO_FILE:/home/berwal/test.ps"
#PRINTER="lp"

#
# Here you can set the print command
# $PRINTER is substituted by the PRINTER
# variable
#PRINT_COMMAND="lpr -P$PRINTER"
#PRINT_COMMAND="CUPS"
#PRINT_COMMAND="gv -"
PRINT_COMMAND="kghostview -"

#
# Here you can set the path to the penguin image
PENGUIN="/usr/share/ospics/Debian_color.eps"
#PENGUIN="off"

#
# Turn printing of X-Face picture on/off (on needs the packages compface
# and imagemagick)
XFACE="off"

#
# Here you can turn the duplex print on or off. (needs psutils)
# Possible values are "off" or "on"
#
# For Postscript duplex printer set it to "printer"
DUPLEX="printer"

#
# Here you can turn on or off the paper save mode
# (printing 2 pages on 1 page) - needs psutils
# Set it to 'optional' if you only want papersave mode
# if more than one page is printed.
PAPERSAVE="off"

#
# Here you can set the printing speed in seconds
# per page
SPEED="80"

#
# Choose a font:
# - Latex (EC-Fonts)
# - Latex-bright (CM-bright)
# - Times
# - Utopia
# - Palatino
# - Charter
# - Bookman
FONT="Latex"


#
# Choose a style for the first page
# - plain       no rules
# - border      rule after the headers
# - fbox        simple box around the mailheaders
# - shadowbox   shadowbox around the header
# - ovalbox     box with rounded corners around the header (thin lines)
# - Ovalbox     same as "ovalbox" but thicker lines
# - doublebox   box with double lines around the header
# - grey        grey background behind the headers
# - greybox     same as "grey" but with a additional black box
FRONTSTYLE="fbox"

#
# Should there be a rule after the header (not first page)
HEADRULE="on"

#
# Should there be a rule over the footer
FOOTRULE="on"

#
# Choose a paper format, if not specified look in /etc/papersize
# - A4
# - letter
#PAPER="A4"

#
# prints signatures, and strange: Letting it as follows keeps the sig:
REM_SIG="on"
# how does a signature look like?
SIG_REGEXP="^-- $"

#
# prints no quoting
REM_QUOTE="off"

#
# Choose of the printed headers, separation with "_"
# /Header/ : italic printing
# *Header* : bold printing
# If the header does not exist, it is not printed.
#PRINTED_HEADERS="Date_To_From_CC_Newsgroups_*Subject*"
#PRINTED_HEADERS=
PRINTED_HEADERS="Date_From_To_Cc_Subject_In-Reply-To_MIME-Version_Content-Type_Content-Transfer-Encoding_Content-Disposition_References_Resent-Message-ID_Resent-From_X-Mailing-List_X-Loop_List-Id_Precedence_Resent-Sender_Resent-Date_Status_Content-Length_Lines_Return-Path_Delivered-To_Received_Old-Return-Path_X-Original-To"

# 
# Writes error messages of LaTeX and dvips to /tmp/muttprint.log
DEBUG="1"

#
# Font size: 10pt, 11pt or 12pt
FONTSIZE="10pt"

#
# Longest line
WRAPMARGIN="90"

# margins
TOPMARGIN="19"
BOTTOMMARGIN="22"
LEFTMARGIN="20"
RIGHTMARGIN="20"

#
# Date (format of printed date)
# original, local (needs Date::Parse from libtimedate-perl)
DATE="original"

#
# Date format string (only if DATE=local)
# See strftime(3) for details
#DATE_FORMAT="%c"

# pass special options to the verbatim environment, see texdoc fancyvrvb
VERBATIMNORMAL=""
VERBATIMSIG="fontshape=it"

# how should the address be printed out?
ADDRESSFORMAT="%r <%a>,\n"

# own LaTeX code to be inserted
#
# playing with these fonts:
# 'LATEXCODE=' seems to have an impact to the mail headers
# 'LATEXCODE1=' seems being good for the mail body
# .. now the 
#
# LATEXCODE1="\renewcommand{\ttdefault}{pcr}"
#
# seems to change the body font to 'courier'
# while
#
# LATEXCODE1="\renewcommand{\ttdefault}{phv}"
#
# seems to result in 'helvetica' for the mail body ..
#
# Alternatively you can try to replace 'phv' (in the 'LATEXCODE1' line) 
# with 'ptm', 'pop', 'pag' (bigger ..), 'pgm', 'pbk' ... no guarantees
# it will work ...
# See e.g.
# /usr/share/texmf-texlive/tex/latex/sugconf/sugconf.cls
# or simply grep the 'tex' files area above 
# for 'renewcommand', if you're curious ... :)


LATEXCODE="\renewcommand{\familydefault}{\sfdefault}"
#LATEXCODE1="\renewcommand{\ttdefault}{phv}"
LATEXCODE2=""
LATEXCODE3=""
LATEXCODE4=""
LATEXCODE5=""

Advertisements

CUPS and cupsd.conf on Linux

Accessing a CUPS driven printer without password

I had to do a few print-outs with my old printer, and realized the old cupsd.conf didn’t do any more what I wanted it to do, namely running my printer on my home network, via http://127.0.0.1:631/, and without having to type in usernames and passwords there every time I wanted to change some printer settings.

After lots of googling I found a solution: I forgot where I found the template, and how much I changed it to make it work the way it should. You’ll find it below.

Please note that this configuration file is for a secure home network. That is I’m the only one using that printer. So if in doubt whether it’s a good idea or not to use this cupsd.conf – then for the sake of your network security: don’t use it.

Note the cups Debian packages installed with this file :

$ dpkg -l | grep -i cups
ii  cups                                  1.3.10-1                       Common UNIX Printing System(tm) - server
ii  cups-bsd                              1.3.10-1                       Common UNIX Printing System(tm) - BSD comman
ii  cups-client                           1.3.10-1                       Common UNIX Printing System(tm) - client pro
ii  cups-common                           1.3.10-1                       Common UNIX Printing System(tm) - common fil
ii  cups-driver-gutenprint                5.2.3-2+b1                     printer drivers for CUPS
ii  gutenprint-doc                        5.2.3-2                        users' guide for Gutenprint and CUPS
ii  libcups2                              1.3.10-1                       Common UNIX Printing System(tm) - libs
ii  libcupsimage2                         1.3.10-1                       Common UNIX Printing System(tm) - image libs

So here goes /etc/cups/cupsd.conf:

#
# "$Id: cupsd.conf.in 7199 2008-01-08 00:16:30Z mike $"
#
#   Sample configuration file for the Common UNIX Printing System (CUPS)
#   scheduler.  See "man cupsd.conf" for a complete description of this
#   file.
#

# Log general information in error_log - change "info" to "debug" for
# troubleshooting...
LogLevel debug

# Administrator user group...
#SystemGroup lpadmin


# Only listen for connections from the local machine.
Listen localhost:631
Listen /var/run/cups/cups.sock

# Show shared printers on the local network.
Browsing On
BrowseOrder allow,deny
BrowseAllow all

# Default authentication type, when authentication is required...
DefaultAuthType Basic

# Restrict access to the server...
<Location />
  Order deny,allow
</Location>

# Restrict access to the admin pages...
<Location /admin>
  Encryption Required
  Order deny,allow
</Location>

# Restrict access to configuration files...
<Location /admin/conf>
  AuthType None
#  Require user @SYSTEM
  Order deny,allow
</Location>

# Set the default printer/job policies...
<Policy default>
  # Job-related operations must be done by the owner or an administrator...
  <Limit Send-Document Send-URI Hold-Job Release-Job Restart-Job Purge-Jobs Set-Job-Attributes Create-Job-Subscription Renew-Subscription Cancel-Subscription Get-Notifications Reprocess-Job Cancel-Current-Job Suspend-Current-Job Resume-Job CUPS-Move-Job>
#    Require user @OWNER @SYSTEM
    Order deny,allow
  </Limit>

  # All administration operations require an administrator to authenticate...
  <Limit CUPS-Add-Modify-Printer CUPS-Delete-Printer CUPS-Add-Modify-Class CUPS-Delete-Class CUPS-Set-Default>
    AuthType None
#    Require user @SYSTEM
    Order deny,allow
  </Limit>

  # All printer operations require a printer operator to authenticate...
  <Limit Pause-Printer Resume-Printer Enable-Printer Disable-Printer Pause-Printer-After-Current-Job Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer Activate-Printer Restart-Printer Shutdown-Printer Startup-Printer Promote-Job Schedule-Job-After CUPS-Accept-Jobs CUPS-Reject-Jobs>
    AuthType None
#    Require user @SYSTEM
    Order deny,allow
  </Limit>

  # Only the owner or an administrator can cancel or authenticate a job...
  <Limit Cancel-Job CUPS-Authenticate-Job>
#    Require user @OWNER @SYSTEM
    Order deny,allow
  </Limit>

  <Limit All>
    Order deny,allow
  </Limit>
</Policy>

#
# End of "$Id: cupsd.conf.in 7199 2008-01-08 00:16:30Z mike $".
#

An important part to stop access without authentication do seem to play the ‘Require user’ instances, that are commented out above.

I wouldn’t be astonished if the code above could be written much easier, more efficient, and yes, more beautiful than here – if all we want is unrestricted access to some printer: I did not have the time so far to find that solution. Please leave a comment here if you have one.

Thanks in anticipation.