Local Mail Server for MacOS X Lion

Filed under:Uncategorized — posted by admin on July 24, 2011 @ 5:09 pm

Download the UW IMAP software from http://www.washington.edu/imap/

Connect to ftp://ftp.cac.washington.edu/imap

Login as guest

Copy the file imap-2007f.tar.gz to your Desktop

Expand the archive with

tar zxvf imap-2007f.tar.gz

Fix the makefile. Open imap-2007f/Makefile and comment out line 422 that reads:

        EXTRACFLAGS="$(EXTRACFLAGS) -DMAC_OSX_KLUDGE=1" \

Build the software with:

make oxp SSLDIR=/usr SSLCERTS=/System/Library/OpenSSL/certs

Create a place to store the server:

sudo mkdir -p /usr/local/libexec

Copy the server into place:

sudo mv ipopd/ipop3d /usr/local/libexec

Create a PAM authentication module:

sudo cp /etc/pam.d/ftpd /etc/pam.d/pop

Create a self-signed certificate:

sudo openssl req -new -x509 -nodes -out /System/Library/OpenSSL/certs/ipop3d.pem -keyout /System/Library/OpenSSL/certs/ipop3d.pem -days 3650

Create launchd config files

sudo touch /Library/LaunchDaemons/edu.washington.pop3.plist
sudo vi /Library/LaunchDaemons/edu.washington.pop3.plist

Enter the following content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
 <dict>
 <key>Label</key>
 <string>edu.washington.pop3</string>
 <key>ProgramArguments</key>
 <array>
 <string>/usr/local/libexec/ipop3d</string>
 </array>
 <key>Sockets</key>
 <dict>
 <key>Listeners</key>
 <dict>
 <key>Bonjour</key>
 <false/>
 <key>SockServiceName</key>
 <string>pop3</string>
 <key>SockType</key>
 <string>stream</string>
 </dict>
 </dict>
 <key>inetdCompatibility</key>
 <dict>
 <key>Wait</key>
 <false/>
 </dict>
 </dict>
</plist>

Do the same for /Library/LaunchDaemons/edu.washington.pop3s.plist. changing Label to pop3s and SockServiceName to pop3s

Load the launchd config files:

sudo launchctl unload -w /Library/LaunchDaemons/edu.washington.pop3.plist
sudo launchctl load -w /Library/LaunchDaemons/edu.washington.pop3s.plist

Test your POP server:

openssl s_client -connect localhost:995
CONNECTED(00000003)
depth=0 <certificate stuff…>
emailAddress=<the e-mail address you used for the certificate>
verify error:num=18:self signed certificate
verify return:1
depth=0 <certificate stuff…>
emailAddress=<the e-mail address you used for the certificate>
verify return:1
---
Certificate chain
 0 s:<certificate stuff…>
   i:<certificate stuff…>
---
Server certificate
-----BEGIN CERTIFICATE-----
<certificate content in base64>
-----END CERTIFICATE-----
subject=<certificate stuff…>
emailAddress=<the e-mail address you used for the certificate>
issuer=<certificate stuff…>
emailAddress=<the e-mail address you used for the certificate>
---
No client certificate CA names sent
---
SSL handshake has read 1037 bytes and written 328 bytes
---
New, TLSv1/SSLv3, Cipher is AES256-SHA
Server public key is 1024 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
SSL-Session:
    Protocol  : TLSv1
    Cipher    : AES256-SHA
    Session-ID: <something…>
    Session-ID-ctx: 
    Master-Key: <something else…>
    Key-Arg   : None
    Start Time: 1311510626
    Timeout   : 300 (sec)
    Verify return code: 18 (self signed certificate)
---
+OK POP3 localhost 2007f.104 server ready
user <your short user name>
+OK User name accepted, password please
pass <your login password>
+OK Mailbox open, 5 messages
quit
+OK Sayonara
read:errno=0

Edit the launchd config file for postfix:

sudo vi /System/Library/LaunchDaemons/org.postfix.master.plist 

Add the following:

<key>KeepAlive</key>
<true/>

Remove the following:

<string>-e</string>
<string>60</string>

Restart postfix master:

sudo launchctl unload -w /System/Library/LaunchDaemons/org.postfix.master.plist 
sudo launchctl load -w /System/Library/LaunchDaemons/org.postfix.master.plist 

Test your SMTP server:

telnet <your local host> 25
Trying fec0:0:0:fea9::1...
Connected to <your local host>.
Escape character is '^]'.
220 <your local host> ESMTP Postfix
EHLO <your local host>
250-<your local host>
250-PIPELINING
250-SIZE 10485760
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-DSN
250-BINARYMIME
250 CHUNKING
^]
telnet> quit

Construct a test message:

From: <your short user name>@<your local host>
To:  <your short user name>@<your local host>
Subject: This is a local test
This is a local test of the mail system.

