From: Wilfried Goesgens Date: Sun, 23 Dec 2012 19:34:57 +0000 (+0100) Subject: MAILINGLIST: add facility to choose the default room email alias. X-Git-Tag: v8.20~167 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=08c16cd4d6d989d6511d187f41113040cfeda14b MAILINGLIST: add facility to choose the default room email alias. --- diff --git a/libcitadel/lib/libcitadel.h b/libcitadel/lib/libcitadel.h index 3b478b987..ce9baf9dd 100644 --- a/libcitadel/lib/libcitadel.h +++ b/libcitadel/lib/libcitadel.h @@ -58,6 +58,7 @@ enum RoomNetCfg { pop3client, rssclient, participate, + roommailalias, maxRoomNetCfg }; diff --git a/webcit/roomlist.c b/webcit/roomlist.c index 6246e313b..869a594fa 100644 --- a/webcit/roomlist.c +++ b/webcit/roomlist.c @@ -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, diff --git a/webcit/roomops.c b/webcit/roomops.c index 23f027f85..22802ced2 100644 --- a/webcit/roomops.c +++ b/webcit/roomops.c @@ -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); diff --git a/webcit/roomops.h b/webcit/roomops.h index d64cf1f04..7d9cd89e3 100644 --- a/webcit/roomops.h +++ b/webcit/roomops.h @@ -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 index 000000000..2f2bd0be8 --- /dev/null +++ b/webcit/static/t/room/edit/select_alias.html @@ -0,0 +1 @@ + diff --git a/webcit/static/t/room/edit/tab_listserv.html b/webcit/static/t/room/edit/tab_listserv.html index 1c1db769e..e0967e9ec 100644 --- a/webcit/static/t/room/edit/tab_listserv.html +++ b/webcit/static/t/room/edit/tab_listserv.html @@ -72,7 +72,6 @@ :///listsub - @@ -83,6 +82,32 @@ + + + + + + + + +
+ +
+
+

+ + "> + + "> + + + "> +

+
+
diff --git a/webcit/webcit.h b/webcit/webcit.h index be61bbbc6..43ecb0f78 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -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);