File/plugins/compatibility/functions.php

Description

NaSMail Compatibility plugin - functions Copyright (c) 2007-2009 The NaSMail Project

This file is part of NaSMail Compatibility plugin.

Compatibility plugin is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

Compatibility plugin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Compatibility plugin; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

  • version: $Id: functions.php 1461 2009-11-03 08:23:27Z tokul $
Constants
NSM_PREF_EMPTY = '' (line 251)

constant introduced in 1.3

Functions
displayMessageHeader (line 603)

Prints page header in pages related to message content display

Function arguments are 100% compatible with displayMessageHeader() arguments. It only turns off use of displayPageHeader() in NSM_LAYOUT_PREVIEW mode. Function MUST be used instead of stardard displayPageHeader, if script displays content related to displayed message. For example: properties of attached files or some actions related to data taken from message viewed in read_body.php. If script uses displayPageHeader() when it must use displayMessageHeader(), display will be broken in NSM_LAYOUT_PREVIEW mode.

  • since: 1.5 (nasmail 1.4+ compat)
void displayMessageHeader (array $color, string $mailbox, [string $xtra = ''], [int $session = false])
  • array $color: color Color theme
  • string $mailbox: mailbox Mailbox name
  • string $xtra: xtra Additional javascript executed onload
  • int $session: session
file_get_contents (line 816)

Provides backwards compatibility for PHP 4.3+ file_get_contents() function.

This function does not support advanced arguments introduced in PHP5/PHP6.

  • since: 1.4
string file_get_contents (string $filename)
  • string $filename
nsm_addslashes (line 402)

PHP addslashes replacement that does not depend on correct magic_quotes_sybase setting.

  • return: escaped text
  • since: 1.3 (nasmail 1.3+ compat)
string nsm_addslashes (string $str)
  • string $str: text that has to be escaped
nsm_auth_delete_password (line 206)

Removes saved password information.

Function must be executed before html output is started.

  • since: 1.1 (nasmail 1.2+ compatibility)
void nsm_auth_delete_password ([integer $flag = 3])
  • integer $flag: 1 - delete password, 2 - delete otp, 3 - delete both
nsm_auth_read_key (line 169)

Reads encrypted pass password

  • return: one time pad
  • since: 1.1 (nasmail 1.2+ compatibility)
string nsm_auth_read_key ()
nsm_auth_read_otp (line 157)

Reads key used to encrypt password

  • return: one time pad
  • since: 1.1 (nasmail 1.2+ compatibility)
string nsm_auth_read_otp ()
nsm_auth_read_password (line 146)

Reads and decodes stored user password information

  • return: password in plain text
  • since: 1.1 (nasmail 1.2+ compatibility)
string nsm_auth_read_password ()
nsm_auth_save_password (line 185)

Saves password Function must be executed before html output is started.

  • return: false on failure, true on success. Please note that in some cases (read only session, blocked cookies) script might report success even when operation fails.
  • since: 1.1 (nasmail 1.2+ compatibility)
boolean nsm_auth_save_password (string $password)
  • string $password: user's password
nsm_check_for_javascript (line 415)

Detects browsers with broken JavaScript support.

This function checks whether the user's USER_AGENT is known to be broken. If broken browser is detected, function returns false.

  • return: false = broken javascript support, true = no known issues
  • since: 1.3 (nasmail 1.3+ compat)
boolean nsm_check_for_javascript ()
nsm_cstrcasecmp (line 355)

Locale insensitive strcasecmp

Function compares two strings in LC_CTYPE=C locale. Arguments and return values are the same as in standard PHP strcasecmp().

  • return: 0 when strings match. negative int, if first string is less that second one. positive int, if first string is greater than second one.
  • link: http://www.php.net/strcasecmp
  • since: 1.2 (nasmail 1.3+ compatibility)
int nsm_cstrcasecmp (string $str1, string $str2)
  • string $str1
  • string $str2