Send your test message:

cat test.txt | sendmail -t

Setup Apple Mail to connect to:

Incoming Mail Server: <your local host>

User Name: <your short user name>

Password: <your login password>

Outgoing Mail Server SMTP: <your local host>

Use only this server: checked

Advanced:

Port: 995

Use SSL checked

Authentication: Password

Check your e-mail in Apple Mail. Accept the certificate. 

 

Local web development on MacOS X Lion

Filed under:MacOS X,UNIX,Web Development — posted by admin on @ 5:00 pm

Lion no longer creates personal web sites by default. To create one manually, enter the following:

mkdir ~/Sites
echo "<html><body><h1>My site works</h1></body></html>" > ~/Sites/index.html.en

PHP is not enabled in Lion. To enable it, do:

sudo vi /etc/apache2/httpd.conf

Uncomment line 111 that reads:

#LoadModule php5_module libexec/apache2/libphp5.so

to

LoadModule php5_module libexec/apache2/libphp5.so

Edit the launchd config file for Apache:

sudo vi /System/Library/LaunchDaemons/org.apache.httpd.plist  

Remove the following:

<string>-D</string>
<string>WEBSHARING_ON</string>

Restart Apache:

sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 
sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist 

To turn on Apache, go to System Preferences > Sharing and enable Web Sharing.

In Safari, navigate to your web site with the following address:

http://<your local host>/

It should say:

It works!

Now try your user home directory:

http://<your local host>/~<your short user name>

It should say:

My site works!

Now try PHP. Create a PHP info file with:

echo "<?php echo phpinfo(); ?>" > ~/Sites/info.php

And test it by entering the following into Safari’s address bar:

http://<your local host>/~<your short user name>/info.php

You should see your PHP configuration information. This will be important for setting up MySQL later.

Download MySQL from http://www.mysql.com/downloads/mysql/. You want the Mac OS X ver. 10.6 (x86, 64-bit), DMG Archive. Open the archive mysql-5.5.14-osx10.6-x86_64.dmg. Install only the mysql-5.5.14-osx10.6-x86_64.pkg package. Ignore everything else.

Create the launchd config file for MySQL:

sudo vi /Library/LaunchDaemons/com.mysql.mysql.plist  

Use the following content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>KeepAlive</key>
    <true/>
    <key>Label</key>
    <string>com.mysql.mysqld</string>
    <key>ProgramArguments</key>
    <array>
    <string>/usr/local/mysql/bin/mysqld_safe</string>
    <string>--user=mysql</string>
    </array>
  </dict>
</plist>

Create a config file for MySQL that matches the Apple PHP build:

sudo vi /etc/my.conf  

Use the following content:

[client]
socket=/var/mysql/mysql.sock
[mysqld]
socket=/var/mysql/mysql.sock

Start MySQL:

sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysql.plist 

Download DBD::mysql from http://search.cpan.org/~capttofu/DBD-mysql-4.019/lib/DBD/mysql.pm

Extract the archive with:

tar zxvf DBD-mysql-4.019.tar.gz

Move into the directory:

cd DBD-mysql-4.019

First, fix the MySQL client library according to instructions in:

http://probably.co.uk/problems-installing-dbdmysql-on-os-x-snow-leopard.html

For Lion, type:

sudo install_name_tool -id /usr/local/mysql-5.5.14-osx10.6-x86_64/lib/libmysqlclient.18.dylib /usr/local/mysql-5.5.14-osx10.6-x86_64/lib/libmysqlclient.18.dylib

Next, build DBD::mysql with:

perl Makefile.PL --mysql_config=/usr/local/mysql/bin/mysql_config --testsocket=/var/mysql/mysql.sock --testuser=root
make
make test
sudo make install

If you want to add modules to PHP, I suggest the following site:

http://michaelgracie.com/2011/07/21/plugging-mcrypt-into-php-on-mac-os-x-lion-10-7/

I can’t explain it any better.

 

Apple Undocumentation

Filed under:MacOS X — posted by admin on December 31, 2009 @ 6:00 pm

This used to be in Apple’s documentation about how to create flat executables (such as command line tools) that have Info.plist data. The information is gone from Apple’s site now. Still, it may be useful:

Putting Info.plist Files in a Flat Executable

Even if your program does not use the bundle structure, it should still include an information property-list file to identify key pieces of information to the system. For unbundled CFM executables, you can place the contents of the program’s Info.plist file in a ‘plst’ resource. For unbundled Mach-O executables, you can create an __info_plist section in the executable’s __TEXT segment and put the contents of your information property-list file there. To create an __info_plist section, you would create an Info.plist file as you would for a bundled program and then add the following linker options to your makefile or Xcode project:

-sectcreate __TEXT __info_plist Info.plist

