Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/awk -f
- # Prepares a .ldif file in preparation for gnokii to load to a Nokia Series 40 phone
- # Change history
- # * Version 0.0 17may11 Charles
- # First published version, developed and tested using Thunderbird export
- # * Version 0.1 23may11 Charles
- # Changed tabs to spaces
- # * Version 0.2 23jun11 Charles
- # Fixed base64 wrapping lines by adding --wrap=0 option
- # Added ^mobile: to telephone numbers to have non-numerics stripped
- BEGIN {
- FS = ":"
- max_description_len = 116 # gnokii limit at 12may11
- }
- # Note cn for use in any log message
- /^cn:/ {
- if ( $0 ~ /^cn::/ )
- {
- "echo " substr( $0, 6 ) " | base64 --decode" | getline cn
- }
- else
- {
- cn = substr( $0, 5 )
- }
- }
- # Remove non-numerics from phone numbers, keeping any +
- /^facsimiletelephonenumber: / || /^homePhone: / || /^mobile: / || /^telephoneNumber: / {
- $2 = substr( $2, 2 ) # Remove leading space
- if ( substr( $2, 1, 1 ) == "+" )
- {
- plus = "+"
- $2 = substr( $2, 2 )
- }
- else plus = ""
- gsub( /[^0-9]/, "", $2 )
- print $1 ": " plus $2
- next
- }
- # Truncate any long "description"s
- /^description:/ {
- base64 = 0
- truncated = 0
- if ( $0 ~ /^description::/ )
- {
- #print "Found base-64 description. $0: " $0 > "/dev/stderr"
- base64 = 1
- "echo " substr( $0, 14 ) " | base64 --decode" | getline value
- if ( value ~ /^base64: invalid input/ )
- {
- print "WARNING: " cn ": description/note is invalid base-64; deleted (input line " NR ")" > "/dev/stderr"
- next
- }
- }
- else value = $2
- if ( length( value ) > max_description_len )
- {
- truncated = 1
- print "WARNING: " cn ": description/note longer than " max_description_len "; truncated (input line " NR ")" > "/dev/stderr"
- value = substr( value, 1, max_description_len )
- }
- if ( base64 )
- {
- gsub( "'", "'\"'\"'", value )
- "echo '" value "' | base64 --wrap=0" | getline value
- print "description:: " value
- }
- else
- {
- print "description: " value
- }
- next
- }
- { print }
Advertisement
Add Comment
Please, Sign In to add comment