MAILINGLIST: add facility to choose the default room email alias.
authorWilfried Goesgens <dothebart@citadel.org>
Sun, 23 Dec 2012 19:34:57 +0000 (20:34 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Sun, 23 Dec 2012 19:34:57 +0000 (20:34 +0100)
libcitadel/lib/libcitadel.h
webcit/roomlist.c
webcit/roomops.c
webcit/roomops.h
webcit/static/t/room/edit/select_alias.html [new file with mode: 0644]
webcit/static/t/room/edit/tab_listserv.html
webcit/webcit.h

index 3b478b98709d2d8157b81bc34a5dac15f2fab017..ce9baf9dd1ef7da4bbb914427dcf40448f614711 100644 (file)
@@ -58,6 +58,7 @@ enum RoomNetCfg {
        pop3client,
        rssclient,
        participate,
+       roommailalias,
        maxRoomNetCfg
 };
 
index 6246e313b22c48100e5920686b9e0de6b15bc83f..869a594fa8952f4543873e140ff7444746aa719e 100644 (file)
@@ -5,6 +5,11 @@
 #include "webcit.h"
 #include "webserver.h"
 
+typedef enum __eRoomParamType {
+       eNotSet,
+       eDomain,
+       eAlias
+}eRoomParamType;
 
 HashList *GetWhoKnowsHash(StrBuf *Target, WCTemplputParams *TP)
 {
@@ -181,6 +186,7 @@ void FlushIgnetCfgs(folder *room)
                        DeleteHash(&room->IgnetCfgs[i]);
        }
        memset(&room->IgnetCfgs, 0, sizeof(HashList *) * (maxRoomNetCfg + 1));
+       room->RoomAlias = NULL;
 
 }
 
@@ -365,7 +371,7 @@ HashList *GetThisRoomMAlias(StrBuf *Target, WCTemplputParams *TP)
                                    IKEY(n),
                                    Token, 
                                    HFreeStrBuf);
-                               n++; /* #0 is the type... */
+                               n++;
                        }
        }
        else if (State == 550)
@@ -376,6 +382,131 @@ HashList *GetThisRoomMAlias(StrBuf *Target, WCTemplputParams *TP)
        return Aliases;
 }
 
