+void ExpandShortUrls(StrBuf *Message)
+{
+ StrBuf *Shadow;
+ HashList *pUrls;
+ ConstStr *pCUrl;
+ const char *pch;
+ const char *pche;
+
+ /* we just suspect URL shorteners to be inside of feeds from twitter
+ * or other short content messages, so don't crawl through real blogs.
+ */
+ if (StrLength(Message) > 500)
+ return;
+
+ pUrls = NewHash(1, Flathash);
+ CrawlMessageForShorterUrls(pUrls, Message);
+
+ if (GetCount(pUrls) > 0)
+ {
+ StrBuf *ShorterUrlStr;
+ HashPos *Pos;
+ const char *RetrKey;
+ void *pv;
+ long len;
+
+ Shadow = NewStrBufPlain(NULL, StrLength(Message));
+ SortByPayload (pUrls, SortConstStrByPosition);
+
+ ShorterUrlStr = NewStrBufPlain(NULL, StrLength(Message));
+
+ pch = ChrPtr(Message);
+ pche = pch + StrLength(Message);
+ Pos = GetNewHashPos(pUrls, 1);
+ while (GetNextHashPos(pUrls, Pos, &len, &RetrKey, &pv))
+ {
+ pCUrl = (ConstStr*) pv;
+
+ if (pch != pCUrl->Key)
+ StrBufAppendBufPlain(Shadow, pch, pCUrl->Key - pch, 0);
+
+ StrBufPlain(ShorterUrlStr, CKEY(*pCUrl));
+ if (LookupUrl(ShorterUrlStr))
+ {
+ StrBufAppendBufPlain(Shadow, HKEY("<a href=\""), 0);
+ StrBufAppendBuf(Shadow, ShorterUrlStr, 0);
+ StrBufAppendBufPlain(Shadow, HKEY("\">"), 0);
+ StrBufAppendBuf(Shadow, ShorterUrlStr, 0);
+ StrBufAppendBufPlain(Shadow, HKEY("["), 0);
+ StrBufAppendBufPlain(Shadow, pCUrl->Key, pCUrl->len, 0);
+ StrBufAppendBufPlain(Shadow, HKEY("]</a>"), 0);
+ }
+ else
+ {
+ StrBufAppendBufPlain(Shadow, HKEY("<a href=\""), 0);
+ StrBufAppendBufPlain(Shadow, pCUrl->Key, pCUrl->len, 0);
+ StrBufAppendBufPlain(Shadow, HKEY("\">"), 0);
+ StrBufAppendBufPlain(Shadow, pCUrl->Key, pCUrl->len, 0);
+ StrBufAppendBufPlain(Shadow, HKEY("</a>"), 0);
+ }
+ pch = pCUrl->Key + pCUrl->len + 1;
+
+ }
+ if (pch < pche)
+ StrBufAppendBufPlain(Shadow, pch, pche - pch, 0);
+ FlushStrBuf(Message);
+ StrBufAppendBuf(Message, Shadow, 0);
+
+ FreeStrBuf(&ShorterUrlStr);
+ FreeStrBuf(&Shadow);
+ DeleteHashPos(&Pos);
+ }
+
+ DeleteHash(&pUrls);
+}
+
+
+void AppendLink(StrBuf *Message, StrBuf *link, StrBuf *LinkTitle, const char *Title)
+{
+ if (StrLength(link) > 0)
+ {
+ StrBufAppendBufPlain(Message, HKEY("<a href=\""), 0);
+ StrBufAppendBuf(Message, link, 0);
+ StrBufAppendBufPlain(Message, HKEY("\">"), 0);
+ if (StrLength(LinkTitle) > 0)
+ StrBufAppendBuf(Message, LinkTitle, 0);
+ else if ((Title != NULL) && !IsEmptyStr(Title))
+ StrBufAppendBufPlain(Message, Title, -1, 0);
+ else
+ StrBufAppendBuf(Message, link, 0);
+ StrBufAppendBufPlain(Message, HKEY("</a><br>\n"), 0);
+ }
+}