Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Troubleshooting password issues in Mail.app


killall -HUP Mail      # quit Mail


# troubleshooting step 1

open -a 'Keychain Access'    # ... run Keychain First Aid ...


# troubleshooting step 2

ls -l ~/Library/Keychains/*    # check owner & write permissions
find ~/Library/Keychains -ls
dirmodes ~/Library/Keychains     # cf. http://codesnippets.joyent.com/posts/show/1402


# troubleshooting step 3

# delete com.apple.keychainaccess.plist
#srm -v ~/Library/Preferences/com.apple.keychainaccess.plist
mv -i ~/Library/Preferences/com.apple.keychainaccess.{plist,plist.orig}

open -a Mail


# troubleshooting step 4

# delete the login keychain file in ~/Library/Keychains & restore it via Mail.app

killall -HUP Mail 'Keychain Access'

# srm -v ~/Library/Keychains/*

find ~/Library/Keychains -type f -exec mv -i '{}' '{}'.orig \;

#find ~/Library/Keychains -type f -exec bash -c 'fpath=$(printf "%s" '{}' | sed 's/\\\\\\\.orig$//'); mv -i '{}' "${fpath}"' \;    #  undo mv again

open -a Mail



# See also:

# Troubleshooting Mail issues in Mac OS X 10.6 Snow Leopard,
# http://reviews.cnet.com/8301-13727_7-10333904-263.html

# Overcoming Mail.app's Lack of Verbosity,
# http://geekfoibles.wordpress.com/2009/04/21/overcoming-mailapps-lack-of-verbosity/

/Applications/Mail.app/Contents/MacOS/Mail -LogActivityOnPort 25

/Applications/Mail.app/Contents/MacOS/Mail -LogSocketErrors YES -LogActivityOnHost your.mail.server -LogActivityOnPort "25,143,465,597,993"

Debugging a file name with a backslash character in Bash

# create a file name containing a backslash character \
file=${HOME}/Desktop/'te:st\file'.txt
echo "${file}"
echo "${file}" | sed -n -e 'l'

echo 'This is a test case for a file name containing a backslash \ character!' > "${file}"
open -e "${file}"

set -vx

# note: avoid trailing spaces in ed commands
cat <<EOF | /bin/ed -s "${file}"
H
,g|^This|s|test case|SUCCESSFUL TEST CASE|
w
EOF

open -e "${file}"


# escape backslashes
cat <<EOF | /bin/ed -s "${file//\\/\\\\}"
H
,g|^This|s|test case|SUCCESSFUL TEST CASE|
w
EOF

open -e "${file}"


# printf "%q"
help printf | sed -E "s/(%q)/$(printf '\e[1m\\1\e[m')/"
echo "${file}"
echo "$(printf "%q" "${file}")"   # cf. help printf
echo "$(printf "%q" "${file}")" | sed -n -e 'l'

# escape file name
cat <<EOF | /bin/ed -s "$(printf "%q" "${file}")"
H
,g|^This|s|backslash|BACKSLASH|
w
EOF

open -e "${file}"


echo "${file}"
echo "${file}" | sed -n -e 'l'

file="${file//\\/\\\\}"
echo "${file}"
echo "${file}" | sed -n -e 'l'


# references
man bash 2>/dev/null | less -p 'backslash'
man bash 2>/dev/null | less -p 'Each command in a pipeline'
man bash 2>/dev/null | less -p 'Functions are executed'
help printf | sed -E "s/(%q)/$(printf '\e[1m\\1\e[m')/"
open http://en.wikipedia.org/wiki/Filename


# "Each command in a pipeline is executed as a separate process (i.e., in a subshell)."
# From: man bash

# "Functions are executed in the context of the current shell; no new process is created to 
# interpret  them (contrast this with the execution of a shell script)."
# From: man bash

# "Unix-like systems are an exception, as the only control character forbidden in file names 
# is the null character, as that's the end-of-string indicator in C. Trivially, Unix also 
# excludes the path separator / from appearing in filenames."
# From: http://en.wikipedia.org/wiki/Filename

Setting the CrashReporter mode to "Developer"

locate *CrashReporterPrefs.app
open /Developer/Applications/Utilities/CrashReporterPrefs.app

/usr/bin/defaults write com.apple.CrashReporter DialogType -string developer
#/usr/bin/defaults write com.apple.CrashReporter DialogType -string basic
#/usr/bin/defaults write com.apple.CrashReporter DialogType -string server

mycmds

help set
set -xv

#echo $-
#shopt -u
#shopt -s
#shopt -s | grep expand_aliases
#shopt -q expand_aliases; echo $?
#help shopt
#shopt -p
#shopt -s expand_aliases   

unalias mycmds1 mycmds2 mycmds3  2>/dev/null
alias mycmds1="declare -F | /usr/bin/awk '{print \$NF}' | /usr/bin/sort"
alias mycmds2="declare -F | /usr/bin/awk '{print $NF}' | /usr/bin/sort"
alias mycmds3='declare -F | /usr/bin/awk "{print $NF}" | /usr/bin/sort'

mycmds1
mycmds2
mycmds3


alias mycmds="alias -p | /usr/bin/awk -F= '{print \$1}' | /usr/bin/sort; \
              declare -F | /usr/bin/awk '{print \$NF }' | /usr/bin/sort"

mycmds

Show Errors in PHP

php_flag display_errors on
php_value error_reporting 7