sfeed_mbox - localbin - leot's localbin (~/bin)
 (HTM) hg clone https://bitbucket.org/iamleot/localbin
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       sfeed_mbox
       ---
            1 #!/bin/sh
            2 
            3 #
            4 # Convert a feed sfeed to mbox, similar to original sfeed_mbox provided by
            5 # sfeed but also populating the content by converting it to text.
            6 #
            7 
            8 feed=$1
            9 
           10 if [ -z "${feed}" ]; then
           11         echo "usage: sfeed_mbox file"
           12         exit 1
           13 fi
           14 
           15 tail -r "${feed}" |
           16 awk -v FEED=$(basename "${feed}") '
           17 BEGIN {
           18         FS = "\t"
           19         mtime = strftime("%a %b %d %H:%M:%S %Y")
           20 }
           21 
           22 function print_content(c, c_type)
           23 {
           24         gsub("\\\\n", "\n", c)
           25         gsub("\\\\t", "   ", c)
           26         gsub("\\\\\\\\", "\\", c)
           27 
           28         # Nonexistent proxy to block HTTP requests
           29         cmd = "http_proxy=\"http://localhost:31283128\""
           30 
           31         if (c_type == "html") {
           32                 cmd = cmd " w3m -T text/html"
           33         } else {
           34                 cmd = cmd " w3m -T text/plain"
           35         }
           36         cmd = cmd " -config /dev/null"
           37         cmd = cmd " -dump -no-cookie -cols 78"
           38         cmd = cmd " -o display_link=true"
           39         cmd = cmd " -o display_link_number=true"
           40         cmd = cmd " -o display_image=false"
           41         cmd = cmd " -o pseudo_inlines=false"
           42 
           43         # Gracefully handle possible From in content
           44         cmd = cmd " | sed \"s/^From/>From/\""
           45 
           46         print c | cmd
           47         close(cmd)
           48 }
           49 
           50 {
           51         timestamp = $1
           52         title = $2
           53         link = $3
           54         content = $4
           55         content_type = $5
           56         id = $6
           57         author = $7
           58 
           59         feed = FEED
           60         sub(/.*\//, "", feed)
           61 
           62         # Workaround for feeds that have no id
           63         if (!id) {
           64                 id = "empty"
           65         }
           66 
           67         # Workaround for feeds that have empty link fields
           68         if (!link) {
           69                 link = id
           70         }
           71 
           72         if (!author) {
           73                 author = feed
           74         }
           75 
           76         print "From MAILER-DAEMON " mtime
           77         print "From: \"" author "\" <" feed "@sfeed.invalid>"
           78         print "Date: " strftime("%a, %d %b %Y %H:%M +0000 (UTC)", timestamp)
           79         print "Subject: " title
           80         print "X-RSS-Feed: " feed
           81         print "X-RSS-Id: " id
           82         print "X-RSS-URL: " link
           83         print "X-RSS-Content-Type: " content_type
           84         print "Content-Type: text/plain; charset=\"utf-8\""
           85         print "Content-Transfer-Encoding: binary"
           86         print ""
           87         print_content(content, content_type)
           88         print ""
           89         print ""
           90 }
           91 '