App.Models.Message = Backbone.Model.extend({
	defaults: {
		acct: '',
       UID: ''
	},

	initialize: function(attrs,opts){
		this.id = attrs.acct+":"+attrs.UID;
	},

	url: function(){
		return App.baseUrl + '/api/mail/view?folder='+App.email.getCurrentFolder()+'&threadsEnabled=false&acct=' + this.get('acct') + '&uniqueId='+ this.get('UID');
	}

});

App.Models.Message.prototype.emailStrToList = function(addrField){
	var chars, cpos, lastCh, inQuote, addrs;
	
	cpos    = ['0'];
	addrs   = [];
	inQuote = false;
	attrs   = this.get('0');
	chars   = attrs? attrs.headers[addrField] : null;

	if(chars && chars.length){
		_.each(chars, function(ch,i){
			if( ch == '"' && lastCh != "\\" ){
				inQuote = !inQuote;
			}

			if(!inQuote && ch == ','){
				cpos.push(i);
			}

			lastCh = ch;
		});

		_.each(cpos,function(pos,i){
			var end;

			end = cpos[(i+1)] || chars.length;
			pos = parseInt(pos)? (pos+1) : pos;
			addrs.push( chars.substring(pos,end).trim() );
		});
	}
	return addrs;
};
