File: sun2mime

package info (click to toggle)
metamail 2.7-34
  • links: PTS
  • area: main
  • in suites: potato
  • size: 932 kB
  • ctags: 668
  • sloc: ansic: 7,986; sh: 1,661; csh: 229; makefile: 202
file content (40 lines) | stat: -rwxr-xr-x 1,032 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/sh -e
#
# This is sun2mime.  It makes a bold attempt to transform a Sun mailtool message into
# MIME format.
#
# This program is for use with sun-message which takes an arg to figure out how
# (or if) the message is encoded.
#
TMPFILE=`tempfile -p metamail -m 600`

nawk '
  BEGIN { printf("Content-type: multipart/mixed; boundary=--------\n\n")
          RS=""; FS="\n"; mode="HEADER" }
  mode == "HEADER" {
    encoding=""
    for (i=1; i<=NF; i++)
      if ($i ~ /^X-Sun-Encoding-Info:/) {
        encoding = sprintf ("; encoding=%s", substr($i,index($i,":")+1))
      }
    for (i=1; i<=NF; i++)
      if ($i ~ /^X-Sun-Data-Type:/)
        printf ("Content-Type:%s%s\n", substr($i,index($i,":")+1), encoding)
      else
        print $i
    RS="\n"; FS=" "; getline; mode="BODY"; printf ("\n") }
  mode == "BODY" {
    if ($0 == "----------") {
      print
      mode="HEADER"
      RS=""; FS="\n"
    }
    else
      print
  }
  END { printf("----------\n") }
' "$1" > $TMPFILE

metamail -z $TMPFILE
rm $TMPFILE
exit 0