+
+ security.declareProtected(ModifyPortalContent, 'removeUnusedAttachments')
+ def removeUnusedAttachments(self, html) :
+ html = '<div>%s</div>' % html
+ doc = htmlReadDoc(html, '', None, PARSE_OPTIONS)
+ used = {}
+
+ hrefs = doc.xpathEval('//a/@href')
+ for href in [a.get_content() for a in hrefs] :
+ if href.startswith('attachments/') :
+ used[href[len('attachments/'):]] = True
+
+ srcs = doc.xpathEval('//img/@src')
+ for src in [a.get_content() for a in srcs] :
+ if src.startswith('attachments/') :
+ parts = src.split('/')
+ if len(parts) >=2 :
+ used[parts[1]] = True
+
+ unused = [id for id in self.objectIds() if not used.has_key(id)]
+ if unused :
+ self.manage_delObjects(unused)