To retrieve the Info.plist information, your unbundled program can use many of the CFBundle functions for accessing bundle properties. Although your program is not bundled, you can still get the “main bundle” and pass that object to any functions you call.

Update: It looks like it just got moved instead. It is now in the Code Signing Guide.

Debugging Javascript in Safari

Filed under:Web Development — posted by admin on October 1, 2009 @ 10:19 am

When I need this, I use it every day, 38 times a day, for a week. Then I forget about it. No more.

For quick-n-dirty Safari Javascript debugging, try “window.console.log()”.

Hidden tricks in the Xcode editor

Filed under:MacOS X,Perl — posted by admin on June 30, 2009 @ 9:49 am

I’m quite fond of Xcode’s built-in editor. I have no problem with anyone trying to write the Next Great Programmer’s Editor, but the bar is pretty high. I use Xcode for almost all of my programming, including web sites and Perl.

In C, you can use the #pragma mark directive to add a comment to the function listing at the top of the window. In Perl, you can do the same with “TODO:” comments. However, I wanted to see if I could add a mark without having to use “TODO:”. I dug around and found the XcodeEdit private framework and discovered the syntax files for the Xcode editor. Here is the full list of marker codes:

  • TODO:
  • FIXME:
  • !!!:
  • ???:
  • MARK: This one is special. You don’t get the mark, just the text!

Back to work!

Xcode project and file templates

Filed under:MacOS X — posted by admin on June 19, 2009 @ 5:24 pm

I’ve known about Xcode project templates for quite a while. I even wrote a little script once that would take an Xcode project and convert it into a template. All you had to do then was copy it to a magical place in your home directory and you had custom Xcode projects.

Unfortunately, there was no way to setup file templates. If you went to Xcode File -> New File, you would get the Xcode default files.

As of Xcode 3.1.2, there are improvements. You can now specify both project and file templates. Go to /Library/Application Support/Developer/Shared/Xcode. You can create Project Templates and a File Templates directories. Copy your favorite default set from /Developer/Library/Xcode/ and edit the files. Now, just like in New Project, there will be a set of User Templates in the New File dialog box in Xcode. Of course, none of this is documented.

Don’t forget to store your templates somewhere in your home directory and use symbolic links in the system directory. That will help with upgrading.

Thanks to the MacFUSE project for tipping me off.

Paths in MacOS X

Filed under:MacOS X — posted by admin on December 30, 2008 @ 10:22 am

A while back, I installed git to download some random open-source code that I’ve since forgotten about. I noticed this when hacking on my .bash_profile paths to add ImageMagick. I saw that git had been inserted into my path and I couldn’t figure out how. I thought they had been screwing around with my system bash scripts but no – something else was going on…

It seems MacOS X has a little known improvement to UNIX life on the desktop. Instead of adding paths login scripts, you can put them in the /etc/paths.d directory. Add a unique text file whose contents are the path to add. You don’t get control over the order of loading, but that (usually) shouldn’t be a big deal. There is also a /etc/manpaths.d as well.

I normally don’t like to put third party stuff in / directories. That is where things get lost when upgrading. I don’t know if I should use this or not, but I don’t want to forget about it.

MacOS X Application initialization and shutdown sequence

Filed under:MacOS X — posted by admin on December 6, 2008 @ 2:41 pm

Perhaps this is it?

  1. main.m calls the NSApplicationMain function.
  2. init methods of classes in the main nib file
  3. awakeFromNib called on classes instantiated by the nib
  4. [NSApp run]
  5. [NSApp finishLaunching]
  6. Any windows in the nib that were marked as ‘visible at launch time’ are put on screen about now.
  7. applicationWillFinishLaunching:
  8. application:openFile:
  9. applicationDidFinishLaunching:
  10. <run main loop>
  11. applicationShouldTerminate:
  12. reviewUnsavedDocumentsWithAlertTitle:cancellable:delegate:didReviewAllSelector:contextInfo:
  13. closeAllDocumentsWithDelegate:didCloseAllSelector:contextInfo:
  14. <didReviewAllSelector>
  15. applicationWillTerminate:

Updated to add information from this post.

Custom Perl modules

Filed under:Perl — posted by admin on September 19, 2008 @ 5:48 pm

I may need a Perl category here shortly.

Once again, I have had to re-find the following information about doing custom installations of CPAN modules. Here are the details…

$ PERL5LIB=$HOME/lib/perl5/5.8.7:$HOME/lib/perl5/site_perl/5.8.7

$ perl Makefile.PL PREFIX=~/lib

$ make
$ make install

Kill runaway queries in MySQL

Filed under:OSS — posted by admin on @ 8:06 am

OK, this is neither a MacOS X nor a programming item. But I’ve had to look it up twice now. To kill a long-running or runaway MySQL query, follow these instructions:

show processlist;

kill <id>;


next page


image: detail of installation by Bronwyn Lace