/* InterDaemon.cc 25 July 2001 Robin Whittle altered SORTARRIVAL to SORTDATE on line ~796 See "RW". */ /* ==================================================================== * Copyright (c) 2000 University of Valencia. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. All advertising materials mentioning features or use of this * software must display the following acknowledgment: * "This product includes software developed by the University * of Valencia." * * 4. The names "Postman" must not be used to endorse or promote products * derived from this software without prior written permission. * * 5. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by the University of Valencia" * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ITS CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * ==================================================================== */ #include "InterDaemon.h" #include "Config.h" #include "Utils.h" #include "XSocket.h" #include "HTML.h" #include "Language.h" #include "IMAP.h" #include "SendMSG.h" #include "UserOptions.h" #include "Configuration.h" #include "Addressbook.h" #include "rutinas_db.h" #include "PsTitle.h" #include "Cookie.h" XSocket *serversocket; HTML *html; Language *L; IMAP *imap; StringList *SL; TBuffer UserDir; Configuration *Conf; TSBuffer user, ipclient, lastconnid; static int ServerCounter = 1; static long int TotalLogins = 1; pid_t MainServerPid; int LockFileDescriptor; Cookie *cookie; void procsignals (int signal_type) { TSBuffer abuf; switch (signal_type) { /* TIMEOUT. Alarm signal. Kill the child server. */ case SIGALRM: LOG ("Timeout for IP=%s, user=%s", ipclient, user); if (ALLOW_SEVERAL_CONNS == 0) {DeleteFile (ReturnUserLockFileName (user));} strncpy (abuf, make_session_socket (user, lastconnid), CSMALLBUFFER); DeleteFile (abuf); exit (0); break; /* ZOMBIES. This waits for all children, so that they don't become zombies. */ case SIGCHLD: int pid, status; --ServerCounter; while ((pid = wait3(&status, WNOHANG, NULL)) > 0); break; /* SIGHUP. Reload configuration. */ case SIGHUP: bool b; b = Conf->reload(); if (b == true) LOG ("Reloading configuration. Successfull."); else LOG ("Error reloading configuration."); ServerCounter = getNumChilds (); LOG (" ServerCounter is now=%ld", ServerCounter); break; /* SIGTERM. Normal kill sent to daemon*/ case SIGTERM: if (getpid () == MainServerPid) { LOG ("Main server is down."); } else { LOG ("SIGTERM received for IP=%s, user=%s", ipclient, user); if (ALLOW_SEVERAL_CONNS == 0) {DeleteFile (ReturnUserLockFileName (user));} strncpy (abuf, make_session_socket (user, lastconnid), CSMALLBUFFER); DeleteFile (abuf); } exit (0); break; /*SIGSEGV. Invalid memory reference*/ case SIGSEGV: fprintf (stderr, "Received signal SIGSEGV for IP=%s, user=%s\n", ipclient, user); exit (1); break; /*SIGBUS. Bus error (bad memory access)*/ case SIGBUS: fprintf (stderr, "Received signal SIGBUS for IP=%s, user=%s\n", ipclient, user); exit (1); break; /* SIGUSR1. Program signal*/ case SIGUSR1: if (getpid () == MainServerPid) { LOG ("Main server is down."); } else { LOG ("SIGUSR1 received for IP=%s, user=%s", ipclient, user); strncpy (abuf, make_session_socket (user, lastconnid), CSMALLBUFFER); DeleteFile (abuf); } exit (0); break; /* SIGUSR2. Program signal*/ case SIGUSR2: ++ServerCounter; ++TotalLogins; break; } } int main (int argc, char **argv, char **envp) { int listensock = -1; /* So that we can close sockets on ctrl-c */ struct sigaction act1, oldact1, act2, oldact2, act3, oldact3, act4, oldact4, act5, oldact5, act6, oldact6, act7, oldact7; TSBuffer connid, stlang, stcmd, pw, parm3, parm4, allparms, allparms2, imapserver; TBuffer linea; int cs, cmd, validator, pageid, lastcmd; bool VALIDLOGIN; char *fnsocket; initsetproctitle(argc, argv, envp); MainServerPid = WritePidFile (); if (argc != 2) {printf ("Sintax is: interdaemon fileconfname\n"); exit (1);} Conf = new Configuration (argv[1], true); if (!Conf->ConfRead ()) {printf ("Error: %s do not exists.\n", argv[1]); exit (1);} umask (UMASK); OPENLOG(); LOG ("Main server is started."); Randomize (); SL = new StringList (); serversocket = new XSocket (); serversocket->ignore_pipe(); sigemptyset(&act1.sa_mask); act1.sa_flags = 0; act1.sa_handler = procsignals; sigaction(SIGCHLD, &act1, &oldact1); sigemptyset(&act2.sa_mask); act2.sa_flags = 0; act2.sa_handler = procsignals; sigaction(SIGHUP, &act2, &oldact2); sigemptyset(&act3.sa_mask); act3.sa_flags = 0; act3.sa_handler = procsignals; sigaction(SIGTERM, &act3, &oldact3); sigemptyset(&act4.sa_mask); act4.sa_flags = 0; act4.sa_handler = procsignals; sigaction(SIGUSR1, &act4, &oldact4); sigemptyset(&act5.sa_mask); act5.sa_flags = 0; act5.sa_handler = procsignals; sigaction(SIGSEGV, &act5, &oldact5); sigemptyset(&act6.sa_mask); act6.sa_flags = 0; act6.sa_handler = procsignals; sigaction(SIGBUS, &act6, &oldact6); sigemptyset(&act7.sa_mask); act7.sa_flags = 0; act7.sa_handler = procsignals; sigaction(SIGUSR2, &act7, &oldact7); cs = serversocket->do_server_unix (SOCK_STREAM, &listensock); //*** FROM HERE THE NEW CHILD! //Envio una senyal de login al padre para que incremente los contadores necesarios kill (MainServerPid, SIGUSR2); VALIDLOGIN = false; UserOptions *uo; Randomize (); serversocket->SetSock (cs); html = new HTML (serversocket); serversocket->Gets (linea, CMAXBUFFER); //login ini (connid, stlang, stcmd, allparms, allparms2, user, pw, parm3, parm4); initStr (imapserver); sscanf (linea, "%s %d %d %d %s %s %s %[^]]s", connid, &pageid, &validator, &lastcmd, stlang, ipclient, stcmd, allparms); xscanf (linea, connid, &pageid, &validator, &lastcmd, stlang, ipclient, stcmd, user, pw, imapserver, NULL); L = new Language (stlang); cmd = TranslateCmd (stcmd); if (CONVERTUSERNAMETOLOWERCASE == 1) {xlcase (user);} if (ServerCounter > Conf->getInt ("main", "maxconnallowed", 50)) { LOG ("Max connections allowed %d reached.", ServerCounter); html->MsgPage(L->get (MSG_TOO_MAX_CONN), stlang); fflush (stdout); exit (0); } if ((cmd != CMD_LOGIN) || (strcmp(connid, "-1") != 0) || (strcmp(user, "") == 0) || (strcmp(pw, "") == 0)) { html->ErrorPage(L->get (ERR_INV_PARMS)); fflush (stdout); exit (0); } if (ALLOW_SEVERAL_CONNS == 0) //NO simultaneous connections { long LOCKTIME, NOW, INTERVAL; LOCKTIME = GetTimeFromLockFileOpening (ReturnUserLockFileName (user)); NOW = time (NULL); INTERVAL = NOW - LOCKTIME; if ((INTERVAL <= MAX_TIME_BETWEEN_CONNS) && (LOCKTIME != -1)) { --ServerCounter; LOG ("Time minimum between connections. User '%s'. Exiting.", user); html->ErrorPage (L->get(MSG_MIN_TIMEBETWCONNS)); exit(0); } } strncpy (lastconnid, connid, CSMALLBUFFER); uo = new UserOptions (Conf->getString ("main", "usersbasepath", "/var/postman/users", CMAXBUFFER), user, imapserver); uo->setPageId (pageid); uo->set_use_javascript (Conf->getInt ("main", "use_javascript", 1)); html->setMAXMSGSFORPAGE (uo->getMsgsPerIndexPage()); imap = new IMAP (); imap->setMAXMSGSFORPAGE (uo->getMsgsPerIndexPage()); imap->setTimeout (Conf->getInt ("main", "timeout", 1200)); //******************************************************* //****************************************** LOGIN //ENTRADA VACIA EN CAMPO DE CGI imapserver //THIS LINE FOR AVOID THAT PROBLEM WITH OLD CACHED PAGES IN PROXIES (change v. 1.0 to 1.1) if ((imapserver == NULL) || (strcmp (imapserver, "") == 0) || (strcmp (imapserver, " ") == 0)) {strcpy (imapserver, "#");} if ((imapserver == NULL) || (strcmp (imapserver, "") == 0) || (strcmp (imapserver, " ") == 0)) { LOG ("IMAP server EMPTY. IP=%s, User '%s'. Exiting.", ipclient, user); html->ErrorPage (L->get(L_EMPTY_IMAPSERVER)); exit(0); } //ENTRADA # EN CAMPO DE CGI imapserver, SE MIRA EN LA DB PRIMERO else if ((strcmp (imapserver, "#") == 0) && (Conf->getInt ("main", "usedbforconf", 0) == 1)) { //EL USUARIO NO EXISTE EN LA DB if (exist_user (Conf->getString ("main", "dbfile", "/var/postman/postman.db", CMAXBUFFER), user) == 0) { TBuffer xbuf; strncpy (xbuf, Conf->getString ("main", "def_user_not_in_db", "", CMAXBUFFER), CMAXBUFFER); uo->setImapServer (Conf->getString (xbuf, "imapserver", "imap.xx.xx", CMAXIPNAME)); uo->setImapPort (Conf->getInt (xbuf, "imapport", DEFIMAPPORT)); uo->setMailDomain (Conf->getString (xbuf, "maildomain", "xx.xx", CMAXIPNAME)); uo->setSMTPServer (Conf->getString (xbuf, "smtpserver", "smtp.xx.xx", CMAXIPNAME)); } //EL USUARIO SI EXISTE EN LA DB else { int aimapport; IPNAME asmtpserver, amaildomain; db_get_data_from_user (Conf->getString ("main", "dbfile", "/var/postman/postman.db", CMAXBUFFER), user, imapserver, &aimapport, asmtpserver, amaildomain); uo->setImapServer (imapserver); uo->setImapPort (aimapport); uo->setSMTPServer (asmtpserver); uo->setMailDomain (amaildomain); } } //ENTRADA TEXTO EN CAMPO DE CGI imapserver else { //EXISTE LA SECCION imapserver if (Conf->IsThereSection (imapserver) == true) { uo->setImapServer (Conf->getString (imapserver, "imapserver", "imap.xx.xx", CMAXIPNAME)); uo->setImapPort (Conf->getInt (imapserver, "imapport", DEFIMAPPORT)); uo->setMailDomain (Conf->getString (imapserver, "maildomain", "xx.xx", CMAXIPNAME)); uo->setSMTPServer (Conf->getString (imapserver, "smtpserver", "smtp.xx.xx", CMAXIPNAME)); } //NO EXISTE LA SECCION imapserver EN EL FICHERO interdaemon.cfg else { //NO SE PERMITE LA ENTRADA SI NO EXISTE LA SECCION imapserver if (Conf->getInt ("main", "allowotherimapservers", 0) == 0) { LOG ("IMAP server '%s' is not allowed. User '%s'. Exiting.", imapserver, user); html->ErrorPage (L->get(L_NOTALLOWED_IMAPSERVER)); exit(0); } //SI SE PERMITE LA ENTRADA A CUALQUIER imapserver, PERO PUEDE QUE FUERZE ALGUNOS CAMPOS else { uo->setImapServer (imapserver); if (strcmp (Conf->getString ("*", "imapport", "*", CMAXIPNAME), "*") == 0) {uo->setImapPort (DEFIMAPPORT);} else {uo->setImapPort (Conf->getInt ("*", "imapport", DEFIMAPPORT));} if (strcmp (Conf->getString ("*", "smtpserver", "*", CMAXIPNAME), "*") == 0) {uo->setSMTPServer (imapserver);} else {uo->setSMTPServer (Conf->getString ("*", "smtpserver", "smtp.xx.xx", CMAXIPNAME));} if (strcmp (Conf->getString ("*", "maildomain", "*", CMAXIPNAME), "*") == 0) {uo->setMailDomain (imapserver);} else {uo->setMailDomain (Conf->getString ("*", "maildomain", "xx.xx", CMAXIPNAME));} } } } uo->setMailboxPrefix (Conf->getString (imapserver, "mailboxprefix", "", CMAXBUFFER)); if (strchr (uo->getImapServer (), '.') == NULL) { //strcat (imapserver, Conf->getString ("main", "defaultipdomain", ".xx.xx", CMAXIPNAME)); strcat (imapserver, Conf->getString ("main", "defaultipdomain", "", CMAXIPNAME)); uo->setImapServer (imapserver); } imap->setMailboxPrefix (Conf->getString (imapserver, "mailboxprefix", "", CMAXBUFFER)); imap->setPathToRemoteFolder (Conf->getString (imapserver, "remotepath", "", CMAXBUFFER)); VALIDLOGIN = imap->OpenMailbox (uo->getImapServer(), uo->getImapPort(), "INBOX", user, pw); //****************************************** FIN DE LOGIN //******************************************************* if (VALIDLOGIN == true) { if (ALLOW_SEVERAL_CONNS == 0) //NO simultaneous connections { TSBuffer lockfile; int res; strncpy (lockfile, ReturnUserLockFileName (user), CSMALLBUFFER); res = IsLocked (lockfile, &LockFileDescriptor); switch (res) { case 2: //NO EXISTE EL FICHERO DE LOCK LockFileDescriptor = CreateAndLockFile (lockfile); break; case 1: //SI HAY UN LOCK PA'FUERA LOG ("Lock file for user '%s'. Exiting.", user); html->ErrorPage (L->get(MSG_TOO_MAX_TRY_CONN)); exit(0); break; case 0: //NO HAY LOCK int thepid; LOG ("User %s, IP=%s already connected. Killing old connection.", user, ipclient); thepid = GetPIDFromLockFile(LockFileDescriptor); if (thepid >0) kill (thepid, SIGUSR1); EscribePIDenLockFile (LockFileDescriptor); break; }//switch }//if uo->InitStatusLine (); if (imap->getError()==true) {uo->setStatusLine (imap->getErrorString(), RED);} strncpy (UserDir, ReturnUsersDir(Conf->getString ("main", "usersbasepath", "/var/postman/users", CMAXBUFFER), user, uo->getImapServer ()), CMAXBUFFER); TSBuffer asb; char inicials[3]; inicials [0] = user[0]; inicials [1] = user[1]; inicials [2] = '\0'; strncpy (asb, Conf->getString ("main", "usersbasepath", "/var/postman/users", CSMALLBUFFER), CSMALLBUFFER);strcat (asb, "/"); strcat (asb, uo->getImapServer ()); if (CreateDir (asb, USERDIRMODE) == false) {html->ErrorPage(L->get (ERR_CREAT_USERDIR)); fflush (stdout); exit (0);} strcat (asb, "/"); strcat (asb, inicials); if (CreateDir (asb, USERDIRMODE) == false) {html->ErrorPage(L->get (ERR_CREAT_USERDIR)); fflush (stdout); exit (0);} if (CreateDir (UserDir, USERDIRMODE) == false) {html->ErrorPage(L->get (ERR_CREAT_USERDIR)); fflush (stdout); exit (0);} if (CreateDir ((char *)uo->getAttachDir(), USERATTACHSDIRMODE) == false) {html->ErrorPage(L->get (ERR_CREAT_USERATTACHSDIR)); fflush (stdout); exit (0);} uo->leeConf(); DelAllFilesFromDir ((char *)uo->getAttachDir()); strncpy (connid, make_session_id (imapserver), CSMALLBUFFER); strncpy (lastconnid, connid, CSMALLBUFFER); fnsocket = make_session_socket (user, connid); StringList *SL, *SL2; SL = new StringList (); SL2 = new StringList(); uo->setCurrentPosition (0, imap->getTotalMsgs ()); imap->setMAXMSGSFORPAGE (uo->getMsgsPerIndexPage()); imap->getHeaderList (uo->getBeginPage(), SL, user, uo->getMailDomain(), L->get (L_TO)); imap->getMailboxes (SL2, true); uo->setPageId(0); sprintf (linea, "%s 0 0 0 %s %s mb_index\n", connid, stlang, ipclient); uo->addLastStringCmd (linea); uo->setMailboxSize (imap->getMailboxSize()); cookie = new Cookie (user); if (Conf->getInt ("main", "use_cookies", 0) == 1) {html->printCookie(cookie->getSetFullCookieLine());} html->PrintIndexPage (stlang, "INBOX", user, connid, SL, SL2, uo); delete SL; delete SL2; serversocket->Close(); ClientDaemon (uo, user, imapserver, fnsocket); } else //ERROR: PW invalida, server not ready, port not open, ... { TSBuffer errmsg; strncpy (errmsg, imap->getErrorString(), CSMALLBUFFER); LOG ("%s (ipclient='%s', user='%s')", errmsg, ipclient, user); html->ErrorPage(errmsg); } serversocket->Close (); delete serversocket; delete uo; delete imap; delete L; delete SL; delete html; if (getpid () == MainServerPid) {LOG ("Main server is down.");} CLOSELOG(); return 0; } int ClientDaemon (UserOptions *uo, char *user, char *imapserver, char *fnsocket) { XSocket *ss; int cmd, connected_socket = ERROR_SOCKET, listensock = ERROR_SOCKET, validator, pageid, lastcmd; int cmd_conter; TSBuffer linea, connid, stlang, stcmd, allparms, allparms2, parm1, parm2, parm3, parm4, basepath; bool FINISHED, b, WasCreatedSentMailFolder = false; xulong nummsg, len; StringList *SL, *SLAttach, *SLAttachInfo, *SLAttachHeader, *SL2; struct sigaction actx, oldactx; SendMSG *sendmsg; //ALARM INSTALL, FOR TIMEOUT if (USETIMEOUT == 1) { sigemptyset(&actx.sa_mask); actx.sa_flags = 0; actx.sa_handler = procsignals; sigaction(SIGALRM, &actx, &oldactx); } FINISHED = false; cmd_conter = 0; ss = new XSocket (); ss->do_server_unix_only_bind (SOCK_STREAM, &listensock, fnsocket); LOG ("Login Ok IP=%s, user=%s, servercount=%d, totallogins=%ld", ipclient, user, ServerCounter + 2, TotalLogins); UnlockAndCloseFile (LockFileDescriptor); sm_setproctitle (PROGNAME, true, user); while (FINISHED == false) { //LOOP FOR ACCEPTS OF cgis //SWITCH ON THE ALARM uo->setTimeout (Conf->getInt ("main", "timeout", 1200)); if (USETIMEOUT == 1) alarm ((xuint)(uo->getTimeout())); strncpy (basepath, Conf->getString ("main", "usersbasepath", "/var/postman/users", CSMALLBUFFER), CSMALLBUFFER); connected_socket = accept(listensock, NULL, NULL); if (connected_socket < 0) { if (errno != EINTR) {perror("accept"); close(listensock); return (ERROR_SOCKET);} else {continue;} } ss->SetSock (connected_socket); ss->Gets (linea, CMAXBUFFER); ++cmd_conter; html = new HTML (ss); html->setMAXMSGSFORPAGE (uo->getMsgsPerIndexPage()); imap->setMAXMSGSFORPAGE (uo->getMsgsPerIndexPage()); ini (connid, stlang, stcmd, allparms, allparms2, parm1, parm2, parm3, parm4); sscanf (linea, "%s %d %d %d %s %s %s %[^]]s", connid, &pageid, &validator, &lastcmd, stlang, ipclient, stcmd, allparms); //sscanf (linea, "%s %d %d %d %s %s %s %s %[^]]s", connid, &pageid, &validator, &lastcmd, stlang, ipclient, stcmd, parm1, allparms2); xscanf (linea, connid, &pageid, &validator, &lastcmd, stlang, ipclient, stcmd, parm1, allparms2, NULL, NULL); xscanf (linea, connid, &pageid, &validator, &lastcmd, stlang, ipclient, stcmd, parm1, parm2, parm3, parm4); uo->setPageId (pageid); uo->setLastCmd(lastcmd); SL = new StringList (); SL2 = new StringList (); SLAttach = new StringList (); SLAttachHeader = new StringList (); SLAttachInfo = new StringList (); cmd = TranslateCmd (stcmd); strncpy (lastconnid, connid, CSMALLBUFFER); /*****/ //DEBUG (linea); if (!IsGoodValidator (cmd, validator, uo->getValidator())) {cmd = CMD_INVALIDPAGE;} if (imap->Ping () == false) {imap->Reconnect();} uo->addLastStringCmd (linea); switch (cmd) { case (CMD_CHECK_COOKIE): { if (Conf->getInt ("main", "use_cookies", 0) == 1) { //DEBUG ("parm1='%s',getValue='%s'", parm1, cookie->getValue()); if (cmd_conter == 1) //LA PRIMERA VEZ SI EL BROWSER NO SOPORTA/ACEPTA COOKIES ME LO DEVUELVE VACIO { if (strcmp (parm1, cookie->getValue()) != 0) uo->setWorkingWithCookies (false); else uo->setWorkingWithCookies (true); } else { if (uo->IsWorkingWithCookies () == true) { if (strcmp (parm1, cookie->getValue()) != 0) { LOG ("SECURITY PROBLEM: Bad cookie from IP=%s, user=%s", ipclient, user); html->PrintBadCookiePage (stlang, user, connid, uo); } } } } break; } case (CMD_LOGOUT): { LOG ("Logout from IP=%s, user=%s", ipclient, user); if (ALLOW_SEVERAL_CONNS == 0) {DeleteFile (ReturnUserLockFileName (user));} imap->CloseMailbox (); sprintf (linea, "%s?lang=%s", PATH_POSTMAN, stlang); if (Conf->getInt ("main", "use_cookies", 0) == 1) { if (uo->IsWorkingWithCookies () == true) { html->printCookie (cookie->getSetClearFullCookieLine()); } } html->Redirect(linea); FINISHED = true; break; } case (CMD_INVALIDPAGE): { html->PrintInvalidPage (stlang, user, connid, uo); break; } case (CMD_MG_DUMPFULLMSG): { uo->InitStatusLine (); nummsg = xatoldef (parm1, (long int)1); html->dumpPChar (imap->dumpFullMsg (nummsg)); break; } case (CMD_MG_DUMPFULLHEADER): { TBuffer asize; uo->InitStatusLine (); nummsg = xatoldef (parm1, (long int)1); strncpy (asize, imap->getFormattedSize(nummsg), CMAXBUFFER); imap->dumpFullHeader (nummsg, SL); html->PrintFullHeaders(SL, uo, asize); break; } case CMD_MG_DISPLAY: case CMD_MG_DELDISPLAY: case CMD_MG_UNDELDISPLAY: case CMD_MG_FG_DELETE: case CMD_MG_FG_UNDELETE: case CMD_MG_FG_ANSWERED: case CMD_MG_FG_UNANSWERED: case CMD_MG_FG_FLAGGED: case CMD_MG_FG_UNFLAGGED: case CMD_MG_FG_SEEN: case CMD_MG_FG_UNSEEN: case CMD_MG_FG_SEARCHED: case CMD_MG_FG_UNSEARCHED: { char *pc; TBuffer aflags, maincontenttype, ato, afrom, acc, asubject, adate, asize, attid, contenttype, basura; TSBuffer abuf; xulong nummsg, size, cont, ppos; bool ultimomsg; uo->InitStatusLine (); nummsg = xatoldef (parm1, (xulong)1); if (nummsg > (xulong)imap->getTotalMsgs ()) nummsg = imap->getTotalMsgs (); if ((cmd == CMD_MG_DELDISPLAY) || (cmd == CMD_MG_UNDELDISPLAY)) { long todel; todel = xatoidef (parm1, -100); ultimomsg = imap->isLastMsgFromList (todel); if (todel != -100) { ppos = imap->getPosListFromNumMsg(todel); if ((ultimomsg == true) && ((unsigned long)uo->getCurrentPosition() == nummsg)) { sprintf (abuf, "%ld", todel); } else { todel = imap->getNumMsgFromPosList(imap->getPosListFromNumMsg(todel)); sprintf (abuf, "%ld", todel); } if (cmd == CMD_MG_DELDISPLAY) { cont = imap->setFlags ("\\DELETED", abuf); sprintf (abuf, L->get(MSG_FLAGS_CHANGED), cont, L->get(L_DELETEMSG)); strcat (abuf, " "); if (ultimomsg == false) strcat (abuf, L->get(L_NEXTMSGSHOWN)); else strcat (abuf, L->get(L_LASTMSGSHOWN)); } else { cont = imap->clearFlags ("\\DELETED", abuf); sprintf (abuf, L->get(MSG_FLAGS_CHANGED), cont, L->get(L_UNDELETEMSG)); strcat (abuf, " "); if (ultimomsg == false) strcat (abuf, L->get(L_NEXTMSGSHOWN)); else strcat (abuf, L->get(L_LASTMSGSHOWN)); } uo->setStatusLine (abuf, RED); } } else if ((cmd == CMD_MG_FG_DELETE) || (cmd == CMD_MG_FG_UNDELETE) || (cmd == CMD_MG_FG_ANSWERED) || (cmd == CMD_MG_FG_UNANSWERED) || (cmd == CMD_MG_FG_FLAGGED) || (cmd == CMD_MG_FG_UNFLAGGED) || (cmd == CMD_MG_FG_SEEN) || (cmd == CMD_MG_FG_UNSEEN) || (cmd == CMD_MG_FG_SEARCHED) || (cmd == CMD_MG_FG_UNSEARCHED)) { ppos = imap->getPosListFromNumMsg(nummsg); sprintf (abuf, "%ld", nummsg); switch (cmd) { case CMD_MG_FG_DELETE: { cont = imap->setFlags ("\\DELETED", abuf); if (cont <= 1) {sprintf (abuf, L->get(MSG_FLAGS_CHANGED), cont, L->get(L_DELETEMSG));} else {sprintf (abuf, L->get(MSG_FLAGS_CHANGED_S), cont, L->get(L_DELETEMSG));} break; } case CMD_MG_FG_UNDELETE:{ cont = imap->clearFlags ("\\DELETED", abuf); if (cont <= 1) {sprintf (abuf, L->get(MSG_FLAGS_CHANGED), cont, L->get(L_UNDELETEMSG));} else {sprintf (abuf, L->get(MSG_FLAGS_CHANGED_S), cont, L->get(L_UNDELETEMSG));} break; } case CMD_MG_FG_ANSWERED:{ cont = imap->setFlags ("\\ANSWERED", abuf); if (cont <= 1) {sprintf (abuf, L->get(MSG_FLAGS_CHANGED), cont, L->get(L_ANSWEREDMSG));} else {sprintf (abuf, L->get(MSG_FLAGS_CHANGED_S), cont, L->get(L_ANSWEREDMSG));} break; } case CMD_MG_FG_UNANSWERED:{ cont = imap->clearFlags ("\\ANSWERED", abuf); if (cont <= 1) {sprintf (abuf, L->get(MSG_FLAGS_CHANGED), cont, L->get(L_UNANSWEREDMSG));} else {sprintf (abuf, L->get(MSG_FLAGS_CHANGED_S), cont, L->get(L_UNANSWEREDMSG));} break; } case CMD_MG_FG_FLAGGED: { cont = imap->setFlags ("\\FLAGGED", abuf); if (cont <= 1) {sprintf (abuf, L->get(MSG_FLAGS_CHANGED), cont, L->get(L_FLAGGEDMSG));} else {sprintf (abuf, L->get(MSG_FLAGS_CHANGED_S), cont, L->get(L_FLAGGEDMSG));} break; } case CMD_MG_FG_UNFLAGGED:{ cont = imap->clearFlags ("\\FLAGGED", abuf); if (cont <= 1) {sprintf (abuf, L->get(MSG_FLAGS_CHANGED), cont, L->get(L_UNFLAGGEDMSG));} else {sprintf (abuf, L->get(MSG_FLAGS_CHANGED_S), cont, L->get(L_UNFLAGGEDMSG));} break; } case CMD_MG_FG_SEARCHED:{ imap->addMsgInSearchList (nummsg); sprintf (abuf, "%s", L->get(L_SEARCHEDMSG)); break; } case CMD_MG_FG_UNSEARCHED:{ imap->delMsgInSearchList (nummsg); sprintf (abuf, "%s", L->get(L_UNSEARCHEDMSG)); break; } } uo->setStatusLine (abuf, RED); } uo->setCurrentPosition (nummsg, imap->getTotalMsgs ()); strncpy (aflags, imap->getFlags(nummsg), CMAXBUFFER); strncpy (ato, imap->getTo (nummsg), CMAXBUFFER); strncpy (afrom, imap->getFrom (nummsg), CMAXBUFFER); strncpy (acc, imap->getCC (nummsg), CMAXBUFFER); strncpy (asubject, imap->getSubject (nummsg), CMAXBUFFER); strncpy (adate, imap->getDate (nummsg), CMAXBUFFER); strncpy (asize, imap->getFormattedSize(nummsg), CMAXBUFFER); imap->getBodyStructure (nummsg, SLAttach); ULongList *IL; IL = new ULongList (); imap->getMsgIndex (IL); html->PrintMessageHeader (stlang, user, connid, imap->getTotalMsgs (), aflags, ato, afrom, acc, asubject, adate, asize, SLAttach, uo, IL); strncpy (maincontenttype, imap->getContentType(nummsg), CMAXBUFFER); for (int Y=0; YCount(); ++Y) { sscanf (SLAttach->getString(Y).cstr(), "%s %s %ld %s", attid, contenttype, &size, basura); if ((size <= MAXTEXTSIZEATTACHFORDISPLAY) || (Y == 0)) { if (strcmp (contenttype, "TEXT/PLAIN") == 0) { if (DISPLAYTXTATTASHTML == 0) { if (Y > 0) html->WRITE (L->get(L_NUMATTACHSHOW), attid); html->BR(); pc = imap->getAttBody (nummsg, attid, SLAttachInfo, &len, true); html->BeginPre(); if (IsNull(pc) == true) {html->WRITE (L->get(MSG_MALFORMED_MESSAGE));} else {ResaltaURLsEnText (pc, ss, uo->getTruncateLengthReadingMsg());} html->EndPre(); if ((Y != 0) || ((Y == 0) && (SLAttach->Count() > 1))) html->Linea(); } else { if (Y > 0) html->WRITE (L->get(L_NUMATTACHSHOW), attid); html->BR(); pc = imap->getAttBody (nummsg, attid, SLAttachInfo, &len, true); if (IsNull(pc) == true) {html->WRITE (L->get(MSG_MALFORMED_MESSAGE));} else {html->dumpAttachWithoutHead (pc, len);} if ((Y != 0) || ((Y == 0) && (SLAttach->Count() > 1))) html->Linea(); } } else if (strcmp (contenttype, "TEXT/HTML") == 0) { if (Y > 0) html->WRITE (L->get(L_NUMATTACHSHOW), attid); html->BR(); pc = imap->getAttBody (nummsg, attid, SLAttachInfo, &len, true); if (IsNull(pc) == true) {html->WRITE (L->get(MSG_MALFORMED_MESSAGE));} else {html->dumpAttachWithoutHead (pc, len);} if ((Y != 0) || ((Y == 0) && (SLAttach->Count() > 1))) html->Linea(); } //SACO LOS AJUNTOS DE TEXTO QUE NO ENTIENDO POR PANTALLA else if (strstr (contenttype, "TEXT/") != NULL) { if (Y > 0) html->WRITE (L->get(L_NUMATTACHSHOW), attid); html->BR(); pc = imap->getAttBody (nummsg, attid, SLAttachInfo, &len, true); html->BeginPre(); if (IsNull(pc) == true) {html->WRITE (L->get(MSG_MALFORMED_MESSAGE));} else {html->dumpAttachWithoutHead (pc, len);} html->EndPre(); if ((Y != 0) || ((Y == 0) && (SLAttach->Count() > 1))) html->Linea(); } } } //for html->HTMLEnd(uo->getSkinAtribProp("COLOR_BGTABLECOPYRIGHT")); break; } case (CMD_MB_EXPUNGE): { TSBuffer abuf; int cont; cont = imap->getMsgsMarkedDeleted(); if (cont <= 0) {sprintf (abuf, L->get(MSG_MSGSPURGED_0));} else if (cont == 1) {sprintf (abuf, L->get(MSG_MSGSPURGED), cont);} else {sprintf (abuf, L->get(MSG_MSGSPURGED_S), cont);} uo->setStatusLine (abuf, RED); uo->IncValidator(); imap->Expunge (); uo->setCurrentPosition (0, imap->getTotalMsgs ()); imap->getHeaderList (uo->getBeginPage(), SL, user, uo->getMailDomain(), L->get (L_TO)); imap->getMailboxes (SL2, false); uo->setMailboxSize (imap->getMailboxSize()); html->PrintIndexPage (stlang, imap->getMailboxName(), user, connid, SL, SL2, uo); break; } case (CMD_MB_INDEX): { uo->InitStatusLine (); nummsg = xatoldef (parm1, (long int)0); uo->setCurrentPosition (nummsg, imap->getTotalMsgs ()); imap->getHeaderList (uo->getBeginPage(), SL, user, uo->getMailDomain(), L->get (L_TO)); imap->getMailboxes (SL2, WasCreatedSentMailFolder); WasCreatedSentMailFolder = false; uo->setMailboxSize (imap->getMailboxSize()); html->PrintIndexPage (stlang, imap->getMailboxName(), user, connid, SL, SL2, uo); break; } case (CMD_MB_SEARCH): { TSBuffer abuf; xulong firstnummsgfound; int cont, fdsearch; if (strcasecmp (parm1, "fd_subject") == 0) {fdsearch = 1;} else if (strcasecmp (parm1, "fd_from") == 0) {fdsearch = 2;} else if (strcasecmp (parm1, "fd_body") == 0) {fdsearch = 3;} else {fdsearch = 0;} cont = imap->searchIMAP2 ("ALL", fdsearch, allparms2, NULL, NULL); firstnummsgfound = imap->getNumFirstMsgInSearch(); if (cont <= 0) {sprintf (abuf, L->get(MSG_MSGSFOUND_0));} else if (cont == 1) {sprintf (abuf, L->get(MSG_MSGSFOUND), cont);} else {sprintf (abuf, L->get(MSG_MSGSFOUND_S), cont);} uo->setStatusLine (abuf, BLUE); if (firstnummsgfound > 0) {nummsg = firstnummsgfound;} else {nummsg = uo->getCurrentPosition ();} uo->setCurrentPosition (nummsg, imap->getTotalMsgs ()); imap->getHeaderList (uo->getBeginPage(), SL, user, uo->getMailDomain(), L->get (L_TO)); imap->getMailboxes (SL2, false); uo->setMailboxSize (imap->getMailboxSize()); html->PrintIndexPage (stlang, imap->getMailboxName(), user, connid, SL, SL2, uo); break; } case (CMD_MB_SORT): { TSBuffer abuf; int sorttype = NO_SORT; sprintf (abuf, "%s", L->get(MSG_MSGS_SORTED)); uo->setStatusLine (abuf, RED); if (strcasecmp (parm1, "number") == 0) {sorttype = NO_SORT;} else if (strcasecmp (parm1, "date") == 0) {sorttype = SORTDATE;} /* Was SORTARRIVAL; (SORTDATE) RW changed this!!!!! */ else if (strcasecmp (parm1, "from") == 0) {sorttype = SORTFROM;} else if (strcasecmp (parm1, "subject") == 0) {sorttype = SORTSUBJECT;} else if (strcasecmp (parm1, "size") == 0) {sorttype = SORTSIZE;} else {sorttype = NO_SORT;} imap->setSortType (sorttype); imap->Sort (); uo->setCurrentPosition (1, imap->getTotalMsgs ()); imap->getHeaderList (uo->getBeginPage(), SL, user, uo->getMailDomain(), L->get (L_TO)); imap->getMailboxes (SL2, false); uo->setMailboxSize (imap->getMailboxSize()); html->PrintIndexPage (stlang, imap->getMailboxName(), user, connid, SL, SL2, uo); break; } case (CMD_MB_SHOW): { uo->InitStatusLine (); imap->getMailboxes (SL, false); html->PrintMailboxesPage (stlang, imap->getMailboxName(), user, connid, SL, uo); break; } case (CMD_MB_CHANGE): { uo->InitStatusLine (); b = imap->ChangeMailbox (parm1); if (b == true) { uo->IncValidator(); uo->setStatusLine (L->get(MSG_MAILBOXCHANGED), RED); if (imap->getError()==true) {uo->setStatusLine (imap->getErrorString(), RED);} uo->setCurrentPosition (0, imap->getTotalMsgs ()); imap->getHeaderList (uo->getBeginPage(), SL, user, uo->getMailDomain(), L->get (L_TO)); imap->getMailboxes (SL2, false); uo->setMailboxSize (imap->getMailboxSize()); html->PrintIndexPage (stlang, imap->getMailboxName(), user, connid, SL, SL2, uo); } else { TSBuffer abuf; sprintf (abuf, L->get(ERR_INV_MAILBOX), parm1); html->ErrorPage(abuf); } break; } case (CMD_MB_CREATE): { TBuffer theMailBox; strncpy (theMailBox, imap->expandMailboxName (parm1), CMAXBUFFER); uo->InitStatusLine (); b = imap->createMailbox (theMailBox); if (b == true) { uo->setStatusLine (L->get(MSG_MAILBOXCREATED), RED); imap->getMailboxes (SL, true); html->PrintMailboxesPage (stlang, imap->getMailboxName(), user, connid, SL, uo); } else { TSBuffer abuf; sprintf (abuf, L->get(ERR_INV_MAILBOX), theMailBox); html->ErrorPage(abuf); } break; } case (CMD_MB_DELETE): { uo->InitStatusLine (); b = imap->deleteMailbox (parm1); if (b == true) { uo->setStatusLine (L->get(MSG_MAILBOXDELETED), RED); imap->getMailboxes (SL, true); html->PrintMailboxesPage (stlang, imap->getMailboxName(), user, connid, SL, uo); } else { TSBuffer abuf; sprintf (abuf, L->get(ERR_INV_MAILBOX), parm1); html->ErrorPage(abuf); } break; } case (CMD_MB_RENAME): { TBuffer theMailBox; strncpy (theMailBox, imap->expandMailboxName (parm2), CMAXBUFFER); uo->InitStatusLine (); b = imap->renameMailbox (parm1, theMailBox); if (b == true) { uo->setStatusLine (L->get(MSG_MAILBOXRENAMED), RED); imap->getMailboxes (SL, true); html->PrintMailboxesPage (stlang, imap->getMailboxName(), user, connid, SL, uo); } else { TSBuffer abuf; sprintf (abuf, L->get(ERR_INV_MAILBOX), theMailBox); html->ErrorPage(abuf); } break; } case (CMD_MB_DUMP): { uo->InitStatusLine (); html->Head ("text/plain", "", ""); for (int i = 1; i <= imap->getTotalMsgs(); ++i) { time_t now; now = time (NULL); html->pcWRITE ("From Postman "); html->pcWRITE (ctime(&now)); html->pcWRITE (imap->dumpFullMsg (i)); html->pcWRITE ("\r\n"); } break; } case CMD_FG_DELETE: case CMD_FG_UNDELETE: case CMD_FG_ANSWERED: case CMD_FG_UNANSWERED: case CMD_FG_FLAGGED: case CMD_FG_UNFLAGGED: case CMD_FG_SEEN: case CMD_FG_UNSEEN: { TSBuffer abuf; int cont; if (strlen(allparms) == 0) {uo->setStatusLine (L->get(MSG_NO_ENTRIES_MARKED), RED);} else { switch (cmd) { case CMD_FG_DELETE: { cont = imap->setFlags ("\\DELETED", allparms); if (cont <= 1) {sprintf (abuf, L->get(MSG_FLAGS_CHANGED), cont, L->get(L_DELETEMSG));} else {sprintf (abuf, L->get(MSG_FLAGS_CHANGED_S), cont, L->get(L_DELETEMSG));} break; } case CMD_FG_UNDELETE: { cont = imap->clearFlags ("\\DELETED", allparms); if (cont <= 1) {sprintf (abuf, L->get(MSG_FLAGS_CHANGED), cont, L->get(L_UNDELETEMSG));} else {sprintf (abuf, L->get(MSG_FLAGS_CHANGED_S), cont, L->get(L_UNDELETEMSG));} break; } case CMD_FG_ANSWERED: { cont = imap->setFlags ("\\ANSWERED", allparms); if (cont <= 1) {sprintf (abuf, L->get(MSG_FLAGS_CHANGED), cont, L->get(L_ANSWEREDMSG));} else {sprintf (abuf, L->get(MSG_FLAGS_CHANGED_S), cont, L->get(L_ANSWEREDMSG));} break; } case CMD_FG_UNANSWERED: { cont = imap->clearFlags ("\\ANSWERED", allparms); if (cont <= 1) {sprintf (abuf, L->get(MSG_FLAGS_CHANGED), cont, L->get(L_UNANSWEREDMSG));} else {sprintf (abuf, L->get(MSG_FLAGS_CHANGED_S), cont, L->get(L_UNANSWEREDMSG));} break; } case CMD_FG_FLAGGED: { cont = imap->setFlags ("\\FLAGGED", allparms); if (cont <= 1) {sprintf (abuf, L->get(MSG_FLAGS_CHANGED), cont, L->get(L_FLAGGEDMSG));} else {sprintf (abuf, L->get(MSG_FLAGS_CHANGED_S), cont, L->get(L_FLAGGEDMSG));} break; } case CMD_FG_UNFLAGGED: { cont = imap->clearFlags ("\\FLAGGED", allparms); if (cont <= 1) {sprintf (abuf, L->get(MSG_FLAGS_CHANGED), cont, L->get(L_UNFLAGGEDMSG));} else {sprintf (abuf, L->get(MSG_FLAGS_CHANGED_S), cont, L->get(L_UNFLAGGEDMSG));} break; } case CMD_FG_SEEN: { cont = imap->setFlags ("\\SEEN", allparms); //xxxxxxxxxxxxxxcont = imap->clearFlags ("\\RECENT", allparms); if (cont <= 1) {sprintf (abuf, L->get(MSG_FLAGS_CHANGED), cont, L->get(L_SEENMSG));} else {sprintf (abuf, L->get(MSG_FLAGS_CHANGED_S), cont, L->get(L_SEENMSG));} break; } case CMD_FG_UNSEEN: { cont = imap->clearFlags ("\\SEEN", allparms); //xxxxxxxxxxxxxxxxxxxxxxcont = imap->setFlags ("\\RECENT", allparms); if (cont <= 1) {sprintf (abuf, L->get(MSG_FLAGS_CHANGED), cont, L->get(L_UNSEENMSG));} else {sprintf (abuf, L->get(MSG_FLAGS_CHANGED_S), cont, L->get(L_UNSEENMSG));} break; } } uo->setStatusLine (abuf, RED); } imap->getHeaderList (uo->getBeginPage(), SL, user, uo->getMailDomain(), L->get (L_TO)); imap->getMailboxes (SL2, false); uo->setMailboxSize (imap->getMailboxSize()); html->PrintIndexPage (stlang, imap->getMailboxName(), user, connid, SL, SL2, uo); break; } case CMD_MG_MOVE: { if (strlen(allparms2) == 0) {uo->setStatusLine (L->get(MSG_NO_ENTRIES_MARKED), RED);} else { int cont; TSBuffer abuf; cont = imap->moveMessages (parm1, allparms2); if (cont <= 1) {sprintf (abuf, L->get(MSG_MOVEDMESSAGES), cont, parm1);} else {sprintf (abuf, L->get(MSG_MOVEDMESSAGES_S), cont, parm1);} uo->setStatusLine (abuf, RED); } imap->getHeaderList (uo->getBeginPage(), SL, user, uo->getMailDomain(), L->get (L_TO)); imap->getMailboxes (SL2, false); uo->setMailboxSize (imap->getMailboxSize()); html->PrintIndexPage (stlang, imap->getMailboxName(), user, connid, SL, SL2, uo); break; } case CMD_MG_COPY: { if (strlen(allparms2) == 0) {uo->setStatusLine (L->get(MSG_NO_ENTRIES_MARKED), RED);} else { int cont; TSBuffer abuf; cont = imap->copyMessages (parm1, allparms2); if (cont <= 1) {sprintf (abuf, L->get(MSG_COPYMESSAGES), cont, parm1);} else {sprintf (abuf, L->get(MSG_COPYMESSAGES_S), cont, parm1);} uo->setStatusLine (abuf, RED); } imap->getHeaderList (uo->getBeginPage(), SL, user, uo->getMailDomain(), L->get (L_TO)); imap->getMailboxes (SL2, false); uo->setMailboxSize (imap->getMailboxSize()); html->PrintIndexPage (stlang, imap->getMailboxName(), user, connid, SL, SL2, uo); break; } case CMD_CONF_ACT: { /* DIWovBTkom694Qm19aq80Jy eng conf_act mb_delete alternativo*/ uo->InitStatusLine (); html->PrintConfirmPage (parm1, stlang, parm2, user, connid, uo->getValidator(), uo->getPageId(), uo); break; } case (CMD_CM_SAVE): { CopyFileOverWrite (parm1, uo->getfnSavedMsg()); DeleteFile (parm1); uo->InitStatusLine (); html->PrintComposeMsgPage (CMD_CM, CMD_CM_SAVE, stlang, user, connid, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, uo); break; } case (CMD_CM_CLEANALL): { if (FileExists (uo->getfnSavedMsg()) == true) DeleteFile (uo->getfnSavedMsg()); uo->delAllAttachs(); uo->InitStatusLine (); html->PrintComposeMsgPage (CMD_CM, CMD_CM_CLEANALL, stlang, user, connid, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, uo); break; } case (CMD_CM): { uo->setNumMsgToReply (-1); uo->setStatusLine (L->get(MSG_COMPOSE_TIMEOUT), uo->getSkinAtribProp("COLOR_FONT_STATUSLINE")); html->PrintComposeMsgPage (CMD_CM, CMD_CM, stlang, user, connid, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, uo); break; } case (CMD_CM_REPLY): { char *pc; TBuffer attid, contenttype, basura; uo->setStatusLine (L->get(MSG_COMPOSE_TIMEOUT), uo->getSkinAtribProp("COLOR_FONT_STATUSLINE")); nummsg = xatoldef (parm1, (long int)1); uo->setNumMsgToReply ((int)nummsg); imap->getBodyStructure (nummsg, SLAttach); sscanf (SLAttach->getString(0).cstr(), "%s %s %s", attid, contenttype, basura); pc = imap->getAttBody (nummsg, attid, SLAttachInfo, &len, true); html->PrintComposeMsgPage (CMD_CM_REPLY, CMD_CM_REPLY, stlang, user, connid, imap->getTo (nummsg), NULL, NULL, imap->getSubject (nummsg), imap->getReplyTo(nummsg), imap->getFrom(nummsg), imap->getDate(nummsg), pc, uo); break; } case (CMD_CM_FORWARD): { char *pc; TBuffer attid, contenttype, basura; uo->setStatusLine (L->get(MSG_COMPOSE_TIMEOUT), uo->getSkinAtribProp("COLOR_FONT_STATUSLINE")); uo->setNumMsgToReply (-1); nummsg = xatoldef (parm1, (long int)1); if ((uo->getForwAttachs () == false) || (uo->getLastCmd () != CMD_MG_DISPLAY)) {//*** NO INSERT THE ATTACHS IN THE FORWARD imap->getBodyStructure (nummsg, SLAttach); sscanf (SLAttach->getString(0).cstr(), "%s %s %s", attid, contenttype, basura); pc = imap->getAttBody (nummsg, attid, SLAttachInfo, &len, true); html->PrintComposeMsgPage (CMD_CM_FORWARD, CMD_CM_FORWARD, stlang, user, connid, imap->getTo (nummsg), NULL, NULL, imap->getSubject (nummsg), imap->getReplyTo(nummsg), imap->getFrom(nummsg), imap->getDate(nummsg), pc, uo); } else {//*** SI INSERT xulong size; int Y, num; char *pc; TSBuffer ftotname, fname, bas, info; imap->getBodyStructure (nummsg, SLAttach); Y = 0; num = 0; while (Y < SLAttach->Count()) { //2 IMAGE/GIF 154387 bytes, "un comentario", "logo.gif" initStr (basura); initStr (info); sscanf (SLAttach->getString(Y).cstr(), "%s %s %ld %s %[^]]s", attid, contenttype, &size, basura, info); if (strchr (attid, '.') == NULL) { if ((Y > 0) || ((Y == 0) && (strcmp (contenttype, "TEXT/PLAIN") != 0))) { ++num; initStr (fname, "att"); strcat (fname, xitoa(num)); strncpy (ftotname, (char *)uo->getAttachDir(), CSMALLBUFFER); strcat (ftotname, "/"); strcat (ftotname, fname); imap->getAttBodyToFile (nummsg, attid, SLAttachInfo, &len, ftotname, true); sprintf (bas, "%s %s", contenttype, info); uo->addFileNameAtach (fname, bas); } } ++Y; } sscanf (SLAttach->getString(0).cstr(), "%s %s %s", attid, contenttype, basura); pc = imap->getAttBody (nummsg, attid, SLAttachInfo, &len, true); html->PrintComposeMsgPage (CMD_CM_FORWARD, CMD_CM_FORWARD, stlang, user, connid, imap->getTo (nummsg), NULL, NULL, imap->getSubject (nummsg), imap->getReplyTo(nummsg), imap->getFrom(nummsg), imap->getDate(nummsg), pc, uo); } break; } case (CMD_CM_SEND): { CopyFileOverWrite (parm1, uo->getfnSavedMsg()); int numattachs = xatoidef (parm2, 0); if (numattachs != uo->numAttachs()) { html->ErrorPageBack(stlang, user, connid, uo, L->get(MSG_ERR_RELOAD_ATTACHS), 2); } else { TBuffer errormsg; uo->InitStatusLine (); sendmsg = new SendMSG (uo->getSMTPServer(), parm1, uo, uo->getImapServer(), imap); WasCreatedSentMailFolder = false; b = sendmsg->sendSMTP(errormsg, uo->getSentMailName(), &WasCreatedSentMailFolder, MAILCAP); if (b == true) { int anummsg; anummsg = uo->getNumMsgToReply (); if (anummsg > -1) {imap->setFlags ("\\ANSWERED", xitoa(anummsg));} if (strcmp (errormsg, "") == 0) { html->OkPage (stlang, user, connid, uo, L->get(MSG_SEND_OK)); } else { //SENT, BUT CAN NOT COPY IN SENTMAIL html->OkPage (stlang, user, connid, uo, L->get(MSG_ERR_SAVE_SENTMAIL)); } sendmsg->DelAttachs (); } else { html->ErrorPage (errormsg); } delete sendmsg; } DeleteFile (parm1); break; } case (CMD_CM_CANCEL): { uo->setStatusLine (L->get(MSG_CANCELMSG), RED); imap->getHeaderList (uo->getBeginPage(), SL, user, uo->getMailDomain(), L->get (L_TO)); imap->getMailboxes (SL2, false); uo->setMailboxSize (imap->getMailboxSize()); html->PrintIndexPage (stlang, imap->getMailboxName(), user, connid, SL, SL2, uo); break; } case (CMD_OP): { uo->setStatusLine (L->get(MSG_SHOWOPTIONS), RED); html->PrintShowOptions (stlang, user, connid, uo); break; } case (CMD_OP_SAVE): { b = uo->SaveOptions(parm1); if (b == true) {uo->setStatusLine (L->get(MSG_SAVEOPTIONS), RED); uo->LoadOptions();} else uo->setStatusLine (L->get(MSG_ERR_SAVEOPTIONS), RED); html->PrintShowOptions (stlang, user, connid, uo); break; } case (CMD_OP_CANCEL): { uo->setStatusLine (L->get(MSG_CANCELOPTIONS), RED); imap->getHeaderList (uo->getBeginPage(), SL, user, uo->getMailDomain(), L->get (L_TO)); imap->getMailboxes (SL2, false); uo->setMailboxSize (imap->getMailboxSize()); html->PrintIndexPage (stlang, imap->getMailboxName(), user, connid, SL, SL2, uo); break; } case (CMD_AT_DUMP): { char *pcbody; TBuffer attid; uo->InitStatusLine (); nummsg = xatoldef (parm1, (long int)1); //parm2 es el attid, un pchar del tipo "12.3.4" // si es del tipo cid:03d501bf68d6$5465a1e0$0401a8c0@Pc3.ncsa.es // debo convertirlo al anterior if (NCstrstr(parm2, "CID:") > 0) { strncpy (attid, imap->getAttIdFromCID (nummsg, parm2), CMAXBUFFER); } else { strncpy (attid, parm2, CMAXBUFFER); } imap->getAttHeaderSL(nummsg, attid, SLAttachHeader); if (imap->getAttSize (nummsg, attid, SLAttach) > UNHANDLESIZEATTACH) { html->ErrorPage(L->get(ERR_UNHANDLESIZEATTACH)); } else { pcbody = imap->getAttBody (nummsg, attid, SLAttach, &len, true); if ((pcbody != NULL) && (len > 0)) { html->dumpRawAttachSL (SLAttachHeader, pcbody, len); } else { html->EmulatePageNotFound (); } } break; } case (CMD_AT_SHOW): { CopyFileOverWrite (parm1, uo->getfnSavedMsg()); DeleteFile (parm1); uo->setStatusLine (L->get(MSG_SHOWATTACHS), RED); html->PrintShowAttachs (stlang, user, connid, uo); break; } case (CMD_AT_SAVE): { TSBuffer bas; int attssaved; sprintf (bas, "%s \"\", \"%s\"", getMailcapTipoFromFilename(allparms, MAILCAP), allparms); attssaved = uo->addFileNameAtach (allparms, bas); if (attssaved > 0) uo->setStatusLine (L->get(MSG_SAVEATTACHS), RED); else uo->setStatusLine (L->get(MSG_NOATTACHSSAVED), RED); html->PrintShowAttachs (stlang, user, connid, uo); break; } case (CMD_AT_ERASE): { int totdel; totdel = uo->delFileNameAtach (allparms); if (totdel > 0) uo->setStatusLine (L->get(MSG_ERASEATTACHS), RED); else uo->setStatusLine (L->get(MSG_NOATTACHSERASED), RED); html->PrintShowAttachs (stlang, user, connid, uo); break; } case (CMD_AB_SHOWALL): { Addressbook *ab; ab = new Addressbook (ReturnUserAddressbookFileName(basepath, user, imapserver), uo); //uo->setStatusLine (L->get(MSG_ADDBOOK), RED); int sortby = -1; html->PrintAddBook_Show (cmd, stlang, user, connid, uo, ab, sortby); delete ab; break; } case (CMD_AB_DUMP): { Addressbook *ab; ab = new Addressbook (ReturnUserAddressbookFileName(basepath, user, imapserver), uo); uo->setStatusLine (L->get(MSG_ADDBOOK), RED); int sortby = -1; html->PrintAddBook_Dump (cmd, stlang, user, connid, uo, ab, sortby); delete ab; break; } case (CMD_AB_SORT): case (CMD_AB_FROM_CM): { Addressbook *ab; ab = new Addressbook (ReturnUserAddressbookFileName(basepath, user, imapserver), uo); uo->setStatusLine (L->get(MSG_ADDBOOK), RED); int sortby = -1; if (cmd == CMD_AB_SORT) {sortby = xatoidef (parm1, -1);} if (cmd == CMD_AB_FROM_CM) { CopyFileOverWrite (parm1, uo->getfnSavedMsg()); DeleteFile (parm1); } html->PrintAddBook_Show (cmd, stlang, user, connid, uo, ab, sortby); delete ab; break; } case (CMD_AB_TAKEADDRESS): { nummsg = xatoldef (parm1, (long int)1); Addressbook *ab; ab = new Addressbook (ReturnUserAddressbookFileName(basepath, user, imapserver), uo); uo->setStatusLine (L->get(MSG_AB_EDITENTRY), RED); int numentry = ab->AddNewEntry(imap->getFrom (nummsg)); html->PrintAddBook_EditEntry (cmd, stlang, user, connid, uo, ab, numentry); delete ab; break; } case (CMD_AB_EDITENTRY): { Addressbook *ab; ab = new Addressbook (ReturnUserAddressbookFileName(basepath, user, imapserver), uo); uo->setStatusLine (L->get(MSG_AB_EDITENTRY), RED); int numentry = xatoidef (parm1, (int)0); html->PrintAddBook_EditEntry (cmd, stlang, user, connid, uo, ab, numentry); delete ab; break; } case (CMD_AB_NEWENTRY): { Addressbook *ab; ab = new Addressbook (ReturnUserAddressbookFileName(basepath, user, imapserver), uo); uo->setStatusLine (L->get(MSG_AB_EDITENTRY), RED); html->PrintAddBook_EditEntry (cmd, stlang, user, connid, uo, ab, -1); delete ab; break; } case (CMD_AB_DELEENTRIES): { int sortby = -1; bool b; Addressbook *ab; ab = new Addressbook (ReturnUserAddressbookFileName(basepath, user, imapserver), uo); if (strlen(allparms) == 0) {uo->setStatusLine (L->get(MSG_NO_ENTRIES_MARKED), RED);} else { b = ab->DeleteEntries (allparms); if (b) {uo->setStatusLine (L->get(MSG_AB_DELEENTRY), RED);} else {uo->setStatusLine (L->get(ERR_AB_DELEENTRY), RED);} } html->PrintAddBook_Show (cmd, stlang, user, connid, uo, ab, sortby); delete ab; break; } case (CMD_AB_SAVEENTRY): { Addressbook *ab; ab = new Addressbook (ReturnUserAddressbookFileName(basepath, user, imapserver), uo); int numentry = xatoidef (parm1, (int)-1); if (numentry == -1) {numentry = ab->AddNewEntry();} ab->UpdateEntryFromFile (numentry, parm2); uo->setStatusLine (L->get(MSG_AB_SAVEENTRY), RED); delete ab; TBuffer linea; sprintf (linea, "%s", uo->getLastStringCmd (CMD_AB_SAVEENTRY, stlang, connid, false)); html->Redirect (linea); break; } case (CMD_AB_ADDFIELDS): { int sortby = -1; int n1 = 0, n2 = 0, n3 = 0; bool b1 = false, b2 = false, b3 = false; TBuffer lineaTO, lineaCC, lineaBCC, abuf; Addressbook *ab; //LOG ("parm1=%s", parm1); ab = new Addressbook (ReturnUserAddressbookFileName(basepath, user, imapserver), uo); if (FileExists (uo->getfnSavedMsg()) == false) {CreaFileSavedMsg(uo->getfnSavedMsg());} strncpy (lineaTO, getLineFile(parm1, 1, 1), CMAXBUFFER); strncpy (lineaCC, getLineFile(parm1, 2, 2), CMAXBUFFER); strncpy (lineaBCC, getLineFile(parm1, 3, 3), CMAXBUFFER); if (strcmp(lineaTO, " ") != 0) { b1 = ConcatLineToLineOfFile (uo->getfnSavedMsg(), 2, ab->getMultiAddresses(lineaTO), ",", MAXLENGTH_TO); n1 = CountTokensEnString (ab->getMultiAddresses(lineaTO), ','); } if (strcmp(lineaCC, " ") != 0) { b2 = ConcatLineToLineOfFile (uo->getfnSavedMsg(), 3, ab->getMultiAddresses(lineaCC), ",", MAXLENGTH_TO); n2 = CountTokensEnString (ab->getMultiAddresses(lineaCC), ','); } if (strcmp(lineaBCC, " ") != 0) { b3 = ConcatLineToLineOfFile (uo->getfnSavedMsg(), 4, ab->getMultiAddresses(lineaBCC), ",", MAXLENGTH_TO); n3 = CountTokensEnString (ab->getMultiAddresses(lineaBCC), ','); } if ((b1 == true) || (b2 == true) || (b3 == true)) { uo->setStatusLine (L->get(MSG_ADDRESS_LINE_CUT), RED); } else if ((strcmp(lineaTO, " ") == 0) && (strcmp(lineaCC, " ") == 0) && (strcmp(lineaBCC, " ") == 0)) { uo->setStatusLine (L->get(MSG_NO_ENTRIES_MARKED), RED); } else { sprintf (abuf, L->get(MSG_AB_ADDFIELDS), n1 + n2 + n3); uo->setStatusLine (abuf, RED); } DeleteFile (parm1); html->PrintAddBook_Show (cmd, stlang, user, connid, uo, ab, sortby); delete ab; break; } case (CMD_DEBUG): { uo->setStatusLine (L->get(MSG_DEBUG), RED); html->PrintDebugPage (stlang, user, connid, uo); break; } default: { imap->CloseMailbox (); html->Redirect(PATH_POSTMAN); FINISHED = true; break; } } close (connected_socket); delete SLAttachInfo; delete SLAttachHeader; delete SLAttach; delete SL2; delete SL; } //while (FINISHED == false) ss->Close (); DeleteFile (fnsocket); return 0; }