Приложение «Почтовый архив» с использованием базы данных.
<database component-id="mailExm" order="last"> <db version="1"> CREATE TABLE parameters( id INTEGER NOT NULL AUTO_INCREMENT , name VARCHAR(100) NOT NULL , value VARCHAR(3000) NOT NULL , modified_date DATETIME NOT NULL , PRIMARY KEY (id) ); </db> </database>
<AppXML title="Почтовый архив" icon="res:mail_earth.png" log-modifying-date="true" default-class-name="Lib" language="ru" ini-storage="file"> <system> <connect type="h2" login="sa" password="" alias="file:.data/MailExample" connect="true"/> <include file="db.appxml"/> </system> <main> <window id="mainWindow" location="center" height="600" width="850"> <oncreated> destaMailPanel:mainWindow; </oncreated> <toolbar> <toolbaritem text="Настройки"> <onaction> destaMailParameters.show = true; </onaction> </toolbaritem> </toolbar> </window> </main> <common> <include file="biz.desta.jlib.standartComponents.mailcollector.appxml"/> <panel id="destaMailPanel"> <oncreated> destaGetSource.execute = true; if(length(destaGetSource) > 0){ if (destaGetSource[0][1] == 'mail'){ destaMailCol.source-type = "mail"; destaGetServer.execute = true; destaGetLogin.execute = true; destaGetPassword.execute = true; destaMailCol.host = destaGetServer[0][1]; destaMailCol.login = destaGetLogin[0][1]; destaMailCol.password = destaGetPassword[0][1]; } else { destaGetDir.execute = true; destaMailCol.source-type = "dir"; destaMailCol.source-dir = destaGetDir[0][1]; } destaMailCol.connect = true; destaMailView.refresh = "2"; if (destaMailCol.amount > 0){ msg("Принятых сообщений " + destaMailCol.amount + "!"); } } </oncreated> <splitter type="vertical" a-id="split_1" b-id="split_2" position="center" location="250"> <panel id="dmv" position="split_1.center"> <panel id="tool" position="top"> <oncreated> destaMailToolbar:tool; </oncreated> </panel> <oncreated> destaMailView:dmv; </oncreated> </panel> <panel position="split_2.center"> <panel position="top" height="40"> <panel layout="flow" align="left" gap="3" position="top"> <label id="destaFromLabel" text="От:" font-style="bold"/> <label id="destaToLabel" text="Кому:" font-style="bold"/> </panel> <panel layout="flow" align="left" gap="3"> <label id="destaSubjectLabel" text="Тема:" font-style="bold"/> </panel> </panel> <splitter type="horizontal" a-id="a_1" b-id="a_2" position="center"> <panel id="a1" position="a_1.center"> <oncreated> destaAttachView:a1; </oncreated> </panel> <panel id="a2" position="a_2.center"> <oncreated> destaDetailEMail:a2; </oncreated> </panel> </splitter> </panel> </splitter> </panel> <window id="destaSendMailWindow" title="Создать сообщение" location="center" width="600" height="400"> <oncreated> <![CDATA[ if (this.param:answer == 1){ if(this.param:text != ""){ body.value = "---Оригинальный текст---\n" + this.param:text; } to.value = substr(this.param:to, pos('<', this.param:to));; to_name.value = substr(this.param:to, 0, pos('<', this.param:to)); subject.value = "Re: " + this.param:subject; } ]]> </oncreated> <toolbar scale="28" border="line:gray"> <toolbaritem id="sendMail" icon="res:mail_send.png" hint="Отправить сообщение"> <onaction> <![CDATA[ var problem = 0; destaGetServer.execute = true; destaGetLogin.execute = true; destaGetPassword.execute = true; destaGetFrom.execute = true; destaGetFromName.execute = true; destaMailCol.host = destaGetServer[0][1]; destaMailCol.login = destaGetLogin[0][1]; destaMailCol.password = destaGetPassword[0][1]; destaMailCol.send-from = destaGetFrom[0][1]; destaMailCol.send-from-name = destaGetFromName[0][1]; if (!to.empty){ destaMailCol.send-to = to.value; }else{ msg('Не удается отправить данное сообщение!\n Необходимо указать адрес получателя!'); problem = 1; } destaMailCol.send-to-name = to_name.value; destaMailCol.send-cc = cc.value; destaMailCol.send-cc-name = cc_name.value; destaMailCol.send-bcc = bcc.value; destaMailCol.send-bcc-name = bcc_name.value; destaMailCol.send-subject = subject.value; destaMailCol.send-body = body.value; if (!attach.empty){ destaMailCol.send-attach = attach.value; } if (problem == 0){ destaMailCol.send = true; destaSendMailWindow.close = true; } ]]> </onaction> </toolbaritem> </toolbar> <panel> <panel position="top" margin="10"> <panel layout="flow" align="left" position="top" gap="3"> <string id="to" text="Кому:" width="360" value-type="email" value1="irina.kuneva@desta.com.ua"/> <string id="to_name" text="Имя" width="203" value1="Ирина Кунева"/> </panel> <panel> <panel layout="flow" align="left" position="top" gap="3"> <string id="cc" text="Копия:" width="360" value-type="email"/> <string id="cc_name" text="Имя" width="203"/> </panel> <panel> <panel layout="flow" align="left" position="top" gap="3"> <string id="bcc" text="Скрытая:" width="360" value-type="email"/> <string id="bcc_name" text="Имя" width="203"/> </panel> <panel> <panel layout="flow" align="left" position="top" gap="3"> <string id="subject" text="Тема:" width="570" length="256"/> </panel> <panel layout="flow" align="left" gap="3"> <string id="attach" text="Присоединить:" width="570" length="5000" browse="file"/> </panel> </panel> </panel> </panel> </panel> <panel> <memo id="body" margin-left="10" margin-right="12"/> </panel> </panel> </window> <mailcollector id="destaMailCol" store="db" count="1"/> <!-- Окно параметров для EMAIL --> <edit id="destaMailParameters" order="column" title-mode='Параметры для EMAIL' ok-button-title="Сохранить" repeat-visible="false" repeat="false"> <onbeforeedit> destaGetSource.execute = true; for (sr in destaGetSource){ if (sr[1] != null or sr[1] != ''){ mail_source.init-value = sr[1]; mail_source_id.init-value = sr[0]; } } destaGetDir.execute = true; for (sr in destaGetDir){ if (sr[1] != null or sr[1] != ''){ mail_dir.init-value = sr[1]; mail_dir_id.init-value = sr[0]; } } destaGetServer.execute = true; for (sr in destaGetServer){ if (sr[1] != null or sr[1] != ''){ mail_server.init-value = sr[1]; mail_server_id.init-value = sr[0]; } } destaGetLogin.execute = true; for (cn in destaGetLogin){ if (cn[1] != null or cn[1] != ''){ mail_login.init-value = cn[1]; mail_login_id.init-value = cn[0]; } } destaGetPassword.execute = true; for (cd in destaGetPassword){ if (cd[1] != null or cd[1] != ''){ mail_password.init-value = cd[1]; mail_password_id.init-value = cd[0]; } } destaGetFrom.execute = true; for (f in destaGetFrom){ if (f[1] != null or f[1] != ''){ mail_from.init-value = f[1]; mail_from_id.init-value = f[0]; } } destaGetFromName.execute = true; for (nf in destaGetFromName){ if (nf[1] != null or nf[1] != ''){ mail_from_name.init-value = nf[1]; mail_from_name_id.init-value = nf[0]; } } </onbeforeedit> <edititem text="Источник приема сообщений" order="freeform"> <edititem id="mail_source" type="radio"> <radioitem name="Сервер" value="mail" default="true"/> <radioitem name="Директория" value="dir"/> <oninited> if (this.init-value == 'mail'){ mail_group.enable = true; dir_group.enable = false; }else{ mail_group.enable = false; dir_group.enable = true; } </oninited> <onselected> if (this.value == 'mail'){ mail_group.enable = true; dir_group.enable = false; }else{ mail_group.enable = false; dir_group.enable = true; } </onselected> </edititem> <edititem id="mail_source_id" visible="false" type="number" /> </edititem> <edititem y="new" id="mail_group" text="Атрибуты подключения к серверу"> <edititem id="mail_server" text="Server" text-position="left" value-type="plain"/> <edititem id="mail_server_id" visible="false" type="number" /> <edititem id="mail_login" text="Login" text-position="left" value-type="plain"/> <edititem id="mail_login_id" visible="false" type="number" /> <edititem id="mail_password" text="Password" text-position="left" value-type="hidden"/> <edititem id="mail_password_id" visible="false" type="number" /> </edititem> <edititem y="new" id="dir_group" text="Путь к папке с почтовыми сообщениями"> <edititem id="mail_dir" width="470" length="256" browse="dir" value-type="filename"/> <edititem id="mail_dir_id" visible="false" type="number" /> </edititem> <edititem y="new" id="mail_send" text="Настройка отправки сообщений"> <edititem id="mail_from" text="От кого" text-position="left" value-type="email"/> <edititem id="mail_from_id" visible="false" type="number" /> <edititem id="mail_from_name" text="От кого (Имя)" text-position="left" /> <edititem id="mail_from_name_id" visible="false" type="number" /> </edititem> <onaction> destaGetMailParameters{'id' => mail_source_id.value}; if(length(destaGetMailParameters) > 0){ destaUpdateMailParameters{'value' => mail_source.value, 'id' => mail_source_id.value}; destaUpdateMailParameters.execute = true; }else{ destaInsertMailParameters{'name' => 'mail_source', 'value' => mail_source.value}; destaInsertMailParameters.execute = true; } if(mail_server.changed){ destaGetMailParameters{'id' => mail_server_id.value}; if(length(destaGetMailParameters) > 0){ destaUpdateMailParameters{'value' => mail_server.value, 'id' => mail_server_id.value}; destaUpdateMailParameters.execute = true; }else{ destaInsertMailParameters{'name' => 'mail_server', 'value' => mail_server.value}; destaInsertMailParameters.execute = true; } } if(mail_login.changed){ destaGetMailParameters{'id' => mail_login_id.value}; if (length(destaGetMailParameters) > 0){ destaUpdateMailParameters{'value' => mail_login.value, 'id' => mail_login_id.value}; destaUpdateMailParameters.execute = true; }else{ destaInsertMailParameters{'name' => 'mail_login', 'value' => mail_login.value}; destaInsertMailParameters.execute = true; } } if(mail_password.changed){ destaGetMailParameters{'id' => mail_password_id.value}; if (length(destaGetMailParameters) > 0){ destaUpdateMailParameters{'value' => mail_password.value, 'id' => mail_password_id.value}; destaUpdateMailParameters.execute = true; }else{ destaInsertMailParameters{'name' => 'mail_password', 'value' => mail_password.value}; destaInsertMailParameters.execute = true; } } if(mail_dir.changed){ destaGetMailParameters{'id' => mail_dir_id.value}; if(length(destaGetMailParameters) > 0){ destaUpdateMailParameters{'value' => mail_dir.value, 'id' => mail_dir_id.value}; destaUpdateMailParameters.execute = true; }else{ destaInsertMailParameters{'name' => 'mail_dir', 'value' => mail_dir.value}; destaInsertMailParameters.execute = true; } } if(mail_from.changed){ destaGetMailParameters{'id' => mail_from_id.value}; if(length(destaGetMailParameters) > 0){ destaUpdateMailParameters{'value' => mail_from.value, 'id' => mail_from_id.value}; destaUpdateMailParameters.execute = true; }else{ destaInsertMailParameters{'name' => 'mail_from', 'value' => mail_from.value}; destaInsertMailParameters.execute = true; } } if(mail_from_name.changed){ destaGetMailParameters{'id' => mail_from_name_id.value}; if(length(destaGetMailParameters) > 0){ destaUpdateMailParameters{'value' => mail_from_name.value, 'id' => mail_from_name_id.value}; destaUpdateMailParameters.execute = true; }else{ destaInsertMailParameters{'name' => 'mail_from_name', 'value' => mail_from_name.value}; destaInsertMailParameters.execute = true; } } </onaction> </edit> <query id="destaGetMailParameters"> select * from parameters where id = %id </query> <query id="destaInsertMailParameters"> insert into parameters(name, value, modified_date) values('%name', '%value', now()); </query> <query id="destaUpdateMailParameters"> update parameters set value = '%value' where id = %id </query> <query id="destaGetSource"> select id, value from parameters where name = 'mail_source' </query> <query id="destaGetDir"> select id, value from parameters where name = 'mail_dir' </query> <query id="destaGetServer"> select id, value from parameters where name = 'mail_server' </query> <query id="destaGetLogin"> select id, value from parameters where name = 'mail_login' </query> <query id="destaGetPassword"> select id, value from parameters where name = 'mail_password' </query> <query id="destaGetFrom"> select id, value from parameters where name = 'mail_from' </query> <query id="destaGetFromName"> select id, value from parameters where name = 'mail_from_name' </query> <query id="destaDetailsMail"> select mail_source_text from sys_desta_mail where id = %mail_id </query> <query id="destaToMail"> select value from sys_desta_mail_header where name = 'To' and mail_id = %mail_id </query> <query id="destaAttachQuery" load-blob="true"> select filename, contents from sys_desta_mail_attach where id = %attach_id </query> <query id="destaGetMailText"> select mail_source_text from sys_desta_mail where id = %mail_id </query> <query id="destaGetMailFrom"> select sys_desta_mail_header.value from sys_desta_mail_header join sys_desta_mail on sys_desta_mail.id = sys_desta_mail_header.mail_id where sys_desta_mail.id = %mail_id and sys_desta_mail_header.name = 'From' </query> <query id="destaGetMailSubject"> select sys_desta_mail_header.value from sys_desta_mail_header join sys_desta_mail on sys_desta_mail.id = sys_desta_mail_header.mail_id where sys_desta_mail.id = %mail_id and sys_desta_mail_header.name = 'Subject' </query> <fn id="downLoadMail"> destaGetSource.execute = true; if (length(destaGetSource) > 0){ if (destaGetSource[0][1] == 'mail'){ destaMailCol.source-type = "mail"; destaGetServer.execute = true; destaGetLogin.execute = true; destaGetPassword.execute = true; if (length(destaGetServer) > 0){ destaMailCol.host = destaGetServer[0][1]; if(length(destaGetLogin) > 0){ destaMailCol.login = destaGetLogin[0][1]; if (length(destaGetPassword) > 0){ destaMailCol.password = destaGetPassword[0][1]; }else{ msg('Не задан пароль. Проверьте параметры подключения!'); } }else{ msg('Не задан логин. Проверьте параметры подключения!'); } }else{ msg('Не задан сервер. Проверьте параметры подключения!'); } } else { destaGetDir.execute = true; destaMailCol.source-type = "dir"; destaMailCol.source-dir = destaGetDir[0][1]; } destaMailCol.connect = true; }else{ msg('Не могу найти источник приема сообщений!\nПроверьте настройки для почтового ящика!'); } </fn> <slaveview id="destaAttachView" margin="0" width="100" header-visible="false" statusbar-visible="false" sql="select sys_desta_mail_attach.id, sys_desta_mail_attach.filename from sys_desta_mail_attach where sys_desta_mail_attach.mail_id = @mail_id #refresh# order by filename"> <toolbar visible="false"/> <onaction> <![CDATA[ var fname = ""; destaAttachQuery{'attach_id' => this[this.current-row]['id']}; destaAttachQuery.execute = true; fname = destaAttachQuery[0][0]; if (!isCorrectFileName(fname)){ msg('Имя файла не должно быть пустым или содержать следующие символы: \n \/:*?"<>|'); } else { fname = getTmpDir() + fname; fwrite(fname, destaAttachQuery[0][1]); execute(fname); fremove(fname); } ]]> </onaction> </slaveview> <memo id="destaDetailEMail" enable="false" margin="0"/> <toolbar id="destaMailToolbar" scale="28"> <toolbaritem id="addBtn" visible="false"/> <toolbaritem id="newMail" icon="res:mail_add.png" hint="Создать сообщение"> <onaction> destaSendMailWindow.param:answer = 0; destaSendMailWindow; </onaction> </toolbaritem> <toolbaritem id="answerMail" icon="res:mail_edit.png" hint="Ответить отправителю"> <onaction> //......... var mail_text = ""; var mail_from = ""; var mail_subject = ""; var mail_id = ""; if (destaMailView.current-row > -1){ mail_id = destaMailView[destaMailView.current-row]['id']; destaGetMailText{'mail_id' => mail_id}; destaGetMailText.execute = true; destaGetMailFrom{'mail_id' => mail_id}; destaGetMailFrom.execute = true; destaGetMailSubject{'mail_id' => mail_id}; destaGetMailSubject.execute = true; mail_text = destaGetMailText[0][0]; mail_from = destaGetMailFrom[0][0]; mail_subject = destaGetMailSubject[0][0]; destaSendMailWindow.param:answer = 1; destaSendMailWindow.param:text = mail_text; destaSendMailWindow.param:to = mail_from; destaSendMailWindow.param:subject = mail_subject; destaSendMailWindow; } else { msg('Не выбрано письмо для ответа!'); } </onaction> </toolbaritem> <toolbaritem id="delBtn" visible="true" icon="res:mail_delete.png" hint="Удалить сообщение"/> <toolbaritem id="mailDownload" icon="res:mail_download.png" hint="Загрузить почту с сервера"> <onaction> downLoadMail(); destaMailView.refresh = "2"; </onaction> </toolbaritem> </toolbar> <view id="destaMailView" margin="0" grid-mode="on" grid-color="lightGray" toolbar-visible="false" sql="select sys_desta_mail.id as id, ifnull(trim(substr(from_header.value, 0, instr(from_header.value, '<') - 1)), '') as from_mail, ifnull(trim(substr(to_header.value, 0, instr(to_header.value, '<') - 1)), '') as to_mail, ifnull(subject_header.value, '') as subject, parsedatetime(date_header.value, 'EEE, dd MMM yyyy HH:mm:ss', 'en') as date from sys_desta_mail left join (select value, mail_id from sys_desta_mail_header where name = 'Date') date_header on (date_header.mail_id = sys_desta_mail.id) left join (select value, mail_id from sys_desta_mail_header where name = 'From') from_header on (from_header.mail_id = sys_desta_mail.id) left join (select value, mail_id from sys_desta_mail_header where name = 'To') to_header on (to_header.mail_id = sys_desta_mail.id) left join (select value, mail_id from sys_desta_mail_header where name = 'Subject') subject_header on (subject_header.mail_id = sys_desta_mail.id) #refresh# order by modified_date desc" id-field="id" table-name="sys_desta_mail" slave="destaAttachView" slave-parameters="mail_id:id"> <columns> <column name="from_mail" text="От" as="memo" width="200"/> <column name="to_mail" visible="false"/> <column name="subject" text="Тема" width="130" as="memo"/> <column name="date" text="Получено" as="datetime" mask="dd.MM.yy HH:mm" width="70"/> </columns> <onselected> if (this.current-row > -1){ if (this[this.current-row]['from_mail'] == ""){ destaFromLabel.value = " "; }else{ destaFromLabel.value = this[this.current-row]['from_mail']; } if (this[this.current-row]['to_mail'] == ""){ destaToLabel.value = " "; }else{ destaToLabel.value = this[this.current-row]['to_mail']; } if (this[this.current-row]['subject'] == ""){ destaSubjectLabel.value = " "; }else{ destaSubjectLabel.value = this[this.current-row]['subject']; } destaDetailsMail{'mail_id' => this[this.current-row]['id']}; destaDetailsMail.execute = true; destaDetailEMail.value = destaDetailsMail.value; } </onselected> <onafterdelete> destaFromLabel.value = " "; destaToLabel.value = " "; destaSubjectLabel.value = " "; </onafterdelete> </view> </common> </AppXML>