<?xml version="1.0" encoding="UTF-8"?>
<Export generator="Cache" version="25" zv="Cache for Windows (x86-64) 2014.1.4 (Build 803U)" ts="2015-08-19 13:36:27">
<Routine name="%CSMEN080CSW" type="MAC" languagemode="0" timestamp="63783,35646.424686"><![CDATA[
%CSMEN080CSW	; 07/2009 - ROTINA DE CONFIGURACAO
vrm	do New^%CSW1UTI("%VRM") new %VRM set %VRM="0.0.0" if $$FE^%CSUTIVR("%CSzzz") set %VRM=$$ver^%CSzzz
	;
0000	do New^%CSW1UTI("%PRG,%TR,sc,TABESN,TABIDE,TABEMP,TABEST,%CSMENCF,%CSMENCFA,CONFIR,%SMConf,ARQFTP,ARQUIVO")
	new %PRG,%TR,sc,TABESN,TABIDE,TABEMP,TABEST,%CSMENCF,%CSMENCFA,CONFIR,%SMConf,ARQFTP,ARQUIVO
	do New^%CSW1UTI("WIN,CAMIHNO,FLGFOCUS,TBCLOC,ATU,SN,VERSAO,TABTIPREL,MACADDRESS,TABFLO,TABSEGCON")
	new WIN,CAMIHNO,FLGFOCUS,TBCLOC,ATU,SN,VERSAO,TABTIPREL,MACADDRESS,TABFLO,TABSEGCON
	;
	set %PRG="%CSMEN080CSW"
	;
	set sc=$$ObterTabSimNao^%CSW1E(.TABESN)
	set sc=$$VerIdentificacaoEmpresa^%CSMEN080RG(.TABIDE)
	set sc=$$RetEmpresa^%CSMEN080RG(.TABEMP)
	set sc=$$VerTipoEnvioRelEmail^%CSMEN080RG(.TABTIPREL)
	set sc=$$ObterTabelaControleLock^%CSMEN080RG(.TBCLOC,2)
	set sc=$$ObterTabelaModeloFloat^%CSMEN080RG(.TABFLO)
	set sc=$$VerTipoSegurancaConexao^%CSMEN080RG(.TABSEGCON)
	;
	set sc=##class(Src2.Utils2).ObterDadosServidor(.MACADDRESS)
	;
	do FieldDisplayValue^%CSW1D("Csmen.Configuracao","estilo",.TABEST)
	set CT=%index
	;
	; verifica acesso
	;
0010	do AC^%CSUTIUD
	do AC^%CSW1UTI("0010AC1^%CSMEN080CSW")
	quit:$$CSP^%CSW1UTI()
0010AC1	if %'=13 do  quit
	. do FJ^%CSW1UTI
	;
	; csw:aj:90,25,Configuração Geral do Sistema
	do AJ^%CSUTIUD(78,24,"Configuração Geral do Sistema")
	;
	;set sc=$$LockConfiguracao^%CSMENRG000()
	;if sc'=1 do ME^%CSUTICSP(sc) goto 9999
	;
	set sc=$$CriarAbas^%CSMEN080RG(CE)
	;
0500	do 9000
	;
	set sc=$$VerConfGeral^%CSMENRG005(.%CSMENCF)
	set %CSMENCFA=%CSMENCF
	;
	set %SMConf("Indef")=$get(^%SMConf("System","Indef"),0)
	set:%SMConf("Indef")="" %SMConf("Indef")=0
	set %SMConf("DispTelnet")=$get(^%SMConf("System","DispTelnet"),0)
	set %SMConf("TestaNetTerm")=$get(^%SMConf("System","TestaNetTerm"),0)
	;
	set CONFIR=$piece(%CSMENCF,Z,17)
	;
	if $piece(%CSMENCF,Z,13)="" do
	. if $$NOMEHOS^%CSUTIUD()="UNIX" set $piece(%CSMENCF,Z,13)=1 quit
	. set $piece(%CSMENCF,Z,13)=2
	;
	do CarregarGrid^%CSW1C("%CSMEN080TAB7",71,1)
	;
	do selecionarTab^%CSW1A("sheat1",1)
	;
	quit
	;
	; Confirma
	;
3000	if '$$Validate() quit:$$CSP^%CSW1UTI()
	;
	if '$$validateTab^%CSW1A("sheat1",1) quit
	if '$$validateTab^%CSW1A("sheat1",2) quit
	if '$$validateTab^%CSW1A("sheat1",3) quit
	if '$$validateTab^%CSW1A("sheat1",4) quit
	if '$$validateTab^%CSW1A("sheat1",5) quit
	;if '$$validateTab^%CSW1A("sheat1",6) quit
	if '$$validateTab^%CSW1A("sheat1",7) quit
	if '$$validateTab^%CSW1A("sheat1",8) quit
	;
	set $piece(%CSMENCF,Z,4)=1
	set $piece(%CSMENCF,Z,7)=1
	set $piece(%CSMENCF,Z,16)=1
	set $piece(%CSMENCF,Z,19)=0
	set $piece(%CSMENCF,Z,38)=""
	set $piece(%CSMENCF,Z,39)=""
	set $piece(%CSMENCF,Z,40)=0
	;
	set sc=$$Salvar^%CSMEN080RG(CE,.%SMConf,%CSMENCF)
	if sc=1 do MECABECALHO^%CSW1UTI()
	;
	quit
	;
	; Tela
	;
9000	do BtnManter^%CSW1D(2)
	quit
	;
9100	do BtnManter^%CSW1D(0)
	quit
	;
	; fim
	;
9999	do removerTabPanel^%CSW1A("sheat1")
	;
	set sc=$$Finalizar^%CSW1GRID(CT,"%CSMEN080TAB7",71)
	;
	set sc=$$UnLockConfiguracao^%CSMENRG000()
	;
	do FJ^%CSUTIUD
	do FJ^%CSW1UTI
	quit
	;
Validate()	;
	quit 1
	;
	; Metodo Show
	;
Show(%cswP1,%cswP2,%cswP3,%cswP4)	;
	do Show^%CSW1UTI("%CSMEN080CSW",$get(%cswP1),$get(%cswP2),$get(%cswP3),$get(%cswP4))
	quit
	;
	; csw:btnManter:1,24.4,3000^%CSMEN080CSW,0500^%CSMEN080CSW
	;
	; csw:labelcreate:%CSMEN080CSW
	; csw:labeldestroy:9999
	; csw:csp:gerar
]]></Routine>


