Posts

How to Edit Text Configuration Files on OS X Server

Managing OS X Server, quite often requires one to manually edit text based configuration files. As do many of our tutorials and FAQs.

There are many ways of doing this. You can use a Terminal based editor or one with a fancy GUI. What is paramount though, is that you use a Plain Text Editor like TextWrangler, Textastic or BBEdit. Rich Text Editors like Microsoft Word or Pages can severely damage your configuration files. Keeping above in mind, the rest comes down to personal preference.

On OS X I prefer to either use PICO, a Terminal based editor or TextWrangler which has a simple but powerful GUI and good syntax highlighting.

On iOS, PICO – accessed through an SSH session with Prompt – or TextWrangler with its built in SFTP client are my tools of choice.

Whether I use a Terminal based editor or one with a GUI mainly depends on the task at hand. For quick edits of a few lines, PICO works well and is the fastest way to go. If I need to make lots of changes or need a good overview of the file I am editing, a GUI editor is way more comfortable.

Let’s have a quick look at how these work.

Assuming we want to modify Postfix’ main.cf, we would issue:

sudo pico /Library/Server/Mail/Config/postfix/main.cf

And be presented with a view like this:

Now we can use our cursor keys to move around, the backspace key to delete characters or simply type what we need. When we are done editing, we need to save and exit. The commands for this are at the bottom of the window.

In order to save and exit, we would hit CTRL-O (to write the file) and CTRL-X to exit PICO. Alternatively we can just hit CTRL-X and enter y when asked to save.

Have a good look at the available commands as there are more options like cutting text and page scrolling.

While it may need a bit of time to get adjusted to, mastering a Terminal based text editor can be a very useful item in your tool chest.

Using the GUI instead of Terminal

If you don’t like using Terminal, you can always use a Plain Text Editor like TextWrangler which would look something like this

and behave like any other GUI Plain Text Editor.
The choice is yours, just make sure you avoid Rich Text Editors like Microsoft Word or Pages. There are plenty to choose from, like TextWrangler, Textastic, BBEdit, SubEthaEdit, SublimeText and many more. The choice on iOS is equally large.

For this tutorial, let’s look at TextWrangler which is a powerful (yet free) plain text editor

TextWrangler allows you to navigate hidden directories (/etc /Library etc) and edit files even when they are owned by root.

IMPORTANT: Don’t use the App Store version
Due to app store rules, the version from the app store is not able to unlock/edit files.
Download the application directly from the publisher: http://www.barebones.com/products/textwrangler/

These steps walk you through editing a hidden/privileged (root) file. We’ll use /etc/php.ini as our example.

In TextWrangler, use the Open File by Name option in the File menu.
This allows you to simply paste the path/name: /etc/php.ini

OpenByName

Another way to open /etc/php.ini is with the more familiar Open Dialog from TextWrangler.
Be sure to choose the Show Hidden Files option.

open-dialog

ALWAYS backup a file before you make changes
Save a backup to your Desktop using the Save a Copy option from the File menu.
Because the file is owned by root, you’ll need to authenticate.

Screen Shot 2016-02-10 at 11.45.44 AM

We need to be careful editing this file, one out of place character could effect your system.
You did backup first, right ?

Let’s make a safe change.
In the php.ini file, comments start with a semi-colon.
Simply add a space at the end of one of the commented lines:

;;;;;;;;;;;;;;;;;;;
; About php.ini   ;  <<--- add a space at the end of this line
;;;;;;;;;;;;;;;;;;;

When you attempt to edit the file, you’ll be asked to authenticate again.
Once you authenticate, you can edit, then save the file.

That is all there is. Happy editing!

How to copy (bcc) all mail from specific senders to another address

Sender BCC Maps allow you to specify one or more senders along with a bcc_recipient address.
When an incoming or outgoing message matches sender_bcc_maps, the message is BCCd to the specified address

A few examples
  • BCC all mail sent from a fax or copier to a Fax/Copier archive
  • Bob wants all mail he sends from his 3 company addresses copied to his AOL account
  • Audit mail from a specific address

Create the sender_bcc file

Here is how I would create the file using pico.
note: when done editing with pico, hit ctrl-x to exit and y to save

sudo pico /Library/Server/Mail/Config/postfix/sender_bcc

Then you can start entering the following:

# sender-address [space(s)]  bcc-address
sender@example.com    archive@example.com
anothersender@example.com    archive@example.com

Alternatively you can use a plain text editor of your choice.

Run postmap anytime you edit the sender_bcc file

sudo /Applications/Server.app/Contents/ServerRoot/usr/sbin/postmap /Library/Server/Mail/Config/postfix/sender_bcc

Tell postfix where to find your new sender_bcc file then reload postfix

sudo /Applications/Server.app/Contents/ServerRoot/usr/sbin/postconf -e sender_bcc_maps=hash:/Library/Server/Mail/Config/postfix/sender_bcc
sudo /Applications/Server.app/Contents/ServerRoot/usr/sbin/postfix reload

To disable sender_bcc_maps

