extractMessages function
Implementation
List<MessageRef> extractMessages(BeautifulSoup soup) {
List<MessageRef> messages = [];
var messageTableParent =
soup.find("table", id: "s_m_Content_Content_threadGV_ctl00");
var folderIdInput =
soup.find('*', id: 's_m_Content_Content_ListGridSelectionTree_folders');
int? folderId = int.tryParse(folderIdInput?.getAttrValue("value") ?? "");
if (messageTableParent != null && folderId != null) {
var messageTable = messageTableParent.children[0].children;
messageTable.removeAt(0).decompose();
for (var messageRow in messageTable) {
Bs4Element linkElement = messageRow.children[3].children[0].children[0];
String postCode = linkElement.getAttrValue("onclick")!;
int indexOfDollar = postCode.indexOf("\$");
String id = postCode.substring(
indexOfDollar, postCode.indexOf('\'', indexOfDollar));
int indexOfUnderDollar = id.indexOf(r'_$_');
String normalizedId = id.substring(indexOfUnderDollar + 3);
String topic = messageRow.children[3].text.trim();
String receivers =
messageRow.children[5].children[0].getAttrValue('title')!;
String dateChanged = messageRow.children[7].text;
DateTime parsedTime = parseLectioDate(dateChanged);
messages.add(MessageRef(
id: id,
dateChanged: parsedTime,
topic: topic,
sender: receivers,
folderId: folderId,
normalizedId: normalizedId));
}
}
return messages;
}