+
+void AppendPossibleAliasWithDomain(
+       HashList *PossibleAliases,
+       long *nPossibleAliases,
+       const HashList *Domains, 
+       const char *prefix,
+       long len,
+       const char* Alias,
+       long AliasLen)
+{
+       const StrBuf *OneDomain;
+       StrBuf *Line;
+       HashPos *It = NULL;
+       const char *Key;
+       long KLen;
+       void *pV;
+       int n;
+
+       It = GetNewHashPos(Domains, 1);
+       n = *nPossibleAliases;
+       while (GetNextHashPos(Domains, It, &KLen, &Key, &pV))
+       {
+               OneDomain = (const StrBuf*) pV;
+               Line = NewStrBuf();
+               StrBufAppendBufPlain(Line, prefix, len, 0);
+               StrBufAppendBufPlain(Line, Alias, AliasLen, 0);
+               StrBufAppendBufPlain(Line, HKEY("@"), 0);
+               StrBufAppendBuf(Line, OneDomain, 0);
+
+               Put(PossibleAliases, 
+                   IKEY(n),
+                   Line, 
+                   HFreeStrBuf);
+               n++;
+       }
+       DeleteHashPos(&It);
+       *nPossibleAliases = n;
+}
+
+HashList *GetThisRoomPossibleMAlias(StrBuf *Target, WCTemplputParams *TP) 
+{
+       wcsession *WCC = WC;
+       HashList *Domains;
+       StrBuf *Line;
+       StrBuf *Token;
+       HashList *PossibleAliases = NULL;
+       
+       const char *pComma;
+       const char *pAt;
+       long aliaslen;
+       long locallen;
+       long State;
+       long n = 0;
+
+       Domains = GetValidDomainNames(Target, TP);
+       if (Domains == NULL)
+               return NULL;
+       PossibleAliases = NewHash(1, NULL);
+       Line = NewStrBuf();
+
+       AppendPossibleAliasWithDomain(PossibleAliases,
+                                     &n,
+                                     Domains,
+                                     HKEY("room_"),
+                                     SKEY(WCC->CurRoom.name));
+
+
+       serv_puts("GNET "FILE_MAILALIAS);
+       StrBuf_ServGetln(Line);
+       if (GetServerStatus(Line, &State) == 1) 
+       {
+               int Done = 0;
+
+               while(!Done && (StrBuf_ServGetln(Line) >= 0))
+                       if ( (StrLength(Line)==3) && 
+                            !strcmp(ChrPtr(Line), "000"))
+                       {
+                               Done = 1;
+                       }
+                       else
+                       {
+                               pComma = strchr(ChrPtr(Line), ',');
+                               if (pComma == NULL)
+                                       continue;
+                               aliaslen = pComma - ChrPtr(Line);
+                               locallen = StrLength(Line) - 1 - aliaslen;
+                               if (locallen - 5 != StrLength(WCC->CurRoom.name))
+                                       continue;
+                               if (strncmp(pComma + 1, "room_", 5) != 0)
+                                       continue;
+
+                               if (strcasecmp(pComma + 6, ChrPtr(WCC->CurRoom.name)) != 0)
+                                       continue;
+                               pAt = strchr(ChrPtr(Line), '@');
+                               if ((pAt == NULL) || (pAt > pComma))
+                               {
+                                       AppendPossibleAliasWithDomain(PossibleAliases,
+                                                                     &n,
+                                                                     Domains,
+                                                                     HKEY(""),
+                                                                     ChrPtr(Line),
+                                                                     aliaslen);
+                                       n++;
+                               }
+                               else
+                               {
+                                       
+                                       Token = NewStrBufPlain(ChrPtr(Line), aliaslen);
+                                       Put(PossibleAliases,
+                                           IKEY(n),
+                                           Token,
+                                           HFreeStrBuf);
+                                       n++;
+                               }
+                       }
+       }
+       else if (State == 550)
+               AppendImportantMessage(_("Higher access is required to access this function."), -1);
+
+       FreeStrBuf(&Line);
+
+       return PossibleAliases;
+}
+
+
 HashList *GetNetConfigHash(StrBuf *Target, WCTemplputParams *TP) 
 {
        wcsession *WCC = WC;
@@ -401,8 +532,12 @@ HashList *GetNetConfigHash(StrBuf *Target, WCTemplputParams *TP)
        {
                const char *Pos = NULL;
                int Done = 0;
+               int HaveRoomMailAlias = 0;
 
                while(!Done && (StrBuf_ServGetln(Line) >= 0))
+               {
+                       if (StrLength(Line) == 0)
+                               continue;
                        if ( (StrLength(Line)==3) && 
                             !strcmp(ChrPtr(Line), "000"))
                        {
@@ -412,6 +547,12 @@ HashList *GetNetConfigHash(StrBuf *Target, WCTemplputParams *TP)
                        {
                                StrBufExtract_NextToken(Token, Line, &Pos, '|');
                                PutTo = GetTokenDefine(SKEY(Token), -1);
+                               if (PutTo == roommailalias)
+                               {
+                                       if (HaveRoomMailAlias > 0)
+                                               continue; /* Only ONE alias possible! */
+                                       HaveRoomMailAlias++;
+                               }
                                if ((PutTo >= 0) && 
                                    (PutTo < maxRoomNetCfg) &&
                                    (Pos != StrBufNOTNULL))
@@ -437,6 +578,10 @@ HashList *GetNetConfigHash(StrBuf *Target, WCTemplputParams *TP)
                                        while (Pos != StrBufNOTNULL) {
                                                Content = NewStrBuf();
                                                StrBufExtract_NextToken(Content, Line, &Pos, '|');
+
+                                               if ((PutTo == roommailalias) && n == 1)
+                                                       WCC->CurRoom.RoomAlias = Content;
+
                                                Put(SubH, 
                                                    IKEY(n),
                                                    Content, 
@@ -446,6 +591,7 @@ HashList *GetNetConfigHash(StrBuf *Target, WCTemplputParams *TP)
                                }
                                Pos = NULL;
                        }
+               }
        }
        else if (State == 550)
                AppendImportantMessage(_("Higher access is required to access this function."), -1);
@@ -649,6 +795,60 @@ int CompareRooms(const folder *room1, const folder *room2)
        return CompareRoomListByFloorRoomPrivFirst(room1, room2);
 }
 
+int ConditionalThisRoomIsStrBufContextAlias(StrBuf *Target, WCTemplputParams *TP)
+{
+       wcsession       *WCC = WC;
+       const char      *pVal;
+       long             len;
+       eRoomParamType   ParamType;
+
+       ParamType = GetTemplateTokenNumber(Target, TP, 2, eNotSet);
+       GetTemplateTokenString(Target, TP, 3, &pVal, &len);
+
+       if (ParamType == eNotSet)
+       {
+               return StrLength(WCC->CurRoom.RoomAlias) == 0;
+       }
+       else if (ParamType == eDomain)
+       {
+               const StrBuf *CtxStr = (const StrBuf*) CTX(CTX_STRBUF);
+               const char *pAt;
+
+               if (CtxStr == NULL) 
+                       return 0;
+               
+               if (StrLength(WCC->CurRoom.RoomAlias) == 0)
+                       return 0;
+
+               if (strncmp(ChrPtr(WCC->CurRoom.RoomAlias), "room_", 5) != 0)
+                       return 0;
+
+               pAt = strchr(ChrPtr(WCC->CurRoom.RoomAlias), '@');
+               if (pAt == NULL)
+                       return 0;
+               return strcmp(pAt + 1, ChrPtr(CtxStr)) == 0;
+       }
+       else if (ParamType == eAlias)
+       {
+               const StrBuf *CtxStr = (const StrBuf*) CTX(CTX_STRBUF);
+
+               if (CtxStr == NULL) 
+                       return 0;
+               
+               if (StrLength(WCC->CurRoom.RoomAlias) == 0)
+                       return 0;
+
+               return strcmp(ChrPtr(WCC->CurRoom.RoomAlias), ChrPtr(CtxStr)) == 0;
+       }
+       else
+       {
+               LogTemplateError(Target, "TokenParameter", 2, TP, 
+                                "Invalid paramtype; need one of [eNotSet|eDomain|eAlias]");
+               return 0;
+       }
+
+}
+
 int ConditionalRoomIsRESTSubRoom(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession  *WCC = WC;
@@ -744,6 +944,7 @@ InitModule_ROOMLIST
        RegisterIterator("ITERATE:THISROOM:WHO_KNOWS", 0, NULL, GetWhoKnowsHash, NULL, DeleteHash, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
        RegisterIterator("ITERATE:THISROOM:GNET", 1, NULL, GetNetConfigHash, NULL, NULL, CTX_STRBUFARR, CTX_NONE, IT_NOFLAG);
        RegisterIterator("ITERATE:THISROOM:MALIAS", 1, NULL, GetThisRoomMAlias, NULL, NULL, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
+       RegisterIterator("ITERATE:THISROOM:POSSIBLE:MALIAS", 1, NULL, GetThisRoomPossibleMAlias, NULL, NULL, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
 
        RegisterIterator("LFLR", 0, NULL, GetFloorListHash, NULL, NULL, CTX_FLOORS, CTX_NONE, IT_FLAG_DETECT_GROUPCHANGE);
        RegisterIterator("LKRA", 0, NULL, GetRoomListHashLKRA, NULL, NULL, CTX_ROOMS, CTX_NONE, IT_FLAG_DETECT_GROUPCHANGE);
@@ -751,10 +952,15 @@ InitModule_ROOMLIST
        RegisterIterator("LPRM", 0, NULL, GetRoomListHashLPRM, NULL, DeleteHash, CTX_ROOMS, CTX_NONE, IT_FLAG_DETECT_GROUPCHANGE);
 
 
+       REGISTERTokenParamDefine(eNotSet);
+       REGISTERTokenParamDefine(eDomain);
+       REGISTERTokenParamDefine(eAlias);
 
 
        RegisterConditional("COND:ROOM:REST:ISSUBROOM", 0, ConditionalRoomIsRESTSubRoom, CTX_ROOMS);
 
+       RegisterConditional("COND:THISROOM:ISALIAS:CONTEXTSTR", 0, ConditionalThisRoomIsStrBufContextAlias, CTX_NONE);
+
        RegisterSortFunc(HKEY("byfloorroom"),
                         NULL, 0,
                         CompareRoomListByFloorRoomPrivFirst,
index 23f027f853ac66da7228b354f1633061bfe4e082..22802ced20750a8ef1a793802eb4ba4f20dc41a3 100644 (file)
@@ -1051,6 +1051,7 @@ void netedit(void) {
        StrBuf *Line;
        StrBuf *TmpBuf;
        int malias = 0;
+       int malias_set_default = 0;
        char sepchar = '|';
        int Done;
 
@@ -1079,18 +1080,27 @@ void netedit(void) {
        }
        else if (havebstr("alias")) {
                const char *domain;
-               malias = 1;
-               sepchar = ',';
                domain = bstr("aliasdomain");
-               strcat(line, bstr("prefix"));
-               if (!IsEmptyStr(domain))
+               if ((domain == NULL) || IsEmptyStr(domain))
                {
-                       strcat(line, "@");
-                       strcat(line, domain);
+                       malias_set_default = 1;
+                       strcpy(line, bstr("prefix"));
+                       strcat(line, bstr("default_aliasdomain"));
+               }
+               else
+               {
+                       malias = 1;
+                       sepchar = ',';
+                       strcat(line, bstr("prefix"));
+                       if (!IsEmptyStr(domain))
+                       {
+                               strcat(line, "@");
+                               strcat(line, domain);
+                       }
+                       strcat(line, ",");
+                       strcat(line, "room_");
+                       strcat(line, ChrPtr(WC->CurRoom.name));
                }
-               strcat(line, ",");
-               strcat(line, "room_");
-               strcat(line, ChrPtr(WC->CurRoom.name));
        }
        else {
                output_headers(1, 1, 1, 0, 0, 0);       
@@ -1130,12 +1140,23 @@ void netedit(void) {
                        if (StrLength(Line) == 0)
                                continue;
 
-                       extract_token(cmpa0, ChrPtr(Line), 0, sepchar, sizeof cmpa0);
-                       extract_token(cmpa1, ChrPtr(Line), 1, sepchar, sizeof cmpa1);
-                       if ( (strcasecmp(cmpa0, cmpb0)) || (strcasecmp(cmpa1, cmpb1)) )
+                       if (malias_set_default)
                        {
-                               StrBufAppendBufPlain(Line, HKEY("\n"), 0);
-                               StrBufAppendBuf(TmpBuf, Line, 0);
+                               if (strncmp(ChrPtr(Line), HKEY("roommailalias|")) != 0)
+                               {
+                                       StrBufAppendBufPlain(Line, HKEY("\n"), 0);
+                                       StrBufAppendBuf(TmpBuf, Line, 0);
+                               }
+                       }
+                       else
+                       {
+                               extract_token(cmpa0, ChrPtr(Line), 0, sepchar, sizeof cmpa0);
+                               extract_token(cmpa1, ChrPtr(Line), 1, sepchar, sizeof cmpa1);
+                               if ( (strcasecmp(cmpa0, cmpb0)) || (strcasecmp(cmpa1, cmpb1)) )
+                               {
+                                       StrBufAppendBufPlain(Line, HKEY("\n"), 0);
+                                       StrBufAppendBuf(TmpBuf, Line, 0);
+                               }
                        }
                }
        }
@@ -1448,6 +1469,7 @@ InitModule_ROOMOPS
        }
        REGISTERTokenParamDefine(rssclient);
        REGISTERTokenParamDefine(participate);
+       REGISTERTokenParamDefine(roommailalias);
 
 
 
index d64cf1f0418374a9c2eb9476492555c6ee4b0058..7d9cd89e3792281e9e51ac22bb9796fa76a276cd 100644 (file)
@@ -78,6 +78,9 @@ typedef struct _folder {
        int RoomAideLoaded;
        StrBuf *RoomAide;
 
+/* only available if GNET contains this */
+       const StrBuf* RoomAlias; /* by what mail will this room send mail? */
+
 /* only available if GETR was run */
        int XALoaded;
        StrBuf *XAPass;
diff --git a/webcit/static/t/room/edit/select_alias.html b/webcit/static/t/room/edit/select_alias.html
new file mode 100644 (file)
index 0000000..2f2bd0b
--- /dev/null
@@ -0,0 +1 @@
+<option value="<?CONTEXTSTR("U")>"<?%("COND:THISROOM:ISALIAS:CONTEXTSTR", 1, #"eAlias", "", ' selected="selected"', "")>><?CONTEXTSTR("X")></option>
index 1c1db769e1a316382be570cd9195f54a6e140cba..e0967e9ecae215063d560c582458f2cc71093b6f 100644 (file)
@@ -72,7 +72,6 @@
                                                <tt><?%("COND:IS_HTTPS", 3, 1, 0, "https", "http")>://<?SERV:FQDN>/listsub</tt>
                                        </td>
                                </tr>
-                               <tr>
                                <tr>
                                  <td colspan="2" align="center">
                                    <input type="hidden" name="last_tabsel" value="<?TAB:N>">
                                </tr>
                        </table>
                </form>
+
+               <table class="altern">
+                 <tr>
+                 <td colspan="2">
+                   <?_("Which from address should be used: ")>
+                 </td>
+                 </tr>
+                 <tr>
+                   <td colspan="2">
+                     <form method="post" action="netedit">
+                       <p>
+                         <input type="hidden" name="last_tabsel" value="<?TAB:N>">
+                         <input type="hidden" name="alias" value="room_<?THISROOM:NAME("X")>">
+                         <input type="hidden" name="nonce" value="<?NONCE>">
+                         <input type="hidden" name="go" value="<?THISROOM:NAME("X")>">
+                         <input type="hidden" name="prefix" value="roommailalias|">
+                         <select size="1" name="default_aliasdomain">
+                                 <option value=""<?%("COND:THISROOM:ISALIAS:CONTEXTSTR", 1, #"eNotSet", "", ' selected="selected"', "")>><?_("none (not advised)")></option>
+                 <?ITERATE("ITERATE:THISROOM:POSSIBLE:MALIAS", ="room_edit_select_alias", 0, 0, -1, "")>
+                         </select>
+                         <input type="submit" name="add_button" value="<?_("Set")>">
+                       </p>
+                     </form>
+                   </td>
+                 </tr>
+               </table>
                <table class="altern">
                  <td colspan="2">
                    <?_("Alternative public emailaddresses pointing to this room: ")>
index be61bbbc65dd9cd91cae5a520e65437fc70a4dc3..43ecb0f78cc4f51efd355d6a4d1d0a9c1639bf3b 100644 (file)
@@ -765,3 +765,5 @@ struct bltr {
 struct bltr blogview_learn_thread_references(long msgnum);
 void tmplput_blog_permalink(StrBuf *Target, WCTemplputParams *TP);
 void display_summary_page(void);
+
+HashList *GetValidDomainNames(StrBuf *Target, WCTemplputParams *TP);