Difference between revisions of "PECL Mailparse"

From DreamHost
Jump to: navigation, search
m (Intro, fixes, and a link - oh my!)
m (Double-brackets are like moldy cheese.. they don't work!!)
Line 17: Line 17:
 
set -e
 
set -e
  
# Version 1.0a, 2007-10-05
+
# Version 1.0b, 2007-10-05
 
#
 
#
 
# - Initial Release (2007-10-05)
 
# - Initial Release (2007-10-05)
Line 52: Line 52:
  
 
# Clear and/or create the source directory.
 
# Clear and/or create the source directory.
if [[ -d ${SRCDIR} ]]; then
+
if [ -d ${SRCDIR} ]; then
 
  echo "Source directory already exists! Cleaning it..."
 
  echo "Source directory already exists! Cleaning it..."
 
  rm -rf $SRCDIR/*
 
  rm -rf $SRCDIR/*
Line 61: Line 61:
 
# Create the dist files directory if it doesn't exist
 
# Create the dist files directory if it doesn't exist
 
# optionally cleaning it if it does exist already.
 
# optionally cleaning it if it does exist already.
if [[ -d ${DISTDIR} ]]; then
+
if [ -d ${DISTDIR} ]; then
 
echo ""; echo "Distribution directory already exists!"; echo "Clean it?"
 
echo ""; echo "Distribution directory already exists!"; echo "Clean it?"
if [[ ${DISTDEL} == "Yes" ]]
+
if [ ${DISTDEL} == "Yes" ]
 
then
 
then
 
echo ""; echo "Yes!"; echo "Cleaning now..."; echo ""
 
echo ""; echo "Yes!"; echo "Cleaning now..."; echo ""
Line 75: Line 75:
 
fi
 
fi
 
# Make sure the extensions directory exists.
 
# Make sure the extensions directory exists.
if [[ -d ${INSTALLDIR}/lib/php/extensions ]]; then
+
if [ -d ${INSTALLDIR}/lib/php/extensions ]; then
 
  echo "lib/php/extensions folder already exists! Doing nothing..."
 
  echo "lib/php/extensions folder already exists! Doing nothing..."
 
else
 
else
Line 83: Line 83:
 
# Detect how many processors the system has (for more optimal compliation).
 
# Detect how many processors the system has (for more optimal compliation).
 
cores=2  # the number of cores/procs to use when building
 
cores=2  # the number of cores/procs to use when building
if [[ $cores -a $cores -gt 1 ]]; then
+
if [ $cores -a $cores -gt 1 ]; then
 
  j="-j$cores "
 
  j="-j$cores "
 
fi
 
fi
 
  OS=`uname -s`
 
  OS=`uname -s`
if [[ "Darwin" = $OS ]]; then
+
if [ "Darwin" = $OS ]; then
 
  sed=gnused
 
  sed=gnused
 
  makefile=makefile.macosx
 
  makefile=makefile.macosx
Line 107: Line 107:
  
 
# Do some of our own error checking here too.
 
# Do some of our own error checking here too.
if [[ -a ${DISTDIR}/${AUTOCONF}.tar.gz ]]; then
+
if [ -a ${DISTDIR}/${AUTOCONF}.tar.gz ]; then
 
  echo "Skipping wget of ${AUTOCONF}.tar.gz"
 
  echo "Skipping wget of ${AUTOCONF}.tar.gz"
 
else
 
else
 
  wget $WGETOPT ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/${AUTOCONF}.tar.gz
 
  wget $WGETOPT ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/${AUTOCONF}.tar.gz
 
  # If primary mirror fails, use the alternative mirror.
 
  # If primary mirror fails, use the alternative mirror.
  if [[ -a ${DISTDIR}/${AUTOCONF}.tar.gz ]]; then
+
  if [ -a ${DISTDIR}/${AUTOCONF}.tar.gz ]; then
 
echo "Got ${AUTOCONF}.tar.gz"
 
echo "Got ${AUTOCONF}.tar.gz"
 
  else
 
  else
 
wget $WGETOPT ftp://ftp.gnu.org/gnu/autoconf/${AUTOCONF}.tar.gz
 
wget $WGETOPT ftp://ftp.gnu.org/gnu/autoconf/${AUTOCONF}.tar.gz
 
# Check to make sure the alternative mirror worked.
 
# Check to make sure the alternative mirror worked.
if [[ -a ${DISTDIR}/${AUTOCONF}.tar.gz ]]; then
+
if [ -a ${DISTDIR}/${AUTOCONF}.tar.gz ]; then
 
echo "Got ${AUTOCONF}.tar.gz"
 
echo "Got ${AUTOCONF}.tar.gz"
 
else
 
else
Line 127: Line 127:
 
  fi
 
  fi
 
fi
 
fi
if [[ -a ${DISTDIR}/${AUTOMAKE}.tar.bz2 ]]; then
+
if [ -a ${DISTDIR}/${AUTOMAKE}.tar.bz2 ]; then
 
  echo Skipping wget of ${AUTOMAKE}.tar.bz2
 
  echo Skipping wget of ${AUTOMAKE}.tar.bz2
 
else
 
else
 
  wget $WGETOPT ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/${AUTOMAKE}.tar.bz2
 
  wget $WGETOPT ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/${AUTOMAKE}.tar.bz2
 
  # If primary mirror fails, use the alternative mirror.
 
  # If primary mirror fails, use the alternative mirror.
  if [[ -a ${DISTDIR}/${AUTOMAKE}.tar.bz2 ]]; then
+
  if [ -a ${DISTDIR}/${AUTOMAKE}.tar.bz2 ]; then
 
echo "Got ${AUTOMAKE}.tar.bz2"
 
echo "Got ${AUTOMAKE}.tar.bz2"
 
  else
 
  else
 
wget $WGETOPT ftp://ftp.gnu.org/gnu/automake/${AUTOMAKE}.tar.bz2
 
wget $WGETOPT ftp://ftp.gnu.org/gnu/automake/${AUTOMAKE}.tar.bz2
 
# Check to make sure the alternative mirror worked.
 
# Check to make sure the alternative mirror worked.
if [[ -a ${DISTDIR}/${AUTOMAKE}.tar.bz2 ]]; then
+
if [ -a ${DISTDIR}/${AUTOMAKE}.tar.bz2 ]; then
 
echo "Got ${AUTOMAKE}.tar.bz2"
 
echo "Got ${AUTOMAKE}.tar.bz2"
 
else
 
else
Line 147: Line 147:
 
  fi
 
  fi
 
fi
 
fi
if [[ -a ${DISTDIR}/${MPARSE}.tgz ]]; then
+
if [ -a ${DISTDIR}/${MPARSE}.tgz ]; then
 
  echo "Skipping wget of ${MPARSE}.tgz"
 
  echo "Skipping wget of ${MPARSE}.tgz"
 
else
 
else
 
  wget $WGETOPT ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/${MPARSE}.tgz
 
  wget $WGETOPT ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/${MPARSE}.tgz
 
  # If primary mirror fails, use the alternative mirror.
 
  # If primary mirror fails, use the alternative mirror.
  if [[ -a ${DISTDIR}/${MPARSE}.tgz ]]; then
+
  if [ -a ${DISTDIR}/${MPARSE}.tgz ]; then
 
echo "Got ${MPARSE}.tgz"
 
echo "Got ${MPARSE}.tgz"
 
  else
 
  else
 
wget $WGETOPT http://pecl.php.net/get/${MPARSE}.tgz
 
wget $WGETOPT http://pecl.php.net/get/${MPARSE}.tgz
 
# Check to make sure the alternative mirror worked.
 
# Check to make sure the alternative mirror worked.
if [[ -a ${DISTDIR}/${MPARSE}.tgz ]]; then
+
if [ -a ${DISTDIR}/${MPARSE}.tgz ]; then
 
echo "Got ${MPARSE}.tgz"
 
echo "Got ${MPARSE}.tgz"
 
else
 
else
Line 216: Line 216:
  
 
rm -rf $SRCDIR
 
rm -rf $SRCDIR
if [[ ${DISTDEL} == "Yes" ]]; then
+
if [ ${DISTDEL} == "Yes" ]; then
 
rm -rf $DISTDIR
 
rm -rf $DISTDIR
elif [[ ${DISTDEL} == "No" ]]; then
+
elif [ ${DISTDEL} == "No" ]; then
 
echo "Your DISTDIR will not be cleaned."
 
echo "Your DISTDIR will not be cleaned."
 
else
 
else

Revision as of 10:25, 5 October 2007

Introduction to Mailparse

The PECL Mailparse extension is a stream based, resource efficient module for PHP that works to decode RFC 822 and RFC 2045 (MIME-based) compliant messages. The current version of Mailparse works with PHP versions 4.3 to 6.0.

Installing Mailparse

The instructions provided in this article or section are considered advanced.

You are expected to be knowledgeable in the UNIX shell.
Support for these instructions is not available from DreamHost tech support.
Server changes may cause this to break. Be prepared to troubleshoot this yourself if this happens.
We seriously aren't kidding about this.

Please Note: The installation of Mailparse requires Installing_PHP5 or Installing_PHP4 as well as the mbstring extension.
If you are unable to meet this prerequisite, then you may not be able to use the Mailparse module on your DreamHost account.


Below is the install script for the Mailparse PHP module.
Please make sure to run 'dos2unix mailparse.sh' from the shell if you use a Windows-based editor to create this file.

mailparse.sh

#!/bin/sh
set -e

# Version 1.0b, 2007-10-05
#
# - Initial Release (2007-10-05)

#### User Configuration Options
# Temporary source directory
SRCDIR=${HOME}/source
# Download temporary DIST files to which directory?
DISTDIR=${HOME}/dist
# Delete contents of DISTDIR after installation? (Default: Yes)
DISTDEL="Yes"
# Install Mailparse to which directory?
# Note: This *MUST* be set to your PHP5 installation directory!
INSTALLDIR=${HOME}/php5
# Nice Level for Processes. (Depreciated)
# Higher is nicer, lower is less nice and could get your install process killed!
NICE=19

## Program Version Configuration
# Don't touch unless you know what you're doing!
AUTOCONF="autoconf-2.61"
AUTOMAKE="automake-1.10"
MPARSE="mailparse-2.1.1"
# What features do you want enabled?
MPARSEFEATURES="--prefix=${INSTALLDIR}"

#### END User Configuration Options

########## DO NOT MODIFY BELOW ##########
sleep 1s

# Push the install dir's bin directory into the path
export PATH=${INSTALLDIR}/bin:$PATH

# Clear and/or create the source directory.
if [ -d ${SRCDIR} ]; then
		  echo "Source directory already exists! Cleaning it..."
		  rm -rf $SRCDIR/*
else
		  echo "Creating source directory..."
		  mkdir -p ${SRCDIR}
fi
# Create the dist files directory if it doesn't exist
# optionally cleaning it if it does exist already.
if [ -d ${DISTDIR} ]; then
	echo ""; echo "Distribution directory already exists!"; echo "Clean it?"
	if [ ${DISTDEL} == "Yes" ]
	then
		echo ""; echo "Yes!"; echo "Cleaning now..."; echo ""
		rm -rf $DISTDIR/*
	else
		echo ""; echo "No!"; echo "Leaving the distribution directory intact."; echo ""
	fi
else
		  echo "Creating distribution directory..."
		  mkdir -p ${DISTDIR}
fi
# Make sure the extensions directory exists.
if [ -d ${INSTALLDIR}/lib/php/extensions ]; then
		  echo "lib/php/extensions folder already exists! Doing nothing..."
else
		  mkdir -p ${INSTALLDIR}/lib/php/extensions
fi

# Detect how many processors the system has (for more optimal compliation).
cores=2   # the number of cores/procs to use when building
if [ $cores -a $cores -gt 1 ]; then
		  j="-j$cores "
fi
		  OS=`uname -s`
if [ "Darwin" = $OS ]; then
		  sed=gnused
		  makefile=makefile.macosx
else
		  makefile=makefile.linux_x86_ppc_alpha
		  sed=sed
fi

for i in $sed wget; do
		  $i --version >/dev/null 2>&1
done

## Check if packages already exist and get packages the ones that don't.
cd ${DISTDIR}
# Do not abort on errors.
set +e
# Wget options
WGETOPT="-t1 -T10 -w5 -q -c"

# Do some of our own error checking here too.
if [ -a ${DISTDIR}/${AUTOCONF}.tar.gz ]; then
		  echo "Skipping wget of ${AUTOCONF}.tar.gz"
else
		  wget $WGETOPT ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/${AUTOCONF}.tar.gz
		  # If primary mirror fails, use the alternative mirror.
		  if [ -a ${DISTDIR}/${AUTOCONF}.tar.gz ]; then
			echo "Got ${AUTOCONF}.tar.gz"
		  else
				wget $WGETOPT ftp://ftp.gnu.org/gnu/autoconf/${AUTOCONF}.tar.gz
				# Check to make sure the alternative mirror worked.
				if [ -a ${DISTDIR}/${AUTOCONF}.tar.gz ]; then
					echo "Got ${AUTOCONF}.tar.gz"
				else
					echo "Failed to get ${AUTOCONF}.tar.gz. Aborting 

install!"
					exit 0
				fi
		  fi
fi
if [ -a ${DISTDIR}/${AUTOMAKE}.tar.bz2 ]; then
		  echo Skipping wget of ${AUTOMAKE}.tar.bz2
else
		  wget $WGETOPT ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/${AUTOMAKE}.tar.bz2
		  # If primary mirror fails, use the alternative mirror.
		  if [ -a ${DISTDIR}/${AUTOMAKE}.tar.bz2 ]; then
			echo "Got ${AUTOMAKE}.tar.bz2"
		  else
				wget $WGETOPT ftp://ftp.gnu.org/gnu/automake/${AUTOMAKE}.tar.bz2
				# Check to make sure the alternative mirror worked.
				if [ -a ${DISTDIR}/${AUTOMAKE}.tar.bz2 ]; then
					echo "Got ${AUTOMAKE}.tar.bz2"
				else
					echo "Failed to get ${AUTOMAKE}.tar.bz2. Aborting 

install!"
					exit 0
				fi
		  fi
fi
if [ -a ${DISTDIR}/${MPARSE}.tgz ]; then
		  echo "Skipping wget of ${MPARSE}.tgz"
else
		  wget $WGETOPT ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/${MPARSE}.tgz
		  # If primary mirror fails, use the alternative mirror.
		  if [ -a ${DISTDIR}/${MPARSE}.tgz ]; then
			echo "Got ${MPARSE}.tgz"
		  else
				wget $WGETOPT http://pecl.php.net/get/${MPARSE}.tgz
				# Check to make sure the alternative mirror worked.
				if [ -a ${DISTDIR}/${MPARSE}.tgz ]; then
					echo "Got ${MPARSE}.tgz"
				else
					echo "Failed to get ${MPARSE}.tgz. Aborting install!"
					exit 0
				fi
		  fi
fi

set -e

# Extract the source files into the source directory.
cd ${SRCDIR}
echo "Extracting ${AUTOCONF}..."
tar xzf ${DISTDIR}/${AUTOCONF}.tar.gz > /dev/null
echo "Done."
echo "Extracting ${AUTOMAKE}..."
tar xjf ${DISTDIR}/${AUTOMAKE}.tar.bz2 > /dev/null
echo "Done."
echo "Extracting ${MPARSE}..."
tar xzf ${DISTDIR}/${MPARSE}.tgz > /dev/null
echo "Done."

# Required exports
export PATH=${SRCDIR}/bin:$PATH
export PHP_PREFIX=${INSTALLDIR}/bin

## Compile deps and install Mailparse
#AUTOCONF
cd ${SRCDIR}/${AUTOCONF}
./configure --prefix=${SRCDIR}
# make clean
nice -n ${NICE} make
make install

#AUTOMAKE
cd ${SRCDIR}/${AUTOMAKE}
./configure --prefix=${SRCDIR}
# make clean
nice -n ${NICE} make
make install

#Mailparse
cd ${SRCDIR}/${MPARSE}
$PHP_PREFIX/phpize
./configure ${MPARSEFEATURES}
# make clean
nice -n ${NICE} make

# Install Mailparse now by copying the lib file over to the PHP extension dir.
cp modules/mailparse.so ${INSTALLDIR}/lib/php/extensions/mailparse.so
# additional module file just in case...
cp modules/mailparse.la ${INSTALLDIR}/lib/php/extensions/mailparse.la

# Post install clean-up.
sleep 2s
cd ${HOME} && clear

rm -rf $SRCDIR
if [ ${DISTDEL} == "Yes" ]; then
	rm -rf $DISTDIR
elif [ ${DISTDEL} == "No" ]; then
	echo "Your DISTDIR will not be cleaned."
else
	echo "Unknown DISTDEL option! Cleaning your DISTDIR by default."
fi

## End of Install
echo "Installation of Mailparse completed!" `date +%r`

#EOF

php.ini Modifications

Locate the following line(s) in your php.ini file:

; Directory in which the loadable extensions (modules) reside.
extension_dir = "./"

Modify the extension_dir line to look like this, replacing username with the username of your account:

; Directory in which the loadable extensions (modules) reside.
extension_dir = "/home/username/php5/lib/php/extensions"


Now add the following near the very end of your current php.ini file.

[mailparse]
extension="mailparse.so"

External Links

Pecl Mailparse Homepage
Mailparse Functions Manual