boxspring.js
function(name, value, iType) {
			var type = iType
			, coded
			, attach = {
				'_attachments': this.get('_attachments') || {}
			}
			, types = {
				"html": {"content_type":"text\/html"},
				"text": {"content_type":"text\/plain"},
				"xml": {"content_type":"text\/plain"},
				"jpeg": {"content_type":"image\/jpeg"},
				"png": {"content_type":"image\/png"}
			}
			// base64 chokes on charCodes > 255
			, filterCharCodes = function(s) {
				// replace newlines and carriage returns with a space. then filter the non-ascii
				return _.reduce(s.replace(/\n/g, ' ').replace(/\r/g, ' '), function(result, x, i) {
					if (s.charCodeAt(i) < 256) {
						result += s[i];
					}
					return result;
				}, '');
			};;

			// as a prelude to a 'read', the second argument is the 'type'
			if (arguments.length === 2) {
				this.options.set('Content-Type', (types && types[value] &&
						types[value].content_type) || 'text\/plain');
			} else if (arguments.length === 3) {
				type = (types && types[type]) ? type : 'xml';
				types[type].data = _.encode(filterCharCodes(value));
				attach._attachments[name] = types[type];
			}

			this.set('_attachments', attach._attachments);
			return this;
		}
function(name, value, iType) {
			var type = iType
			, coded
			, attach = {
				'_attachments': this.get('_attachments') || {}
			}
			, types = {
				"html": {"content_type":"text\/html"},
				"text": {"content_type":"text\/plain"},
				"xml": {"content_type":"text\/plain"},
				"jpeg": {"content_type":"image\/jpeg"},
				"png": {"content_type":"image\/png"}
			}
			// base64 chokes on charCodes > 255
			, filterCharCodes = function(s) {
				// replace newlines and carriage returns with a space. then filter the non-ascii
				return _.reduce(s.replace(/\n/g, ' ').replace(/\r/g, ' '), function(result, x, i) {
					if (s.charCodeAt(i) < 256) {
						result += s[i];
					}
					return result;
				}, '');
			};;

			// as a prelude to a 'read', the second argument is the 'type'
			if (arguments.length === 2) {
				this.options.set('Content-Type', (types && types[value] &&
						types[value].content_type) || 'text\/plain');
			} else if (arguments.length === 3) {
				type = (types && types[type]) ? type : 'xml';
				types[type].data = _.encode(filterCharCodes(value));
				attach._attachments[name] = types[type];
			}

			this.set('_attachments', attach._attachments);
			return this;
		}
function ( name , value , iType ) { var type = iType , coded , attach = { '_attachments' : this . get ( '_attachments' ) || { } } , types = { "html" : { "content_type" : "text\/html" } , "text" : { "content_type" : "text\/plain" } , "xml" : { "content_type" : "text\/plain" } , "jpeg" : { "content_type" : "image\/jpeg" } , "png" : { "content_type" : "image\/png" } } // base64 chokes on charCodes > 255 , filterCharCodes = function ( s ) { // replace newlines and carriage returns with a space. then filter the non-ascii return _ . reduce ( s . replace ( / \n / g , ' ' ) . replace ( / \r / g , ' ' ) , function ( result , x , i ) { if ( s . charCodeAt ( i ) < 256 ) { result += s [ i ] ; } return result ; } , '' ) ; } ; ; // as a prelude to a 'read', the second argument is the 'type' if ( arguments . length === 2 ) { this . options . set ( 'Content-Type' , ( types && types [ value ] && types [ value ] . content_type ) || 'text\/plain' ) ; } else if ( arguments . length === 3 ) { type = ( types && types [ type ] ) ? type : 'xml' ; types [ type ] . data = _ . encode ( filterCharCodes ( value ) ) ; attach . _attachments [ name ] = types [ type ] ; } this . set ( '_attachments' , attach . _attachments ) ; return this ; }
configure the URL for an attachment
configure the URL for an attachment