nsm_decode_mod_base64 (line 386)

Decodes modified Base64 encoding

  • return: Decoded text (usually in UTF-16)
  • since: 1.3 (nasmail 1.3+ compat)
string nsm_decode_mod_base64 (string $base64)
  • string $base64: Text in modified base64 encoding
nsm_encode_mod_base64 (line 370)

Encodes string in modified Base64 encoding

  • return: Text in modified Base64
  • since: 1.3 (nasmail 1.3+ compat)
string nsm_encode_mod_base64 (string $utf16)
  • string $utf16: Text (usually in UTF-16)
nsm_fix_session_url (line 137)

Failsafe of NaSMail nsm_fix_session_url function.

Function provides backwards compatibility with NaSMail 1.0 and 1.1. Function differs from the one that is bundled in NaSMail 1.2, because older versions always turn on with session cookies.

  • return: html encoded url.
  • since: 1.1 (nasmail 1.2+ compatibility)
string nsm_fix_session_url (string $url, [boolean $link = true])
  • string $url: URL which needs session id.
  • boolean $link: Is URL html encoded.
nsm_form_check_token (line 739)

Checks form security token

  • since: 1.8 (nasmail 1.7+ compat)
boolean nsm_form_check_token ([string $name = 'input_token'])
  • string $name: form key which stores token value
nsm_form_get_token (line 723)

Returns token which can be used to protect forms from cross site form attacks

  • since: 1.8 (nasmail 1.7+ compat)
string nsm_form_get_token ()
nsm_html2txt (line 261)

Converts HTML to plain text.

  • return: plain text (in utf-8)
  • since: 1.2 (nasmail 1.3+ compatibility)
string nsm_html2txt (string $string, string $input_charset)
  • string $string: HTML text
  • string $input_charset: character set
nsm_http_redirect (line 123)

Function sends HTTP 302 header.

Function provides backwards compatibility with NaSMail 1.0 and 1.1. Function differs from the one that is bundled in NaSMail 1.2, because older versions always turn on with session cookies.

  • since: 1.1 (nasmail 1.2+ compatibility)
void nsm_http_redirect (string $url)
  • string $url: redirection url
nsm_imap_login (line 234)

Logs the user into the IMAP server. If $hide is set, no error messages will be displayed. This function returns the IMAP connection handle.

Function replaces sqimap_login(). $password argument must contain decoded password information.

  • return: IMAP connection resource
  • since: 1.1 (nasmail 1.2+ compatibility)
stream nsm_imap_login (string $username, string $password, string $imap_server_address, integer $imap_port, boolean $hide)
  • string $username: username
  • string $password: plain text password
  • string $imap_server_address: address of IMAP server or mapping ('map:function_name')
  • integer $imap_port: port of IMAP server
  • boolean $hide: hide connection errors
nsm_imap_mailbox_expunge (line 676)

Expunges messages in selected mailbox.

Mailbox must be selected with sqimap_mailbox_select() before issuing the command.

If message UIDs are set and IMAP UIDPLUS extension is supported, function tries to expunge only selected messages.

  • return: Number of expunged messages
  • since: 1.7 (nasmail 1.5+ compat)
integer nsm_imap_mailbox_expunge (stream $imap_stream, [boolean $handle_errors = true], [array $msgs = array()], [boolean $force_expunge = false])
  • stream $imap_stream: IMAP connection resource
  • boolean $handle_errors: Controls internal error handling. Allows to ignore expunge errors, if option is set to false
  • array $msgs: List of message UIDs. Function accepts string values due to sqimap_message_list_squisher() function specifics, but use of strings is deprecated and unsupported.
  • boolean $force_expunge: Force mailbox expunge, if UIDPLUS extension is not supported and code can't expunge only selected message UIDs.
nsm_imap_mailbox_name (line 639)

Returns human readable mailbox name

Function does utf7-imap decoding and applies all rewrites done in scripts.

  • since: 1.6 (nasmail 1.4+ compat)
