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(string){
	var chars, cpos, lastCh, inQuote, addrs;
	
	cpos    = ['0'];
	addrs   = [];
	inQuote = false;
	chars   = this.get('0').headers[string];

	_.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;
};