sudo /Applications/Server.app/Contents/ServerRoot/usr/sbin/postconf -e sender_bcc_maps=
sudo /Applications/Server.app/Contents/ServerRoot/usr/sbin/postfix reload

Why don’t I see X-Spam-Status headers ?

By default, amavisd adds the X-Spam-Status header only when the score is 2.0 or higher.

Edit

/Library/Server/Mail/Config/amavisd/amavisd.conf

and look for

$sa_tag_level_deflt  = 2.0;  # add spam info headers if at, or above that level

You want to see X-Spam-Status headers on all mail, even non-spam – so make it a negative number.

$sa_tag_level_deflt  = -999.0;  # add spam info headers if at, or above that level

Stop amavisd (it will be automatically re-started)

sudo launchctl stop org.amavis.amavisd

MCrypt Installer for OS X Server

Compatibility

  • OS X 10.11.x El Capitan with Server app 5.x (SIP compatible)
  • OS X 10.10.x Yosemite with Server app 4.x or 5.x
  • OS X 10.9.x Mavericks with Server app 3.x
  • OS X 10.8.x Mountain Lion with Server app 2.x

Note: If MCrypt is already installed and loadable by PHP, the installer will exit without making changes.


For both, OS X 10.10 and 10.11 with OS X Server 5

The PHP module installed here:

/usr/local/lib/php/extensions/mcrypt.so

We add/edit the mcrypt module location in /etc/php.ini

extension=/usr/local/lib/php/extensions/mcrypt.so

For OS X 10.8, 10.9 and 10.10 with OS X Server 2-4

PHP modules are installed here:

/usr/lib/php/extensions/no-debug-non-zts-20121212/mcrypt.so
/usr/lib/php/extensions/no-debug-non-zts-20100525/mcrypt.so
/usr/lib/php/extensions/no-debug-non-zts-20090626/mcrypt.so

Your system will use the correct version

We enable the mcrypt module location in /etc/php.ini

extension=mcrypt.so

What is installed and how do I remove files installed by this package.

Please see the Installer FAQ.

The topicdesk Mcrypt installer is a free download.

 

 

AutoCreate/AutoSubscribe and Special-Use IMAP folders

Requirements
  • OS X 10.9.x Mavericks with Server 3.x
  • OS X 10.10.x Yosemite with Server 4.x or 5.x
  • OS X 10.11.x El Capitan with Server 5.x

For this article, we assume you are comfortable editing config files with Terminal or a suitable text editor.

Sever 3.x was the first version of OS X Server to include Dovecot 2.1.

Dovecot 2.1 added several new features, we will cover:

  • How to define folders which are automatically created, and optionally auto subscribed for all imap users.
    This useful feature allows you to define a core set of folders all users should have.
    Obvious examples are folders like Junk and Drafts, but it can be used to create folders for any use.

  • How to define Special-Use folders
    Modern email clients will ask the imap server which folder is preferred for Sent, Trash, Junk and Drafts.
    Defining these Special-Use folders helps keep the user experience consistent and predictable.

Before editing any file, be sure to back it up.

We’ll be working with just this one file:

/Library/Server/Mail/Config/dovecot/conf.d/15-mailboxes.conf

Here is a default copy of the file

##
## Mailbox definitions
##
## Version 2.2.x (AR14759611)

# NOTE: Assumes "namespace inbox" has been defined in 10-mail.conf.
namespace inbox {

  #mailbox name {
    # auto=create will automatically create this mailbox.
    # auto=subscribe will both create and subscribe to the mailbox.
    #auto = no

    # Space separated list of IMAP SPECIAL-USE attributes as specified by
    # RFC 6154: \All \Archive \Drafts \Flagged \Junk \Sent \Trash
    #special_use =
  #}

  # These mailboxes are widely used and could perhaps be created automatically:
  mailbox Drafts {
    special_use = \Drafts
  }
  mailbox Junk {
    special_use = \Junk
  }
  mailbox Trash {
    special_use = \Trash
  }

  # For \Sent mailboxes there are two widely used names. We'll mark both of
  # them as \Sent. User typically deletes one of them if duplicates are created.
  mailbox Sent {
    special_use = \Sent
  }
  mailbox "Sent Messages" {
    special_use = \Sent
  }

  # If you have a virtual "All messages" mailbox:
  #mailbox virtual/All {
  #  special_use = \All
  #}

  # If you have a virtual "Flagged" mailbox:
  #mailbox virtual/Flagged {
  #  special_use = \Flagged
  #}
}

Not much to it – its already commented with clear instructions

Lets look at the definition for Drafts.

mailbox Drafts {
    special_use = \Drafts
  }

If we want Drafts to be auto created, we would add auto=create and to have Drafts created and automatically subscribed instead use auto=subscribe.

This simple change will ensure everyone has a Drafts.

mailbox Drafts {
    auto=create
    special_use = \Drafts
  }

You can add any new folder

mailbox Important {
    auto=create
  }

When done editing, you’ll need to stop/start dovecot to activate the change.

sudo launchctl stop org.dovecot.dovecotd

It will restart automatically.