string nsm_imap_mailbox_name (string $mailbox, [boolean $html_safe = true])
  • string $mailbox: Full IMAP mailbox name
  • boolean $html_safe: Controls html sanitizing of returned data
nsm_page_title (line 540)

Returns standard formated NaSMail page title.

This function should be used after page header is printed with displayPageHeader(). It allows to use same formating style in all NaSMail pages.

Warning. This function returns html tags with open table cell. Scripts must close cell with '</td></tr></table>' after displaying own output.

  • return: html formated page title
  • since: 1.5 (nasmail 1.4+ compat)
string nsm_page_title (string $title, [string $subtitle = ''], [boolean $backlink = false])
  • string $title: Page title
  • string $subtitle: Subtitle
  • boolean $backlink: Prints link to message. Scripts must provide passed_id, startMessage, mailbox and passed_ent_id parameters in GET or POST. passed_id is required. Others are optional, but link might be broken, if startMessage or mailbox are not set correctly.
nsm_process_upload_errors (line 475)

Converts PHP 4.2+ upload error codes to human readable (and translated) string

Function always runs in NaSMail gettext domain. Don't use it to detect upload errors. Function only provides error message _after_ upload error is detected.

  • return: Translated upload error message or empty string
  • since: 1.4 (nasmail 1.4+ compat)
string nsm_process_upload_errors (string $fieldname)
  • string $fieldname: name of attachment field
nsm_setint_u32 (line 616)

Makes sure that number is 32bit unsigned integer

Primary function use - sanitizing of passed_id value.

  • return: Unsigned 32bit integer. Some values are not actually evaluated as integers by PHP. If argument is not unsigned 32bit integer, function returns 0.
  • since: 1.6 (nasmail 1.4+ compat)
float nsm_setint_u32 (mixed $number)
  • mixed $number: Value that must be represented as unsigned 32bit integer
nsm_str_pad (line 450)

Multibyte aware string padding

Currently code allows only ascii symbols in $pad_string. If pad is not in ascii, code won't be able to calculate correct pad string.

  • return: Padded string
  • since: 1.4 (nasmail 1.4+ compat)
string nsm_str_pad (string $input, int $pad_length, [string $pad_string = ' '], [int $pad_type = STR_PAD_RIGHT], [string $charset = 'utf-8'])
  • string $input: text
  • int $pad_length
  • string $pad_string: String used for padding
  • int $pad_type: Padding type. PHP STR_PAD_RIGHT,STR_PAD_LEFT,STR_PAD_BOTH constants.
  • string $charset: Input character set
scandir (line 793)

Provides backwards compatibility with PHP5 scandir() function

Function was originally written for SquirrelMail gpg plugin

array scandir (string $dirstr)
  • string $dirstr
soupNazi (line 432)

Checks for browsers with broken JavaScript support.

Obsolate function.

  • return: 1 = browser is broken. 0 = no known JavaScript issues
  • deprecated: Use nsm_check_for_javascript()
  • since: 1.3 (nasmail 1.0-1.3 compat)
int soupNazi ()
sq_strpos (line 83)

Wrapper that is used to switch between vanilla and multibyte strpos functions.

string sq_strpos (string $haystack, mixed $needle, integer $offset, [string $charset = 'utf-8'])
  • string $haystack
  • mixed $needle
  • integer $offset
  • string $charset
sq_substr (line 48)

Wrapper that is used to switch between vanilla and multibyte substr functions.

string sq_substr (string $string, integer $start, integer $length, [string $charset = 'utf-8'])
  • string $string
  • integer $start
  • integer $length
  • string $charset
stream_get_contents (line 771)

Provides compatibility with PHP5+ stream_get_contents() for PHP4

string stream_get_contents (resource $handle)
  • resource $handle

Documentation generated on Sun, 22 Nov 2009 17:36:29 +0200 by phpDocumentor 1.4.3