<Routine name="%CSMEN080D" type="MAC" languagemode="0" timestamp="63783,38910.641126"><![CDATA[
%CSMEN080D	; 04/2006 - CONFIGURACAO E - MAIL
vrm	do New^%CSW1UTI("%VRM") new %VRM set %VRM="0.0.0" if $$FE^%CSUTIVR("%CSzzz") set %VRM=$$ver^%CSzzz
	;
	#include %CSUTICSP
	;
0000	do New^%CSW1UTI("%CSMENCF,%CSMENCFA,%PRG,%TR,SN,TABSEGCON")
	new %CSMENCF,%CSMENCFA,%PRG,%TR,SN,TABSEGCON
	set %PRG="%CSMEN080D"
	;
	if $$CSP^%CSW1UTI() do ME^%CSUTIUD("Rotina desabilitada! Favor utilizar a rotina %CSMEN080.") do FJ^%CSW1UTI quit
	;
	set sc=$$VerTipoSegurancaConexao^%CSMEN080RG(.TABSEGCON)
	;
	; verifica acesso
	;
0500	do AC^%CSUTIUD
	do AC^%CSW1UTI("0500AC1^%CSMEN080D")
	quit:$$CSP^%CSW1UTI()
0500AC1	if %'=13 do  quit
	. do FJ^%CSW1UTI
	;
	write /smnr
	; csw:aj:78,15,Configuração E-mail
	do AJ^%CSUTIUD(78,18,"Configuração E-mail"),9000
	set (%CSMENCF,%CSMENCFA)=$get(^%CSMENCF)
	do 8000
	if $$$IfLock("+","^%CSMENCF",0)
	else  do  goto 9999
	. do ME^%CSUTIUD("Configuração aberta em outro terminal")
	;
	; E-mail do Administrador
	;
1000	;
1000ON	do ^%CSLE(2,32,45,"$P(%CSMENCF,Z,25)",$piece(%CSMENCF,Z,25),,,,",,1,cp1000,26,,,,,,1,1",",1")
	quit:$$CSP^%CSW1UTI()
1000EX	goto 9999:%=27!(%=140)
	if '$$Valcp1000() goto 1000
	;
	; Enviar E-mail em caso erro
	;
1100	;
1100ON	do ^%CSLE(3,32,1,"$P(%CSMENCF,Z,35)",$piece(%CSMENCF,Z,35),,",5,6",,",SIMNAO^%CSMEN299,2,cp1100,26,,,,,,1,1",",1")
	quit:$$CSP^%CSW1UTI()
1100EX	goto 9999:%=27,1000:%=140
	if '$$Valcp1100() goto 1100
	write /smp(33,3),/smw($select($piece(%CSMENCF,Z,35)=1:"Sim",1:"Nao")),/sme
	;
	; E-mail do Copia
	;
1200	;
1200ON	do ^%CSLE(4,32,45,"$P(%CSMENCF,Z,26)",$piece(%CSMENCF,Z,26),,,,",,3,cp1200,26,,,,,,1,1",",1")
	quit:$$CSP^%CSW1UTI()
1200EX	goto 9999:%=27,1100:%=140
	if '$$Valcp1200() goto 1200
	;
	; Enviar E-mail em caso erro
	;
1300	;
1300ON	do ^%CSLE(5,32,1,"$P(%CSMENCF,Z,36)",$piece(%CSMENCF,Z,36),"",",5,6",,",SIMNAO^%CSMEN299,4,cp1300,26,,,,,,1,1",",1")
	quit:$$CSP^%CSW1UTI()
1300EX	goto 9999:%=27,1200:%=140
	if '$$Valcp1300() goto 1300
	write /smp(33,5),/smw($select($piece(%CSMENCF,Z,36)=1:"Sim",1:"Nao")),/sme
	;
	; E-mail do Resposta
	;
1400	;
1400ON	do ^%CSLE(6,32,45,"$P(%CSMENCF,Z,24)",$piece(%CSMENCF,Z,24),,,,",,5,cp1400,26,,,,,,1,1",",1")
	quit:$$CSP^%CSW1UTI()
1400EX	goto 9999:%=27,1300:%=140
	if '$$Valcp1400() goto 1400
	;
	; Endereco IP do servidor POP3
	;
1500	;
1500ON	do ^%CSLE(7,32,30,"$P(%CSMENCF,Z,29)",$piece(%CSMENCF,Z,29),,,,",,6,cp1500,26,,,,,,1,1")
	quit:$$CSP^%CSW1UTI()
1500EX	goto 9999:%=27,1400:%=140
	if '$$Valcp1500() goto 1500
	;
	; Porta POP3
	;
1600	;
1600ON	do ^%CSLE(7,73,4,"$P(%CSMENCF,Z,27)",$piece(%CSMENCF,Z,27),,,,",,7,cp1600,67,,,,,,1,1")
	quit:$$CSP^%CSW1UTI()
1600EX	goto 9999:%=27,1500:%=140
	if '$$Valcp1600() goto 1600
	;
	; Endereco IP do servidor SMTP
	;
1700	;
1700ON	do ^%CSLE(8,32,30,"$P(%CSMENCF,Z,30)",$piece(%CSMENCF,Z,30),,,,",,8,cp1700,26,,,,,,1,1")
	quit:$$CSP^%CSW1UTI()
1700EX	goto 9999:%=27,1600:%=140
	if '$$Valcp1700() goto 1700
	;
	; Porta SMTP
	;
1800	;
1800ON	do ^%CSLE(8,73,4,"$P(%CSMENCF,Z,28)",$piece(%CSMENCF,Z,28),,,,",,9,cp1800,67,,,,,,1,1")
	quit:$$CSP^%CSW1UTI()
1800EX	goto 9999:%=27,1700:%=140
	if '$$Valcp1800() goto 1800
	;
	; Porta POP3
	;
1900	;
1900ON	do ^%CSLE(9,32,4,"$P(%CSMENCF,Z,31)",$piece(%CSMENCF,Z,31),,,,",,10,cp1900,26,,,,,,1,1")
	quit:$$CSP^%CSW1UTI()
1900EX	goto 9999:%=27,1800:%=140
	if '$$Valcp1900() goto 1900
	;
	; Diretorio temporario
	;
2000	;
2000ON	do ^%CSLE(10,32,45,"$P(%CSMENCF,Z,32)",$piece(%CSMENCF,Z,32),,,,",,11,cp2000,26,,,,,,1,1")
	quit:$$CSP^%CSW1UTI()
2000EX	goto 9999:%=27,1900:%=140
	if '$$Valcp2000() goto 2000
	;
	; Usuario para SMTP
	;
2100	;
2100ON	do ^%CSLE(11,32,35,"$P(%CSMENCF,Z,33)",$piece(%CSMENCF,Z,33),,,,",,12,cp2100,26,,,,,,1,1",",1")
	quit:$$CSP^%CSW1UTI()
2100EX	goto 9999:%=27,2000:%=140
	if '$$Valcp2100() goto 2100
	;
	; Senha para SMTP
	;
2200	;
2200ON	do ^%CSLE(12,32,20,"$P(%CSMENCF,Z,34)",$piece(%CSMENCF,Z,34),,,,",,13,cp2200,26,,,,,,1,1",",1,,,,,1")
	quit:$$CSP^%CSW1UTI()
2200EX	goto 9999:%=27,2100:%=140
	if '$$Valcp2200() goto 2200
	;
	; Cabeçalho do email de erro
	;
2300	;
2300ON	do ^%CSLE(13,32,45,"$P(%CSMENCF,Z,37)",$piece(%CSMENCF,Z,37),,,,",,14,cp2300,26,,,,,,1,1",",1")
	quit:$$CSP^%CSW1UTI()
2300EX	goto 9999:%=27,2200:%=140
	if '$$Valcp2300() goto 2300
	;
	; Anexar Imagem CSW
	;
2400	;
2400ON	do ^%CSLE(14,32,1,"$P(%CSMENCF,Z,61)",$piece(%CSMENCF,Z,61),,",5,6",,",SIMNAO^%CSMEN299,15,cp2400,26,,,,,,1,1",",1")
	quit:$$CSP^%CSW1UTI()
2400EX	goto 9999:%=27,2300:%=140
	if '$$Valcp2400() goto 2400
	write /smp(33,14),/smw($select($piece(%CSMENCF,Z,61)=1:"Sim",1:"Nao")),/sme
	;
	; Identificacao da empresa
2500	;
2500ON	do ^%CSLE(15,32,1,"$P(%CSMENCF,Z,71)",$piece(%CSMENCF,Z,71),"""01""'[@","1",,",TIPENVREL^%CSMEN080RG,16,cp2500,,,10",",1",,,,1,.TABTIPREL)
	quit:$$CSP^%CSW1UTI()
2500EX	goto 9999:%=27,2400:%=140
	write /smp(33,15),/smw($select($piece(%CSMENCF,Z,71)=1:"Local",1:"Servidor")),/sme
	if '$$Valcp2500() goto 2500
	;
	; Segurança da Conexão
	;
2600	;
2600ON	do ^%CSLE(16,32,1,"$P(%CSMENCF,Z,77)",$piece(%CSMENCF,Z,77),"""0123""'[@","1",,",SegurancaConexao^%CSMEN080RG,17,cp2600,26,,,,,,1,1",",1")
	quit:$$CSP^%CSW1UTI()
2600EX	goto 9999:%=27,2500:%=140
	if '$$Valcp2600() goto 2600
	write /smp(33,16),/smw($piece(%CSMENCF,Z,77)_" - "_TABSEGCON($piece(%CSMENCF,Z,77))),/sme
	;
	; Confirma
	;
3000	goto 9999:%CSMENCF=%CSMENCFA
	do SN^%CSUTIUD(,,,,,"3000SN1^%CSMEN080D")
	quit:$$CSP^%CSW1UTI()
3000SN1	goto 9999:%=27,2600:%=140
	if SN="S" do  goto 9999
	. set ^%CSMENCF=%CSMENCF
	. if $data(^%CSTR0(CE,"%CSMENCF")) do
	. . set sc=$$LockCSMV^%CSUTICSP(CE)
	. . do ^%CSMV001($select(%CSMENCFA'="":2,1:1),"%CSMENCF","",%CSMENCF)
	. . set sc=$$UnLockCSMV^%CSUTICSP(CE)
	goto 2500
	;
	; Mostra dados
	;
8000	;
	do Set^%CSW1UTI(%PRG,"cp1000",$piece(%CSMENCF,Z,25),)
	do Set^%CSW1UTI(%PRG,"cp1100",$piece(%CSMENCF,Z,35),"01")
	do Set^%CSW1UTI(%PRG,"cp1200",$piece(%CSMENCF,Z,26),)
	do Set^%CSW1UTI(%PRG,"cp1300",$piece(%CSMENCF,Z,36),"01")
	do Set^%CSW1UTI(%PRG,"cp1400",$piece(%CSMENCF,Z,24),)
	do Set^%CSW1UTI(%PRG,"cp1500",$piece(%CSMENCF,Z,29),)
	do Set^%CSW1UTI(%PRG,"cp1600",$piece(%CSMENCF,Z,27),)
	do Set^%CSW1UTI(%PRG,"cp1700",$piece(%CSMENCF,Z,30),)
	do Set^%CSW1UTI(%PRG,"cp1800",$piece(%CSMENCF,Z,28),)
	do Set^%CSW1UTI(%PRG,"cp1900",$piece(%CSMENCF,Z,31),)
	do Set^%CSW1UTI(%PRG,"cp2000",$piece(%CSMENCF,Z,32),)
	do Set^%CSW1UTI(%PRG,"cp2100",$piece(%CSMENCF,Z,33),)
	do Set^%CSW1UTI(%PRG,"cp2200",$piece(%CSMENCF,Z,34),)
	do Set^%CSW1UTI(%PRG,"cp2300",$piece(%CSMENCF,Z,37),)
	do Set^%CSW1UTI(%PRG,"cp2400",$piece(%CSMENCF,Z,61),)
	do Set^%CSW1UTI(%PRG,"cp2500",$piece(%CSMENCF,Z,71),)
	do Set^%CSW1UTI(%PRG,"cp2600",$piece(%CSMENCF,Z,77),)
	;
	write /smp(33,2),/smw($piece(%CSMENCF,Z,25))
	write /smp(33,3),/smw($select($piece(%CSMENCF,Z,35)=1:"Sim",1:"Nao"))
	write /smp(33,4),/smw($piece(%CSMENCF,Z,26))
	write /smp(33,5),/smw($select($piece(%CSMENCF,Z,36)=1:"Sim",1:"Nao"))
	write /smp(33,6),/smw($piece(%CSMENCF,Z,24))
	write /smp(33,7),/smw($piece(%CSMENCF,Z,29))
	write /smp(74,7),/smw($piece(%CSMENCF,Z,27))
	write /smp(33,8),/smw($piece(%CSMENCF,Z,30))
	write /smp(74,8),/smw($piece(%CSMENCF,Z,28))
	write /smp(33,9),/smw($piece(%CSMENCF,Z,31))
	write /smp(33,10),/smw($piece(%CSMENCF,Z,32))
	write /smp(33,11),/smw($piece(%CSMENCF,Z,33))
	//write /smp(33,12),/smw($piece(%CSMENCF,Z,34))
	write /smp(33,13),/smw($piece(%CSMENCF,Z,37))
	write /smp(33,14),/smw($select($piece(%CSMENCF,Z,61)=1:"Sim",1:"Nao")),/sme
	write /smp(33,15),/smw($select($piece(%CSMENCF,Z,71)=1:"Local",1:"Servidor")),/sme
	write /smp(33,16),/smw(+$piece(%CSMENCF,Z,77)_" - "_TABSEGCON(+$piece(%CSMENCF,Z,77))),/sme
	quit
	;
	; Tela
	;
9000	if $$CSP^%CSW1UTI() do  quit
	. do Clear^%CSW1UTI()
	write /smc(0)
	write /smp(2,2),/smw("Endereco do Administrador(TO):"),/sme
	write /smlf,/smw(" Enviar E-mail em caso erro...:"),/sme
	write /smlf,/smw(" Endereco para copia (CC).....:"),/sme
	write /smlf,/smw(" Enviar E-mail em caso erro...:"),/sme
	write /smlf,/smw(" Endereco de Resposta.........:"),/sme
	write /smlf,/smw(" Endereco IP do servidor POP3.:"),/sme
	write /smtab(65),/smw("Porta.:"),/sme
	write /smlf,/smw(" Endereco IP do servidor SMTP.:"),/sme
	write /smtab(65),/smw("Porta.:"),/sme
	write /smlf,/smw(" Time-Out Conexao (segundos)..:"),/sme
	write /smlf,/smw(" Diretorio Temporario.........:"),/sme
	write /smlf,/smw(" Usuario SMTP.................:"),/sme
	write /smlf,/smw(" Senha SMTP...................:"),/sme
	write /smlf,/smw(" Cabecalho do E-mail de Erro..:"),/sme
	write /smlf,/smw(" Anexar Imagem CSW............:"),/sme
	write /smlf,/smw(" Tipo envio relatorio e-mail..:"),/sme
	write /smlf,/smw(" Seguranca da Conexao.........:"),/sme
	write /smlf,/smw(%TR),/sme
	write /smc(1)
	quit
	;
	; Fim
	;
9999	do $$$DoLock("-","^%CSMENCF")
	do FJ^%CSUTIUD
	do FJ^%CSW1UTI
	quit
	;
	; Metodo Valcp1000()
	;
Valcp1000()	;
	quit $$$OK
	;
	; Metodo Valcp1100()
	;
Valcp1100()	;
	quit $$$OK
	;
	; Metodo Valcp1200()
	;
Valcp1200()	;
	quit $$$OK
	;
	; Metodo Valcp1300()
	;
Valcp1300()	;
	quit $$$OK
	;
	; Metodo Valcp1400()
	;
Valcp1400()	;
	quit $$$OK
	;
	; Metodo Valcp1500()
	;
Valcp1500()	;
	quit $$$OK
	;
	; Metodo Valcp1600()
	;
Valcp1600()	;
	quit $$$OK
	;
	; Metodo Valcp1700()
	;
Valcp1700()	;
	quit $$$OK
	;
	; Metodo Valcp1800()
	;
Valcp1800()	;
	quit $$$OK
	;
	; Metodo Valcp1900()
	;
Valcp1900()	;
	quit $$$OK
	;
	; Metodo Valcp2000()
	;
Valcp2000()	;
	quit $$$OK
	;
	; Metodo Valcp2100()
	;
Valcp2100()	;
	quit $$$OK
	;
	; Metodo Valcp2200()
	;
Valcp2200()	;
	quit $$$OK
	;
	; Metodo Valcp2300()
	;
Valcp2300()	;
	quit $$$OK
	;
	; Metodo Valcp2400()
	;
Valcp2400()	;
	quit $$$OK
	;
	; Metodo Valcp2500()
	;
Valcp2500()	;
	if $piece(%CSMENCF,Z,71)="" do ME^%CSUTIUD("Tipo de envio de relatório por e-mail: Campo obrigatório!") quit 0
	if $piece(%CSMENCF,Z,71)'="","01"'[$piece(%CSMENCF,Z,71) do ME^%CSUTIUD("Tipo de envio de relatório por e-mail: Valor inválido! ("_$piece(%CSMENCF,Z,71)_")") quit 0
	quit $$$OK
	;
	; Metodo Valcp2600()
	;
Valcp2600()	;
	quit $$$OK
	;
	; Metodo Validate()
	;
Validate()	;
	quit:'$$CSP^%CSW1UTI() 1
	if '$$Valcp1000() do Focus^%CSW1UTI(%PRG,"cp1000") quit 0
	if '$$Valcp1100() do Focus^%CSW1UTI(%PRG,"cp1100") quit 0
	if '$$Valcp1200() do Focus^%CSW1UTI(%PRG,"cp1200") quit 0
	if '$$Valcp1300() do Focus^%CSW1UTI(%PRG,"cp1300") quit 0
	if '$$Valcp1400() do Focus^%CSW1UTI(%PRG,"cp1400") quit 0
	if '$$Valcp1500() do Focus^%CSW1UTI(%PRG,"cp1500") quit 0
	if '$$Valcp1600() do Focus^%CSW1UTI(%PRG,"cp1600") quit 0
	if '$$Valcp1700() do Focus^%CSW1UTI(%PRG,"cp1700") quit 0
	if '$$Valcp1800() do Focus^%CSW1UTI(%PRG,"cp1800") quit 0
	if '$$Valcp1900() do Focus^%CSW1UTI(%PRG,"cp1900") quit 0
	if '$$Valcp2000() do Focus^%CSW1UTI(%PRG,"cp2000") quit 0
	if '$$Valcp2100() do Focus^%CSW1UTI(%PRG,"cp2100") quit 0
	if '$$Valcp2200() do Focus^%CSW1UTI(%PRG,"cp2200") quit 0
	if '$$Valcp2300() do Focus^%CSW1UTI(%PRG,"cp2300") quit 0
	if '$$Valcp2400() do Focus^%CSW1UTI(%PRG,"cp2400") quit 0
	if '$$Valcp2500() do Focus^%CSW1UTI(%PRG,"cp2500") quit 0
	if '$$Valcp2600() do Focus^%CSW1UTI(%PRG,"cp2600") quit 0
	quit $$$OK
	;
	; Metodo Show
	;
Show(%cswP1,%cswP2,%cswP3,%cswP4)	;
	do Show^%CSW1UTI("%CSMEN080D",$get(%cswP1),$get(%cswP2),$get(%cswP3),$get(%cswP4))
	quit
	;
	; Monta Tela para o CSW
	;
	; csw:label:1,2,25,Endereço do Administrador (TO)
	; csw:label:1,3,25,Enviar E-mail em caso erro
	; csw:label:1,4,25,Endereço para cópia (CC)
	; csw:label:1,5,25,Enviar E-mail em caso erro
	; csw:label:1,6,25,Endereço do Remetente
	; csw:label:1,7,25,Endereço IP do servidor POP3
	; csw:label:1,7,66,Porta
	; csw:label:1,8,25,Endereço IP do servidor SMTP
	; csw:label:1,8,66,Porta
	; csw:label:1,9,25,Time-Out Conexão (segundos)
	; csw:label:1,10,25,Diretório Temporário
	; csw:label:1,11,25,Usuário SMTP
	; csw:label:1,12,25,Senha SMTP
	; csw:label:1,13,25,Cabeçalho do E-mail de Erro
	; csw:label:1,14,25,Anexar Imagem CSW
	; csw:label:1,15,25,Tipo de envio de relatório por e-mail
	;
	; csw:labelcreate:%CSMEN080D
	; csw:labeldestroy:9999
	; csw:csp:gerar
	; csw:ajuda:CSMEN080D
]]></Routine>


<Routine name="%CSMEN080RG" type="MAC" languagemode="0" timestamp="63783,35795.942025"><![CDATA[
%CSMEN080RG	; 02/2010 - REGRAS CADASTRO DE PARAMETROS
	;
	#include %CSUTICSP
	;
	; Criar Abas
	; (MB 11/02/2010)
CriarAbas(codEmpresa)	;
	$$$VAR
	new tabs
	;
	set tabs(1)="%CSMEN080TAB1"_Z_"Gerais"_Z_"1"
	set tabs(2)="%CSMEN080TAB2"_Z_"Menu"_Z_"1"
	set tabs(3)="%CSMEN080TAB3"_Z_"%SMS/Arquivos"_Z_"1"
	set tabs(4)="%CSMEN080TAB4"_Z_"E-mail"_Z_"1"
	set tabs(5)="%CSMEN080TAB5"_Z_"Licenças"_Z_"1"
	;set tabs(6)="%CSMEN080TAB6"_Z_"Atualização"_Z_"1"
	set tabs(7)="%CSMEN080TAB7"_Z_"LDAP"_Z_"1"
	set tabs(8)="%CSMEN080TAB8"_Z_"Central Ajuda"_Z_"1"
	;
	do criarTabPanel^%CSW1A("sheat1",1,0.5,21.5,90,.tabs,1)
	;
	quit $$$OK
	;
	; Ver Identificacao Empresa
	;
VerIdentificacaoEmpresa(varRetorno)	;
	$$$VAR
	;
	set varRetorno(0)="Razão Social"
	set varRetorno(1)="Fantasia"
	;
	quit $$$OK
	;
	; Ret Empresa
	;
RetEmpresa(varRetorno)	;
	$$$VAR
	new sc,codEmpresa,emp
	;
	kill varRetorno
	set codEmpresa=""
	for  set codEmpresa=$order(^%EMP(codEmpresa)) quit:codEmpresa=""  do
	. set sc=$$VerEmpresa^%CSAPLRG001(codEmpresa,.emp)
	. set varRetorno(codEmpresa)=$piece(emp,z,1)
	;
	quit $$$OK
	;
	; Salvar
	;
Salvar(codEmpresa,%SMConf,%csmencf)	;
	$$$VAR
	new %csmencfA,sc
	;
	set sc=$$ProxyGravacaoCSMV^CCUTIRG001(codEmpresa,$get(%PRG),2,"%CSMENCF","",%csmencf)
	;
	set ^%SMConf("System","Indef")=%SMConf("Indef")
	set ^%SMConf("System","DispTelnet")=%SMConf("DispTelnet")
	set ^%SMConf("System","TestaNetTerm")=%SMConf("TestaNetTerm")
	;
	set sc=$$VerConfGeral^%CSMENRG005(.%csmencfA)
	;
	if +$piece(%csmencfA,Z,64)=0,$piece(%csmencf,Z,64)>0 set $piece(%csmencf,Z,65)=+$$$horolog
	;
	set ^%CSMENCF=%csmencf
	;
	quit $$$OK
	;
	; Ver Tipo de Envio de Relatorio por E-mail
	;
VerTipoEnvioRelEmail(varRetorno)	;
	$$$VAR
	;
	set varRetorno(0)="Servidor"
	set varRetorno(1)="Local"
	;
	quit $$$OK
	;
	; Tipo de Envio de Relatório por E-mail
	;
TIPENVREL	do ^%CSUTIMB("Servidor;Local","%codret","Envio Relatório por E-mail",,,,,,,,,"TIPENVRELMB1^%CSMEN080RG")
	quit:$$CSP^%CSW1UTI()
TIPENVRELMB1	set %codret=$select(%=27:"",1:%codret-1)
	do SetF7^%CSW1UTI(%codret)
	quit
	;
	; Obter Tabela Controle Lock
	; (JD 21/10/2010)
ObterTabelaControleLock(tabControleLock,tipo)	;
	$$$VAR
	;
	kill tabControleLock
	;
	if $get(tipo)="" set tipo=1
	if tipo=0 set tabControleLock="0 - Nativo;1 - Consistem"
	if tipo=1 set tabControleLock="Nativo;Consistem"
	;
	if tipo=2 do
	. set tabControleLock(0)="Nativo"
	. set tabControleLock(1)="Consistem"
	;
	quit $$$OK
	;
	; Obter Tabela Modelo Numeros com Ponto Flutuante
	;
ObterTabelaModeloFloat(tabModeloFloat)	;
	$$$VAR
	;
	kill tabModeloFloat
	;
	set tabModeloFloat(0)="Caractere"
	set tabModeloFloat(1)="Padrão"
	;
	quit $$$OK
	;
	; Obter tabela Habilita Subscrito
	; (MZ - 12/01/2011)
ObterTabSubscrito(tabelaSubscrito,tipo)	;
	$$$VAR
	;
	kill tabelaSubscrito
	;
	if $get(tipo)="" set tipo=1
	if tipo=0 set tabelaSubscrito="0 - Não;1 - Sim"
	if tipo=1 set tabelaSubscrito="Não;Sim"
	;
	if tipo=2 do
	. set tabelaSubscrito(0)="Não"
	. set tabelaSubscrito(1)="Sim"
	;
	quit $$$OK
	;
	; Ver Tipo de Segurança da Conexão
	;
VerTipoSegurancaConexao(varRetorno)	;
	$$$VAR
	;
	set varRetorno(0)="Nenhuma"
	set varRetorno(1)="SSL/TLS"
	set varRetorno(2)="SSL"
	set varRetorno(3)="TLS"
	;
	quit $$$OK
	;
	; Tipo de Segurança da Conexão
	;
SegurancaConexao	;
	do ^%CSUTIMB("Nenhuma;SSL/TLS;SSL;TLS","%codret","Segurança da Conexão",,,,,,,,,"SegurancaConexaoMb1^%CSMEN080RG")
	quit:$$CSP^%CSW1UTI()
SegurancaConexaoMb1	set %codret=$select(%=27:"",1:%codret-1)
	do SetF7^%CSW1UTI(%codret)
	quit
	;
	; csw:csp:naogerar
]]></Routine>


<Routine name="%CSMEN080TAB4" type="MAC" languagemode="0" timestamp="63783,38512.109525"><![CDATA[
%CSMEN080TAB4	; 04/2006 - CONFIGURACAO E - MAIL
0000	quit
	;
0500	if $piece(%CSMENCF,Z,35)="" set $piece(%CSMENCF,Z,35)=0
	if $piece(%CSMENCF,Z,36)="" set $piece(%CSMENCF,Z,36)=0
	if $piece(%CSMENCF,Z,61)="" set $piece(%CSMENCF,Z,61)=0
	if $piece(%CSMENCF,Z,71)="" set $piece(%CSMENCF,Z,71)=0
	;
	do 9000,8000
	;
	; E-mail do Administrador
1000	;
1000ON	do ^%CSLE(1,26,45,"$P(%CSMENCF,Z,25)",$piece(%CSMENCF,Z,25),,,,",,1,cp1000")
	quit:$$CSP^%CSW1UTI()
1000EX	goto 9999:%=27,1000:%=140
	if '$$Valcp1000() goto 1000
	;
	; Enviar E-mail em caso erro
1100	;
1100ON	do ^%CSLE(2,26,1,"$P(%CSMENCF,Z,35)",$piece(%CSMENCF,Z,35),,",5,6",,",SIMNAO^%CSMEN299,2,cp1100",,,,,1,.TABESN)
	quit:$$CSP^%CSW1UTI()
1100EX	goto 9999:%=27,1000:%=140
	if '$$Valcp1100() goto 1100
	;
	; E-mail do Copia
1200	;
1200ON	do ^%CSLE(3,26,45,"$P(%CSMENCF,Z,26)",$piece(%CSMENCF,Z,26),,,,",,3,cp1200")
	quit:$$CSP^%CSW1UTI()
1200EX	goto 9999:%=27,1100:%=140
	if '$$Valcp1200() goto 1200
	;
	; Enviar E-mail em caso erro
1300	;
1300ON	do ^%CSLE(4,26,1,"$P(%CSMENCF,Z,36)",$piece(%CSMENCF,Z,36),"",",5,6",,",SIMNAO^%CSMEN299,4,cp1300",,,,,1,.TABESN)
	quit:$$CSP^%CSW1UTI()
1300EX	goto 9999:%=27,1200:%=140
	if '$$Valcp1300() goto 1300
	;
	; E-mail do Resposta
1400	;
1400ON	do ^%CSLE(5,26,45,"$P(%CSMENCF,Z,24)",$piece(%CSMENCF,Z,24),,,,",,5,cp1400")
	quit:$$CSP^%CSW1UTI()
1400EX	goto 9999:%=27,1300:%=140
	if '$$Valcp1400() goto 1400
	;
	; Endereco IP do servidor POP3
1500	;
1500ON	do ^%CSLE(6,26,45,"$P(%CSMENCF,Z,29)",$piece(%CSMENCF,Z,29),,,,",,6,cp1500,,,30")
	quit:$$CSP^%CSW1UTI()
1500EX	goto 9999:%=27,1400:%=140
	if '$$Valcp1500() goto 1500
	;
	; Porta POP3
1600	;
1600ON	do ^%CSLE(6,67,4,"$P(%CSMENCF,Z,27)",$piece(%CSMENCF,Z,27),,,,",,7,cp1600")
	quit:$$CSP^%CSW1UTI()
1600EX	goto 9999:%=27,1500:%=140
	if '$$Valcp1600() goto 1600
	;
	; Endereco IP do servidor SMTP
1700	;
1700ON	do ^%CSLE(7,26,45,"$P(%CSMENCF,Z,30)",$piece(%CSMENCF,Z,30),,,,",,8,cp1700,,,30")
	quit:$$CSP^%CSW1UTI()
1700EX	goto 9999:%=27,1600:%=140
	if '$$Valcp1700() goto 1700
	;
	; Porta SMTP
1800	;
1800ON	do ^%CSLE(7,67,4,"$P(%CSMENCF,Z,28)",$piece(%CSMENCF,Z,28),,,,",,9,cp1800")
	quit:$$CSP^%CSW1UTI()
1800EX	goto 9999:%=27,1700:%=140
	if '$$Valcp1800() goto 1800
	;
	; Porta POP3
1900	;
1900ON	do ^%CSLE(8,26,4,"$P(%CSMENCF,Z,31)",$piece(%CSMENCF,Z,31),,,,",,10,cp1900")
	quit:$$CSP^%CSW1UTI()
1900EX	goto 9999:%=27,1800:%=140
	if '$$Valcp1900() goto 1900
	;
	; Diretorio temporario
2000	;
2000ON	do ^%CSLE(9,26,45,"$P(%CSMENCF,Z,32)",$piece(%CSMENCF,Z,32),,,,",,11,cp2000")
	quit:$$CSP^%CSW1UTI()
2000EX	goto 9999:%=27,1900:%=140
	if '$$Valcp2000() goto 2000
	;
	; Usuario para SMTP
2100	;
2100ON	do ^%CSLE(10,26,35,"$P(%CSMENCF,Z,33)",$piece(%CSMENCF,Z,33),,,,",,12,cp2100")
	quit:$$CSP^%CSW1UTI()
2100EX	goto 9999:%=27,2000:%=140
	if '$$Valcp2100() goto 2100
	;
	; Senha para SMTP
2200	;
2200ON	do ^%CSLE(11,26,20,"$P(%CSMENCF,Z,34)",$piece(%CSMENCF,Z,34),,,,",,13,cp2200",",,,,,,1")
	quit:$$CSP^%CSW1UTI()
2200EX	goto 9999:%=27,2100:%=140
	if '$$Valcp2200() goto 2200
	;
	; Cabeçalho do email de erro
2300	;
2300ON	do ^%CSLE(12,26,45,"$P(%CSMENCF,Z,37)",$piece(%CSMENCF,Z,37),,,,",,14,cp2300")
	quit:$$CSP^%CSW1UTI()
2300EX	goto 9999:%=27,2200:%=140
	if '$$Valcp2300() goto 2300
	;
	; Anexar Imagem CSW
2400	;
2400ON	do ^%CSLE(13,26,1,"$P(%CSMENCF,Z,61)",$piece(%CSMENCF,Z,61),,",5,6",,",SIMNAO^%CSMEN299,15,cp2400",,,,,1,.TABESN)
	quit:$$CSP^%CSW1UTI()
2400EX	goto 9999:%=27,2300:%=140
	if '$$Valcp2400() goto 2400
	;
	; Identificacao da empresa
2500	;
2500ON	do ^%CSLE(14,26,1,"$P(%CSMENCF,Z,71)",$piece(%CSMENCF,Z,71),"""01""'[@","1",,",TIPENVREL^%CSMEN080RG,16,cp2500,,,10",,,,,1,.TABTIPREL)
	quit:$$CSP^%CSW1UTI()
2500EX	goto 9999:%=27,2400:%=140
	if '$$Valcp2500() goto 2500
	;
	; Utiliza conexão segura
2600	;
2600ON	do ^%CSLE(15,26,10,"$P(%CSMENCF,Z,77)",$piece(%CSMENCF,Z,77),"""0123""'[@","1",,",SegurancaConexao^%CSMEN080RG,17,cp2600",,,,,1,.TABSEGCON)
	quit:$$CSP^%CSW1UTI()
2600EX	goto 9999:%=27,2500:%=140
	if '$$Valcp2600() goto 2600
	;
	; Confirma
	;
3000	if '$$Validate() quit:$$CSP^%CSW1UTI()
	;
	goto 0500
	;
	; Mostra dados
8000	;
	do Set^%CSW1UTI(%PRG,"cp1000",$piece(%CSMENCF,Z,25),)
	do InicializaCombo^%CSW1A("cp1100",.TABESN,0,$piece(%CSMENCF,Z,35),,,1)
	do Set^%CSW1UTI(%PRG,"cp1200",$piece(%CSMENCF,Z,26),)
	do InicializaCombo^%CSW1A("cp1300",.TABESN,0,$piece(%CSMENCF,Z,36),,,1)
	do Set^%CSW1UTI(%PRG,"cp1400",$piece(%CSMENCF,Z,24),)
	do Set^%CSW1UTI(%PRG,"cp1500",$piece(%CSMENCF,Z,29),)
	do Set^%CSW1UTI(%PRG,"cp1600",$piece(%CSMENCF,Z,27),)
	do Set^%CSW1UTI(%PRG,"cp1700",$piece(%CSMENCF,Z,30),)
	do Set^%CSW1UTI(%PRG,"cp1800",$piece(%CSMENCF,Z,28),)
	do Set^%CSW1UTI(%PRG,"cp1900",$piece(%CSMENCF,Z,31),)
	do Set^%CSW1UTI(%PRG,"cp2000",$piece(%CSMENCF,Z,32),)
	do Set^%CSW1UTI(%PRG,"cp2100",$piece(%CSMENCF,Z,33),)
	do Set^%CSW1UTI(%PRG,"cp2200",$piece(%CSMENCF,Z,34),)
	do Set^%CSW1UTI(%PRG,"cp2300",$piece(%CSMENCF,Z,37),)
	do InicializaCombo^%CSW1A("cp2400",.TABESN,0,$piece(%CSMENCF,Z,61),,,1)
	do InicializaCombo^%CSW1A("cp2500",.TABTIPREL,0,$piece(%CSMENCF,Z,71),,,1)
	do InicializaCombo^%CSW1A("cp2600",.TABSEGCON,0,$piece(%CSMENCF,Z,77),,,1)
	quit
	;
	; Tela
	;
9000	do Clear^%CSW1UTI()
	do Enable^%CSW1UTI()
	;
	do InicializaCombo^%CSW1A("cp1100",.TABESN,0,0,,,1)
	do InicializaCombo^%CSW1A("cp1300",.TABESN,0,0,,,1)
	do InicializaCombo^%CSW1A("cp2400",.TABESN,0,0,,,1)
	do InicializaCombo^%CSW1A("cp2500",.TABTIPREL,0,0,,,1)
	do InicializaCombo^%CSW1A("cp2500",.TABESN,0,0,,,1)
	quit
	;
	; Fim
	;
9999	do execLabelTabPanel^%CSW1A("sheat1","9999^%CSMEN080CSW")
	quit
	;
	; Metodo Valcp1000()
	;
Valcp1000()	;
	quit 1
	;
	; Metodo Valcp1100()
	;
Valcp1100()	;
	quit 1
	;
	; Metodo Valcp1200()
	;
Valcp1200()	;
	quit 1
	;
	; Metodo Valcp1300()
	;
Valcp1300()	;
	quit 1
	;
	; Metodo Valcp1400()
	;
Valcp1400()	;
	quit 1
	;
	; Metodo Valcp1500()
	;
Valcp1500()	;
	quit 1
	;
	; Metodo Valcp1600()
	;
Valcp1600()	;
	quit 1
	;
	; Metodo Valcp1700()
	;
Valcp1700()	;
	quit 1
	;
	; Metodo Valcp1800()
	;
Valcp1800()	;
	quit 1
	;
	; Metodo Valcp1900()
	;
Valcp1900()	;
	quit 1
	;
	; Metodo Valcp2000()
	;
Valcp2000()	;
	quit 1
	;
	; Metodo Valcp2100()
	;
Valcp2100()	;
	quit 1
	;
	; Metodo Valcp2200()
	;
Valcp2200()	;
	quit 1
	;
	; Metodo Valcp2300()
	;
Valcp2300()	;
	quit 1
	;
	; Metodo Valcp2400()
	;
Valcp2400()	;
	quit 1
	;
	; Metodo Valcp2500()
	;
Valcp2500()	;
	if $piece(%CSMENCF,Z,71)'="","01"'[$piece(%CSMENCF,Z,71) do ME^%CSUTIUD("Tipo de envio de relatório por e-mail: Valor inválido! ("_$piece(%CSMENCF,Z,71)_")") quit 0
	set $piece(%CSMENCF,Z,71)=+$piece(%CSMENCF,Z,71)
	;
	quit 1
	;
	; Metodo Valcp2600()
	;
Valcp2600()	;
	quit 1
	;
	; Metodo Validate()
	;
Validate()	;
	quit:'$$CSP^%CSW1UTI() 1
	if '$$Valcp1000() do Focus^%CSW1UTI(%PRG,"cp1000") quit 0
	if '$$Valcp1100() do Focus^%CSW1UTI(%PRG,"cp1100") quit 0
	if '$$Valcp1200() do Focus^%CSW1UTI(%PRG,"cp1200") quit 0
	if '$$Valcp1300() do Focus^%CSW1UTI(%PRG,"cp1300") quit 0
	if '$$Valcp1400() do Focus^%CSW1UTI(%PRG,"cp1400") quit 0
	if '$$Valcp1500() do Focus^%CSW1UTI(%PRG,"cp1500") quit 0
	if '$$Valcp1600() do Focus^%CSW1UTI(%PRG,"cp1600") quit 0
	if '$$Valcp1700() do Focus^%CSW1UTI(%PRG,"cp1700") quit 0
	if '$$Valcp1800() do Focus^%CSW1UTI(%PRG,"cp1800") quit 0
	if '$$Valcp1900() do Focus^%CSW1UTI(%PRG,"cp1900") quit 0
	if '$$Valcp2000() do Focus^%CSW1UTI(%PRG,"cp2000") quit 0
	if '$$Valcp2100() do Focus^%CSW1UTI(%PRG,"cp2100") quit 0
	if '$$Valcp2200() do Focus^%CSW1UTI(%PRG,"cp2200") quit 0
	if '$$Valcp2300() do Focus^%CSW1UTI(%PRG,"cp2300") quit 0
	if '$$Valcp2400() do Focus^%CSW1UTI(%PRG,"cp2400") quit 0
	if '$$Valcp2500() do Focus^%CSW1UTI(%PRG,"cp2500") quit 0
	if '$$Valcp2600() do Focus^%CSW1UTI(%PRG,"cp2600") quit 0
	quit 1
	;
	; Metodo Show
	;
Show(%cswP1,%cswP2,%cswP3,%cswP4)	;
	do Show^%CSW1UTI("%CSMEN080TAB4",$get(%cswP1),$get(%cswP2),$get(%cswP3),$get(%cswP4))
	quit
	;
	; Monta Tela para o CSW
	;
	; csw:label:1,1,25,Endereço do Administrador (TO)
	; csw:label:1,2,25,Enviar E-mail em Caso Erro
	; csw:label:1,3,25,Endereço para Cópia (CC)
	; csw:label:1,4,25,Enviar E-mail em Caso Erro
	; csw:label:1,5,25,Endereço do Remetente
	; csw:label:1,6,25,Endereço IP do Servidor POP3
	; csw:label:1,6,66,Porta
	; csw:label:1,7,25,Endereço IP do Servidor SMTP
	; csw:label:1,7,66,Porta
	; csw:label:1,8,25,Time-Out Conexão (Segundos)
	; csw:label:1,9,25,Diretório Temporário
	; csw:label:1,10,25,Usuário SMTP
	; csw:label:1,11,25,Senha SMTP
	; csw:label:1,12,25,Cabeçalho do E-mail de Erro
	; csw:label:1,13,25,Anexar Imagem CSW
	; csw:label:1,14,25,Tipo de Envio de Relatório por E-mail
	; csw:label:1,15,25,Segurança da Conexão
	;
	; csw:labelseltab:0500
	; csw:labelcreate:%CSMEN080TAB4
	; csw:labeldestroy:9999
	; csw:csp:gerar
]]></Routine>


<Routine name="%CSUTIEM" type="MAC" languagemode="0" timestamp="63783,39415.983983"><![CDATA[
%CSUTIEM	; RT CACHE WEBLINK DEVELOPER: POP3 CLIENT FUNCTIONS
	;
	quit
	#include %CSUTICSP
	;
	;
	;  parâmetros de chamada:
	;
	;  1 - assunto
	;  2 - mensagem (matriz)
	;  3 - servidor smtp
	;  4 - e-mail do remetente
	;  5 - destinatario (matriz)
	;  6 - nome do arquivo atachado
	;  7 - timeout da conexão
	;  8 - diferença de Grenwich (300)
	;  9 - owndomain
	; 10 - %smtpport
	; 11 - %displayform
	; 12 - %displayto
	; 13 - tipo de arquivo atachado (0/texto 1/zip 2/outro binario)
	; 14 - tipo de texto inserido (0/texto 1/html)
	; 15 - E-mail para envio de confirmação de Recebimento
	; 16 - usuario SMTP
	; 17 - senha SMTP
	; 18 - e-mail de resposta
	;
	; forma de chamada:
	;
	; set status=$$SEND^%CSUTIUD(....)
	;
	; retorno: 0 - erro
	;          1 - ok
	;          Quando ocorrer erro, é retornada a variavel FailureReason contento
	;          o código e a descrição do motivo
	;
	;1   2    3          4    5            6             7        8          9         10        11           12       13        14       15           16       17       18
SEND(subject,mesg,smtpdomain,from,destinatario,attachfile,%timeout,%GMTOffset,owndomain,%smtpport,%displayfrom,%displayto,attachtype,texttype,emailConfirm,userSMTP,passSMTP,replyTo)	;
	;
	new %h,%inetdate,%inettime,%date,%mess,%from,%to,%csmencf,%idx,i,separador,linha
	new %smtpdialog,CRLF,%sent,sc,cid
	#include %occOptions
	#include %occStatus
	set attachfile=$get(attachfile)
	set attachtype=+$get(attachtype)
	set texttype=+$get(texttype)
	set separador="----=_NextPart_000_0005_01C04D91.A1A0F1D0"
	if $data(destinatario),$order(@destinatario@(""))'="" merge %to=@destinatario
	set %csmencf=$get(^%CSMENCF)
	if $get(%timeout)="" set %timeout=$$GetTimeOut()
	if $get(smtpdomain)="" set smtpdomain=$$GetIP()
	if $get(%smtpport)="" set %smtpport=$$GetPort()
	if $get(from)="" set from=$$GetFrom()
	if $get(userSMTP)="" set userSMTP=$$GetUserSMTP()
	if $get(passSMTP)="" set passSMTP=$$GetPassSMTP()
	if $order(%to(""))="" do GetTo()
	set subject=$get(subject)
	set %GMTOffset=$get(%GMTOffset) if %GMTOffset="" set %GMTOffset="0300 GMT"
	if $get(owndomain)="" set owndomain=$$GetIP()
	;
	set (FailureReason,linha)=""
	if smtpdomain="" set FailureReason="Dominio do SMTP nao especificado" quit 0
	if from="" set FailureReason="No sender's email address specified" quit 0
	if $order(%to(""))="" set FailureReason="No recipient's email address specified" quit 0
	if '$data(@mesg) set FailureReason="No message has been defined in ^wldSMTP" quit 0
	; 
	set attachtype=1
	if ($$Versao^%CSUTICSP()>4) {
		new msgcsw,sc
		merge msgcsw=@mesg
		set sc=$$EnviarEmail^%CSUTIEM(subject,.msgcsw,smtpdomain,%smtpport,from,.%to,.attachfile,attachtype,userSMTP,passSMTP,,$get(texttype),$get(emailConfirm),$get(%displayfrom),$get(replyTo))
		if $$$ISERR(sc) {
			new er
			do $system.Status.DecomposeStatus(sc,.er)
			set FailureReason=$get(er(1))
			set:$get(er(1))["#10000: " FailureReason=$piece($get(er(1)),"#10000: ",2)
			set sc=0
		}
		quit sc
	}
	;
	set %h=$$$horolog
	set %inetdate=$$DECDATE(%h)
	set %inettime=$$INETTIME(%h,%GMTOffset)
	set %date=%inetdate_" "_%inettime
	;
	set %idx=0,i=""
	set %mess($increment(%idx))="Date: "_%date
	set %displayto=$translate($get(%displayto),",",";")
	if $get(%displayfrom)'="" do
	. set %mess($increment(%idx))="From: """_%displayfrom_"""<"_from_">"
	else  do
	. set %mess($increment(%idx))="From: <"_from_">"
	for  set i=$order(%to(i)) quit:i=""  do  ;quit Chamado: 65845 OS: 35517
	. if $get(%displayto)'="" do
	. . set %mess($increment(%idx))="To: """_$piece(%displayto,";",i)_"""<"_%to(i)_">"
	. else  do
	. . set %mess($increment(%idx))="To: <"_%to(i)_">"
	if $get(emailConfirm)=1 do
	. set %mess($increment(%idx))="Message-ID: <"_$random(1000000000000000)_">"
	. set %mess($increment(%idx))="Disposition-Notification-To: ""retorno"" <"_from_">"
	set %mess($increment(%idx))="Subject: "_subject
	;set %mess($increment(%idx))=""
	set %mess($increment(%idx))="MIME-Version: 1.0"
	set %mess($increment(%idx))="Content-Type: multipart/mixed;boundary="""_separador_""""
	set %mess($increment(%idx))=""
	set %mess($increment(%idx))="--"_separador
	if texttype=0 do
	. set %mess($increment(%idx))="Content-Type: text/plain; charset=ISO-8859-1; format=flowed"
	. ;set %mess($increment(%idx))="Content-Transfer-Encoding: quoted-printable" => Colocado em comentário conforme OS 21327
	if texttype=1 do
	. set %mess($increment(%idx))="Content-Type: text/html;"
	set %mess($increment(%idx))=""
	;
	set %from="<"_from_">"
	;set %to="<"_to_">"
	set %sent=$$bigsmtp()
	quit %sent
	;
bigsmtp()	; raw SMTP client
	;
	new dev,X,rcpt,mess,line,resp,error,port,%zt
	set %zt=$ztrap
	kill %smtpdialog
	;
	set $ztrap="smtperr"
	set dev="|TCP|"_%smtpport,CRLF=$char(13,10)
	close dev ; just in case
	open dev:smtpdomain:%timeout else  set FailureReason="Failed to connect to smtp server" goto FAIL
	use dev read resp:%timeout else  set FailureReason="Failed to initiate connection with smtp server" goto FAIL
dlg1	do ADD2DIALOG(resp)
	use dev read resp:1 do ADD2DIALOG(resp)
	;set resp="passei por aqui 1" do ADD2DIALOG(resp)
	;
	use dev write "EHLO ",owndomain,CRLF,! read resp
dlg2	do ADD2DIALOG(resp)
	if resp'["250" set FailureReason=resp  goto FAIL
	;
	;use dev write "MAIL FROM: ",from,CRLF,! read resp
	use dev write "MAIL FROM: <",from,">",CRLF,! read resp
dlg3	do ADD2DIALOG(resp)
	if resp'["250" set FailureReason=resp  goto FAIL
	;
	set error=0,rcpt=""
dlg4	for  set rcpt=$order(%to(rcpt)) quit:rcpt=""  do TO(%to(rcpt))
	if error  goto FAIL
	;
	use dev write "DATA",CRLF,! read resp
dlg5	do ADD2DIALOG(resp)
	if resp'["250"&(resp'[354) set FailureReason=resp goto FAIL
	;
	set line=""
	for  set line=$order(%mess(line)) quit:line=""  do
	. set mess=%mess(line)
	. do MESS(mess)
	;
	set line=""
	for  set line=$order(@mesg@(line)) quit:line=""  do
	. set mess=@mesg@(line)
	. do MESS(mess)
	;
	; verifica se existe arquivo(s) anexos a serem enviados
	;
	set sc=1
	if $get(attachfile)'="" do
	. set sc=$$AttachFile(attachfile,attachtype,separador,dev)
	;
	for  set cid=$order(attachfile($get(cid))) quit:cid=""  do
	. set sc=$$AttachFile(attachfile($get(cid)),attachtype,separador,dev)
	;
	goto:sc'=1 FAIL
	do MESS("--"_separador_"--")
	;
	;set resp="antes do write ." do ADD2DIALOG(resp)
	use dev write ".",CRLF,! read resp
dlg6	do ADD2DIALOG(resp)
	if resp'["250"&(resp'[354)&($translate(resp,CRLF_" ","")'="") set FailureReason=resp goto FAIL
	;set resp="depois do write ." do ADD2DIALOG(resp)
	;
	use dev write "QUIT",CRLF,! read resp:0
dlg7	do ADD2DIALOG(resp)
	set resp="*** fim ***" do ADD2DIALOG(resp)
	;
	close dev quit 1
	;-------------------------------------------------------------------------+
	; subrotinas incorporadas para facilitar a manutenção futura.             |
	;-------------------------------------------------------------------------+
DECDATE(dataint)	; transforma data interna em formato utilizado na mensagem
	;
	new %D,%YY,%MM,%DD,%D1
	set %D1=$zdate(dataint,5)
	set %YY=$piece(%D1,", ",2)
	set %DD=+$piece(%D1," ",2) if %DD<10 set %DD="0"_%DD
	set %MM=$piece(%D1," ",1)
	set %D=%DD_" "_%MM_" "_%YY
	quit %D
	;
DECTIME(HDATE)	; Decode Time from $H format
	;
	new %T,%HR,%MIN,%SEC,%ampm
	set %T=$piece(HDATE,",",2)
	set %HR=%T\3600
	set %T=%T-(%HR*3600)
	set %MIN=%T\60
	set %SEC=%T-(%MIN*60)
	set %ampm="AM" if %HR>12 set %HR=%HR-12,%ampm="pm"
	if %HR<10 set %HR="0"_%HR
	if %MIN<10 set %MIN="0"_%MIN
	if %SEC<10 set %SEC="0"_%SEC
	set %T=%HR_":"_%MIN_":"_%SEC_" "_%ampm
	quit %T
	;
INETDATE(HDATE)	; Decode $H date and time to Internet format
	;
	new %d,%day,%time,%date
	;
	set %time=$piece(HDATE,",",2)
	if %time>86400 do
	. set %time=%time-86400
	. set HDATE=(HDATE+1)_","_%time
	;
	set %d="Thursday,Friday,Saturday,Sunday,Monday,Tuesday,Wednesday"
	set %day=(HDATE#7)+1
	set %day=$piece(%d,",",%day)
	;
	set %date=$$DECDATE(HDATE)
	set %date=$translate(%date," ","-")
	set %time=$$INETTIME(HDATE)
	set %date=%day_", "_%date_" "_%time
	quit %date
	;
INETTIME(horaint,offset)	;
	; transforma hora interna em formato utilizado na mensagem
	; Offset é relativo a GMT, ex: -0300
	;
	new %T,%HR,%MIN,%SEC,%ampm
	set offset=$get(offset) if offset="" set offset="GMT"
	set %T=$piece(horaint,",",2)
	set %HR=%T\3600
	set %T=%T-(%HR*3600)
	set %MIN=%T\60
	set %SEC=%T-(%MIN*60)
	if %HR<10 set %HR="0"_%HR
	if %MIN<10 set %MIN="0"_%MIN
	if %SEC<10 set %SEC="0"_%SEC
	set %T=%HR_":"_%MIN_":"_%SEC_" "_offset
	quit %T
	;
GetIP()	; pega o ip do servidor cache
	;
	if $piece(%csmencf,"^",30)'="" quit $piece(%csmencf,"^",30)
	new ipd,ip
	set ipd=$zutil(54,13,$zutil(54,0)) ; get ip address + domain name
	set ip=$piece(ipd,",",1)
	quit ip
	;
GetFrom()	;
	quit $piece(%csmencf,"^",24) 
	;
GetUserSMTP()	;
	quit $piece(%csmencf,"^",33)
	;
GetPassSMTP()	;	
	quit $piece(%csmencf,"^",34)
	;
	;
GetTo()	; busca o e-mail do destinatario
	;
	new index,end set end=$piece(%csmencf,"^",25)
	for index=1:1:$length(end,";") do
	. if $piece(end,";",index)'="" set %to(index)=$piece(end,";",index)
	quit  ;$p(%csmencf,"^",25)
	;
GetPort()	; busca o numero da porta SMTP
	;
	if $piece(%csmencf,"^",28)'="" quit $piece(%csmencf,"^",28)
	quit 25
	;
GetTimeOut()	; busca o valor de TIMEOUT padrão
	;
	if $piece(%csmencf,"^",31)'="" quit $piece(%csmencf,"^",31)
	quit 20
	;
FAIL	close dev quit 0
	;
OK	close dev quit 1
	;
smtperr	; error has occurred
	;do ^%wldet
	set FailureReason="Erro ao enviar e-mail: "_$zerror
	set $ztrap=%zt
	quit 0
	;
TO(to)	;
	use dev write "RCPT TO: <",to,">",CRLF,! read resp
	do ADD2DIALOG(resp)
	if resp'["250" set FailureReason=resp,error=1 quit
	quit
	;
MESS(line)	;
	new %buf,%p1
	set %buf=$get(line)
	if %buf="" do  quit
	. use dev write CRLF,!
	;
	for  quit:%buf=""  do
	. set %p1=$extract(%buf,1,254),%buf=$extract(%buf,255,$length(%buf))
	. if $extract(%p1)="." set %p1="."_%p1
	. if $length(%p1) use dev write %p1,!
	use dev write CRLF,!
	quit
	;
MESS2(line)	;
	new %buf,%p1
	set %buf=$get(line)
	if %buf="" do  quit
	. use dev write !
	;
	for  quit:%buf=""  do
	. set %p1=$extract(%buf,1,254),%buf=$extract(%buf,255,$length(%buf))
	. ;if $extract(%p1)="." set %p1="."_%p1
	. if $length(%p1) use dev write %p1
	use dev write CRLF,!
	quit
	;
ADD2DIALOG(line)	;
	;
	new %lineno
	set %lineno=$zprevious(%smtpdialog(""))+1
	set %smtpdialog(%lineno)=line
	quit
	;
	; Teste de E-mail
	;
	;set sc=$$TEST^%CSUTIEM("coelho@consistem.com.br","coelho@consistem.com.br",1)
TEST(from,to,confirm)	;
	new codSeq,var,%,tabfile
	new tabEmail,tabDestino,i
	set (codSeq)=""
	set to=$get(to)
	set from=$get(from) if from="" write !,"Nao foi informado o e-mail do remetente" quit
	set confirm=+$get(confirm)
	;
	kill tabEmail,tabDestino
	set tabEmail(1)="Teste de E-mail pelo Sistema Consistem ( "_$zdate(+$$$horolog,4)_" as "_$ztime($piece($$$horolog,",",2))_" )"
	set tabEmail(2)="Utilitário de E-mail %CSUTIEM"
	set tabEmail(3)="---------------------------------------------------------------------------------"
	if confirm=1 do
	. set tabEmail(4)="Este e-mail esta sendo enviado pelo gerador de e-mails da Consistem"
	. set tabEmail(5)="Com confirmação de resposta!"
	. set tabEmail(6)="Se seu software de e-mail nao enviar confirmacao, faca contato com a Consistem"
	;
	kill tabDestino
	do
	. new idx,end,i
	. set idx=0,end=$piece($get(^%CSMENCF),"^",25)
	. for i=1:1:$length(end,";") do
	. . if $piece(end,";",i)'="" set tabDestino($increment(idx))=$piece(end,";",i)
	. set end=$piece($get(^%CSMENCF),"^",26)
	. for i=1:1:$length(end,";") do
	. . if $piece(end,";",i)'="" set tabDestino($increment(idx))=$piece(end,";",i)
	. set end=$translate(to,",",";")
	. for i=1:1:$length(end,";") do
	. . if $piece(end,";",i)'="" set tabDestino($increment(idx))=$piece(end,";",i)
	;
	for  set codSeq=$order(tabmsg(codSeq),1,var) quit:codSeq=""  do
	. set tabEmail($order(tabEmail(""),-1)+1)=var
	set tabfile(1)="/usr/tmp/leandro/camaqua/2010/08/03/43100801229700000115550020000014940186551334-nfe.xml"
	;
	; Envia e-mail
	;
	set %=$$SEND^%CSUTIEM("Teste %CSUTIEM","tabEmail","",from,"tabDestino",,,,,,,,,,confirm)
	quit %
	;
	; Novo metodo de envio de email
	;
EnviarEmail(subject,mesg,smtpdomain,smtpport,from,destinatario,attachfile,attachtype,userSMTP,passSMTP,timeZone,tipoTexto,emailConfirm,%cswDisplayFrom,replyTo)	;
	new AUTH,MSG,SMTP,sc,linha,IsWin,cid,confSSL,nspOri,conexaoSegura
	#include %occOptions
	#include %occStatus
	set sc=1,IsWin=$zversion["Windows"
	set:$get(attachfile)="" attachfile=""
	set:$get(mesg)="" mesg=""
	set:$get(^%SYS("TempDir"))="" ^%SYS("TempDir")=$select($piece($get(^%CSMENCF),"^",32)'="":$piece($get(^%CSMENCF),"^",32),1:$select(IsWin:"c:\WINDOWS\Temp",1:"/usr/tmp"))
	set conexaoSegura=+$piece($get(^%CSMENCF),"^",77)
	;
	; Verifica se utiliza conexão segura (SSL/TLS)
	if "123"[conexaoSegura {
		quit $$EnviarEmailSeguro(subject,.mesg,smtpdomain,smtpport,from,.destinatario,.attachfile,userSMTP,passSMTP,tipoTexto,emailConfirm,%cswDisplayFrom,$get(replyTo),conexaoSegura)
	}
	;
	set SMTP=##class(%Net.SMTP).%New()
	if $get(userSMTP)'=""&&($get(passSMTP)'="") do
	. set AUTH=##class(%Net.Authenticator).%New()
	. set AUTH.UserName=userSMTP
	. set AUTH.Password=passSMTP
	. set SMTP.authenticator=AUTH
	set SMTP.smtpserver=smtpdomain
	set SMTP.port=smtpport
	;
	set MSG=##class(%Net.MailMessage).%New()
	set MSG.From=$get(%cswDisplayFrom)_"<"_from_">"
	if $get(replyTo)'="" set MSG.ReplyTo = replyTo
	if ($get(emailConfirm)=1) do
	. do MSG.Headers.SetAt($random(1000000000000000),"Message-ID")
	. do MSG.Headers.SetAt(""""_from_""" <"_from_">","Disposition-Notification-To")
	;
	; STRING - Tratamento na String caso seja passado um endereço separado por ;
	if ($get(destinatario)'="")&&($get(destinatario)'[";")  do
	. set sc=$$VerEmail^%CSUTICSP(destinatario)
	. if $$$ISERR(sc) quit
	. else  do MSG.To.Insert(destinatario)
	;	
	if $$$ISERR(sc) quit sc
	;		
	if $get(destinatario)[";"  do
	. for i=1:1:$length(destinatario,";") do
	. . if $piece(destinatario,";",i)'="" set sc=$$VerEmail^%CSUTICSP($piece(destinatario,";",i))
	. . if $$$ISERR(sc) quit
	. . else  if $piece(destinatario,";",i)'="" do MSG.To.Insert($piece(destinatario,";",i)) 
	;	
	if $$$ISERR(sc) quit sc
	;
	; VETOR - Tratamento na String caso seja passado um endereço separado por ;
	;	
	for  set linha=$order(destinatario($get(linha))) quit:linha=""!(sc'=1)  do
	. if $get(destinatario($get(linha)))'[";" do 
	. . set sc=$$VerEmail^%CSUTICSP($get(destinatario($get(linha))))
	. . if $$$ISERR(sc) quit
	. . else  do MSG.To.Insert($get(destinatario($get(linha))))
	. else  do
	. . for i=1:1:$length($get(destinatario($get(linha))),";") do
	. . . if ($piece($get(destinatario($get(linha))),";",i)'="")  do 
	. . . . set sc=$$VerEmail^%CSUTICSP($piece($get(destinatario($get(linha))),";",i))
	. . . . if $$$ISERR(sc) quit
	. . . . else  do MSG.To.Insert($piece($get(destinatario($get(linha))),";",i)) 
	;
	if $$$ISERR(sc) quit sc
	;
	set MSG.Subject=subject
	;
	if $get(attachfile)'="" do
	. set sc=$$AttachStream(attachfile,.MSG)
	;
	for  set cid=$order(attachfile($get(cid))) quit:cid=""  do
	. set sc=$$AttachStream(attachfile($get(cid)),.MSG)
	;
	if $get(tipoTexto)=1 set MSG.IsHTML=1
	for  set linha=$order(mesg($get(linha))) quit:linha=""  do
	. do MSG.TextData.Write($get(mesg(linha)))
	. do MSG.TextData.Write($char(13,10))
	if $order(mesg(linha))="" do MSG.TextData.Write(mesg)
	if $$$ISERR(sc) quit sc
	set sc=SMTP.Send(MSG)
	if $$$ISERR(sc) quit sc
	quit $$$OK
	;
	; Envia e-mail seguro
	;
EnviarEmailSeguro(subject,msg,host,port,from,to,attachFile,user,password,isHTML,emailConfirm,displayFrom,replyTo,conexaoSegura)	;
	new IsWin,barra,nomeArq,toFormat,sc,attachFileFormat,tabParam
	set IsWin=$zversion["Windows"
	set barra=$select(IsWin:"\",1:"/")
	;
	do CriarArqMensagem(.msg,.nomeArq,subject)
	set sc=$$GetDestinatarios(.to,.toFormat)
	if $$$ISERR(sc) quit sc
	set sc=$$GetAttachFile(.attachFile,.attachFileFormat)
	if $$$ISERR(sc) quit sc
	;
	set tabParam(1)=nomeArq
	set tabParam(2)=host
	set tabParam(3)=port
	set tabParam(4)=from
	set tabParam(5)=toFormat
	set tabParam(6)=attachFileFormat
	set tabParam(7)=user
	set tabParam(8)=password
	set tabParam(9)=isHTML
	set tabParam(10)=emailConfirm
	set tabParam(11)=displayFrom
	set tabParam(12)=$get(replyTo)
	set tabParam(13)=conexaoSegura
	;
	set sc=$$ExecutarArquivoJAR^CCUTIRG006($get(CE),13,.tabParam)
	if sc'=1 quit $$$ERROR(10000,"Falha no envio do e-mail!")
	;
	set sc=##class(%File).Delete(nomeArq)
	quit $$$OK
	;
	; Cria arquivo com o corpo do e-mail
	;
CriarArqMensagem(msg,nomeArq,subject)	;
	new fileBodyEmail,linha,sc
	set nomeArq=$$caminhoTmp^%CSUTICI()_"bodyEmail"_$$$job_".txt"
	set fileBodyEmail=##class(%File).%New(nomeArq)
	set sc=fileBodyEmail.Open("WN:/IOTABLE=""UTF8""")
	do fileBodyEmail.WriteLine($get(subject))
	for {
		set linha=$order(msg($get(linha)))
		quit:linha=""
		do fileBodyEmail.WriteLine($get(msg(linha)))
	}
	if $order(msg(linha))="" do fileBodyEmail.WriteLine($get(msg))
	do fileBodyEmail.Close()
	set fileBodyEmail=""
	quit
	;
	; Busca destinatarios formatados com separador ","
	;
GetDestinatarios(destinatario,destFormat)	;
	new i,sc
	set destFormat=""
	set sc=1
	if ($get(destinatario)'="")&&($get(destinatario)'[";")  do
	. set sc=$$VerEmail^%CSUTICSP(destinatario)
	. if $$$ISERR(sc) quit
	. else  set destFormat=$select(destFormat="":destinatario,1:destFormat_","_destinatario)
	;	
	if $$$ISERR(sc) quit sc
	;		
	if $get(destinatario)[";"  do
	. for i=1:1:$length(destinatario,";") do
	. . if $piece(destinatario,";",i)'="" set sc=$$VerEmail^%CSUTICSP($piece(destinatario,";",i))
	. . if $$$ISERR(sc) quit
	. . else  if $piece(destinatario,";",i)'="" set destFormat=$select(destFormat="":$piece(destinatario,";",i),1:destFormat_","_$piece(destinatario,";",i)) 
	;	
	if $$$ISERR(sc) quit sc
	;
	; VETOR - Tratamento na String caso seja passado um endereço separado por ;
	;	
	for  set linha=$order(destinatario($get(linha))) quit:linha=""!(sc'=1)  do
	. if $get(destinatario($get(linha)))'[";" do 
	. . set sc=$$VerEmail^%CSUTICSP($get(destinatario($get(linha))))
	. . if $$$ISERR(sc) quit
	. . else  set destFormat=$select(destFormat="":$get(destinatario($get(linha))),1:destFormat_","_$get(destinatario($get(linha))))
	. else  do
	. . for i=1:1:$length($get(destinatario($get(linha))),";") do
	. . . if ($piece($get(destinatario($get(linha))),";",i)'="")  do 
	. . . . set sc=$$VerEmail^%CSUTICSP($piece($get(destinatario($get(linha))),";",i))
	. . . . if $$$ISERR(sc) quit
	. . . . else  set destFormat=$select(destFormat="":$piece($get(destinatario($get(linha))),";",i),1:destFormat_","_$piece($get(destinatario($get(linha))),";",i)) 
	quit $$$OK
	;
	; Busca arquivos anexo formatados com separador ","
	;
GetAttachFile(attachFile,attachFileFormat)	;
	new i
	;
	set attachFileFormat=""
	if $get(attachFile)'="" do
	. set attachFileFormat=$select(attachFileFormat="":attachFile,1:attachFileFormat_","_attachFile)
	;
	for  set i=$order(attachFile($get(i))) quit:i=""  do
	. set attachFileFormat=$select(attachFileFormat="":attachFile($get(i)),1:attachFileFormat_","_attachFile($get(i)))
	set attachFileFormat=""""_attachFileFormat_""""
	quit $$$OK
	;
	;
	;
AttachStream(attachfile,Msg)	;
 	new msg,file,stream,sc,IsWin,arquivo,dir,sep
 	set msg=Msg.AttachNewMessage(),IsWin=$zversion["Windows"
 	set sep=$select(IsWin:"\",1:"/")
 	if $extract(attachfile,$length(attachfile))=sep set attachfile=$extract(attachfile,1,$length(attachfile)-1)
 	set dir=$piece(attachfile,sep,1,$length(attachfile,sep)-1)
	set arquivo=$piece(attachfile,sep,$length(attachfile,sep))
	set sc=msg.AttachFile(dir,arquivo,1)
	if sc'=1 quit $$$ERROR(10000,sc)
  	do msg.%Close()
	quit $$$OK
	;
	; Incluir Arquivo Serial
	;
AttachFile(attachfile,attachtype,separador,dev)	;
	new narq,error,line,stream set narq=$translate(attachfile,"/","\")
	set narq=$piece(narq,"\",$length(narq,"\"))
	set $ztrap="attachError"
	set sc=1
	if '##class(%File).Exists(attachfile) quit $$$ERROR(1000,"Arquivo para anexo não existe!")
	do MESS("")
	do MESS("--"_separador)
	if attachtype=0 {
		do MESS("Content-Type: text/plain;name="""_narq_"""")
		do MESS("Content-Transfer-Encoding: 7bit")  ; O.S. 38019
	} else {
		if ($zconvert($piece(narq,".",2),"l")="xml"){
			do MESS("Content-Type: text/xml;name="""_narq_"""")
		} else {	
			do MESS("Content-Type: application/octet-stream;Charset=ISO-8859-1;name="""_narq_"""")
		}
		do MESS("Content-Transfer-Encoding: base64")
	}
	do MESS("Content-Disposition: attachment;filename="""_narq_"""")
	do MESS("")
	set stream=##class(%FileBinaryStream).%New()
	set stream.Filename=attachfile
	while 'stream.AtEnd {
		
		if attachtype=0 {
			set line=stream.Read(254)
			do MESS2(line)
		} else {
			set line=stream.Read(63)
			use dev write $system.Encryption.Base64Encode(line),!
		}
	}
	set stream=""
	do MESS(CRLF)
	set $ztrap="smtperr"
	if sc'=1 {
		do $system.Status.DecomposeStatus(sc,.error) 
		set FailureReason=$get(error(1)) 
		quit 0
	}
	use dev write ! use 0
	quit $$$OK
	;
	; tratamento de erro para inclusão de arquivo
	;
attachError	;
	//quit 1
	set FailureReason="Erro ao adicionar o anexo: "_$zerror
	close dev quit 1
	; csw:csp:naoconverter
]]></Routine>
</Export>
